Use module.__file__

This commit is contained in:
Devesh Kumar Singh 2020-06-06 13:46:06 +05:30
parent 021eddcb70
commit 76257e4b65
1 changed files with 5 additions and 1 deletions

View File

@ -87,8 +87,12 @@ def get_vendor_version_from_module(module_name):
if not version:
# Try to find version in debundled module info
# The type for module.__file__ is Optional[str] in
# Python 2, and str in Python 3. The type: ignore is
# added to account for Python 2, instead of a cast
# and should be removed once we drop Python 2 support
pkg_set = pkg_resources.WorkingSet(
[os.path.dirname(getattr(module, '__file__', None))]
[os.path.dirname(module.__file__)] # type: ignore
)
package = pkg_set.find(pkg_resources.Requirement.parse(module_name))
version = getattr(package, 'version', None)