Azure / azure-cli

Azure Command-Line Interface
MIT License
4.02k stars 2.99k forks source link

In Azure CLI installed by Homebrew, `azure` and `azure.mgmt` still have `__init__.py` files calling `pkg_resources` #21910

Open jiasli opened 2 years ago

jiasli commented 2 years ago

Even though https://github.com/Azure/azure-cli/pull/14372 migrated CLI packaging system to PEP 420 Implicit Namespace Packages, In Azure CLI installed by Homebrew, azure and azure.mgmt still have __init__.py files:

cat /opt/homebrew/Cellar/azure-cli/2.34.1/libexec/lib/python3.10/site-packages/azure/__init__.py
__import__('pkg_resources').declare_namespace(__name__)

cat /opt/homebrew/Cellar/azure-cli/2.34.1/libexec/lib/python3.10/site-packages/azure/mgmt/__init__.py
__import__('pkg_resources').declare_namespace(__name__)

This brings problems:

  1. azure namespace package installed by extensions won't work: https://github.com/Azure/azure-cli-extensions/issues/4562
  2. This defeats the purpose of migrating to PEP 420
  3. Loading time of pkg_resources is slow and this slows down the execution speed of Azure CLI
yonzhan commented 2 years ago

packaging

bebound commented 2 years ago

Homebrew install azure-cli requirements from src. In some packages, the setup.py is not standard and installing these packages will create __init__.py in above folders.

For example, azure-keyvault 1.1.0 uses pkg_resources to accomplish namespace package. But its setup.py does not contain namespace_packages=['azure'], so pip install just copies the __init__.py to azure folder rather than skip it.

One possible fix is updating Homebrew formula to replace src with Wheels, as __init__.py is removed explicitly in Wheels by wheel build script, .

Affected packages

package latest version auzre/init.py azure/mgmt/init.py
azure-keyvault-1.1.0 4.2.0 x
azure-loganalytics-0.1.0 0.1.1 x
azure-mgmt-consumption-2.0.0 9.0.0 x x
azure-mgmt-datalake-analytics-0.2.1 0.6.0 x x
azure-mgmt-datalake-store-0.5.0 0.5.0 x x
azure-mgmt-relay-0.1.0 1.1.0 x x
bebound commented 2 years ago

According to https://github.com/tdsmith/homebrew-pypi-poet/pull/42 , homebrew-pypi-poet only support build from source and homebrew also has --no-binary param when install Python dependencies. It seems that we have to update the dependencies to fix this.