Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jiasli opened this issue Apr 2, 2022 · 3 comments

Comments

@jiasli
Copy link
Member

jiasli commented Apr 2, 2022

Even though #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: Dataprotection ModuleNotFoundError 'azure.mgmt.resourcegraph' azure-cli-extensions#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
@jiasli jiasli self-assigned this Apr 2, 2022
@jiasli jiasli changed the title In Azure CLI installed by Homebrew, azure and azure.mgmt still have a __init__.py files In Azure CLI installed by Homebrew, azure and azure.mgmt still have __init__.py files calling pkg_resources Apr 2, 2022
@yonzhan
Copy link
Collaborator

yonzhan commented Apr 2, 2022

packaging

@bebound
Copy link
Contributor

bebound commented Apr 2, 2022

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
Copy link
Contributor

bebound commented Apr 6, 2022

According to tdsmith/homebrew-pypi-poet#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants