-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Extension] Allow to load extensions in the system path via packages #12367
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
Conversation
On Linux, check if there are extension in the system Python
library path (eg: /usr/lib/python3/dist-packages/azure-cli-extensions).
This allows extensions to be installed via system packages in
dist-packages, and registered by simply creating an extension directory
and symlinking the egg-info and the module.
EG:
$ ls -l /usr/lib/python3/dist-packages/azure-cli-extensions/azure-devops/
total 0
lrwxrwxrwx 1 root root 18 Feb 23 12:31 azext_devops -> ../../azext_devops
lrwxrwxrwx 1 root root 34 Feb 23 12:31 azure_devops-0.17.0.egg-info -> ../../azure_devops-0.17.0.egg-info
$ az extension list
[
{
"extensionType": "whl",
"name": "azure-devops",
"version": "0.17.0"
}
]
Locally installed extensions still have higher priority if available.
8724142 to
1001e0f
Compare
|
HI @fengzhou-msft could you pls help to have a look? thanks. |
|
Why Linux only? As far as I know, windows should also work for this. |
|
|
||
| from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX | ||
|
|
||
| from distutils.sysconfig import get_python_lib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is extension containing C code (non-pure Python), will the get_python_lib() work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my Debian box cpython libraries are in dist-packages too, so I'm not expecting issues:
>>> from distutils.sysconfig import get_python_lib
>>> get_python_lib()
'/usr/lib/python3/dist-packages'
$ find /usr/lib/python3/dist-packages/ -name *.so -type f | wc -l
241
Also, what we are after is the azure-cli-extensions directory where we store the symlinks - the symlinks themselves can point to anywhere
Because I can only test it on Linux :-) If someone can confirm it works on Windows too, and we can establish a canonical installation path, then we can add it in the future. OSX too. But I'm not sure it's too interesting for other OSes? The use case is Linux distro packages, not sure Win/OSX match that model? But I'm really not familiar with deployments in those OSes, so I might very well be wrong. |
|
@bluca While this PR adds a useful feature to use extensions in the system path, I plan to make the system directory configurable just like the user extension directory. And it's also useful to add an option in |
That's fine, as long as the default works as-is without any additional configuration - otherwise it's not useful |
@fengzhou-msft can we start by merging this and then doing additional work on top? |
Yes. That's the plan. |
|
Great, thank you! |
|
@bluca on Ubuntu, our package uses a wrapped python instead of the system python, and the python_lib path is |
|
I don't use your packages because of that. I've uploaded azure-cli to Debian and Ubuntu using system's python and dependencies. https://packages.debian.org/sid/azure-cli |
|
Thanks! |
|
@bluca, after we supported Python 3.10 (#20195), >>> from distutils.sysconfig import get_python_lib
<stdin>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<stdin>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig insteadAccording to https://bugs.python.org/issue41282#msg393021, it is not recommended/possible to get >>> import distutils.sysconfig
>>> distutils.sysconfig.get_python_lib()
'/usr/lib/python3/dist-packages'
>>> import sysconfig
>>> sysconfig.get_paths()
{'stdlib': '/usr/lib/python3.8', 'platstdlib': '/usr/lib/python3.8', 'purelib': '/usr/lib/python3.8/site-packages', 'platlib': '/usr/lib/python3.8/site-packages', 'include': '/usr/include/python3.8', 'platinclude': '/usr/include/python3.8', 'scripts': '/usr/bin', 'data': '/usr'}
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
...
return os.path.join(prefix, "lib", "python3", "dist-packages")Questions:
|
|
I think it's still being discussed. As a temporary workaround you could do something like |
|
It doesn't seem >>> import distutils.sysconfig
>>> import sysconfig
>>> distutils.sysconfig.get_python_lib()
'/usr/lib/python3/dist-packages'
>>> sysconfig.get_paths()['platlib'].replace("site", "dist")
'/usr/lib/python3.8/dist-packages'
Now it is flooding our CI with |
|
Right, it doesn't seem like Python added a way to get that path then - you can just hard-code it until they fix it, if you want to get rid of the warnings I guess |
|
Thanks @bluca, this is helpful information. Could you help create a PR? It is difficult for me to test it. Appreciate it! |
|
Sure, this works for me: #20391 |
On Linux, check if there are extension in the system Python
library path (eg: /usr/lib/python3/dist-packages/azure-cli-extensions).
This allows extensions to be installed via system packages in
dist-packages, and registered by simply creating an extension directory
and symlinking the egg-info and the module.
EG:
$ ls -l /usr/lib/python3/dist-packages/azure-cli-extensions/azure-devops/
total 0
lrwxrwxrwx 1 root root 18 Feb 23 12:31 azext_devops -> ../../azext_devops
lrwxrwxrwx 1 root root 34 Feb 23 12:31 azure_devops-0.17.0.egg-info -> ../../azure_devops-0.17.0.egg-info
$ az extension list
[
{
"extensionType": "whl",
"name": "azure-devops",
"version": "0.17.0"
}
]
Locally installed extensions still have higher priority if available.