generalimport
generalimport copied to clipboard
Error on namespace packages
It seems like the library does not handle namespace packages (https://packaging.python.org/en/latest/guides/packaging-namespace-packages/) correctly. Even when the package is installed, the library will still return fake modules.
A minimal example to reproduce this error:
pip install azure-identity
Without generalimport:
>>> from azure.identity import AzureCliCredential
>>> AzureCliCredential()
<azure.identity._credentials.azure_cli.AzureCliCredential object at 0x7efc5e5f4ca0>
runs fine.
But with generalimport:
>>> from generalimport import generalimport
>>> generalimport("azure")
<generalimport.import_catcher.ImportCatcher object at 0x7f0d7d070a30>
>>> from azure.identity import AzureCliCredential # A FakeModule is returned
>>> AzureCliCredential()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python3.10/site-packages/generalimport/fake_module.py", line 69, in error_func
return self._error_func(error_pars=error_pars)
File "/opt/conda/lib/python3.10/site-packages/generalimport/fake_module.py", line 65, in _error_func
raise MissingDependencyException(msg=msg)
generalimport.exception.MissingDependencyException: Optional dependency azure.identity (required by 'AzureCliCredential') was used but it isn't installed. Triggered by '__call__'.
Did I use this library incorrectly?
Looking forward to your help!!
@Mandera