Handle a (rare) case while guessing version of a package

This will fix the case which was reported for packages installed
via pacman on archlinux where '__version__' attribute of the pkg
object (module) seems to be getting shadowed by the module
'pkg.__version__' module. Refer to issue #140.

Although the issue seems to be specific to package installed on
archlinux via pacman, the root cause is not known. Also, the behaviour
is seen only if FrozenRequirement is imported (see issue comments for
more details).

In general, this will handle cases where a package's '__init__.py' module doesn't
provide a '__version__' attribute, but a '__version__.py' file is
present.
This commit is contained in:
Vineet Naik 2020-12-20 12:50:43 +05:30
parent be26d32c16
commit 4ec6cd2f4e
1 changed files with 5 additions and 1 deletions

View File

@ -69,7 +69,11 @@ def guess_version(pkg_key, default='?'):
except ImportError:
return default
else:
return getattr(m, '__version__', default)
v = getattr(m, '__version__', default)
if inspect.ismodule(v):
return getattr(v, '__version__', default)
else:
return v
def frozen_req_from_dist(dist):