az cli looks for extension dependencies in incorrect locations which results in ModuleNotFound errors
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
**Describe the bug**
Dependency resolution for .whl installed extension changes depending on how the AZ-CLI was installed.
Our extension requires the `azure-mgmt-resourcegraph` which we define in `setup.py`:
```
DEPENDENCIES = [
'azure-cli-core',
'azure-mgmt-resourcegraph',
# The following are dependencies from azure-cli-core that we are using directly
'requests~=2.20',
'six~=1.12'
]
```
When the az-cli is installed via `pip` in a clean python distro, or via the Debian/Redhat installer, our extensions dependencies are successfully resolved to `$USERHOME/.azure/cliextensions/livedata/azure/mgmt/resourcegraph`
Other supported means of installing the az-cli may result in the following errors when installing our .whl extension and trying to resolve dependencies
---
az-cli installed via brew on macOS:
```
ImportError: cannot import name 'resourcegraph' from 'azure.mgmt' (/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/azure/mgmt/__init__.py)
```
Observe that the dependency is being looked for in the python distribution rather than under `.azure/cliextensions`
---
az-cli installed in venv where `azdev setup` is ran:
```
File "/Users/user/.pyenv/versions/3.8.5/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/Users/user/.azure/cliextensions/livedata/azext_livedata/custom.py", line 14, in
from azure.mgmt import resourcegraph as arg
ImportError: cannot import name 'resourcegraph' from 'azure.mgmt' (unknown location)
```
Observe that importlib is used from within the python distribution and is not resolving dependency from `.azure/cliextensions/livedata/module-name`
---
**To Reproduce**
- Install az-cli through homebrew
- Create an extension with the `azure-mgmt-resourcegraph` listed in setup.py and a command which will import this dependency
- Build and add extension via `az extension add --source /path/to/extension.whl`
**Expected behavior**
Extensions used in the az-cli should resolve their dependencies from the extension module in `.azure/cliextensions` in a consistent way when using commands
Attached is the python build wheel for our extension. It needs to have the filename extension renamed to `.whl` in order to work.
[livedata-0.14.2-py2.py3-none-any.2412.zip](https://github.com/Azure/azure-cli/files/7303478/livedata-0.14.2-py2.py3-none-any.2412.zip)
Contributor guide
Assessment
This issue has not been assessed yet.