From 4ec6cd2f4ebf101d5951b2171981b58974bfeb45 Mon Sep 17 00:00:00 2001 From: Vineet Naik Date: Sun, 20 Dec 2020 12:50:43 +0530 Subject: [PATCH] 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. --- pipdeptree.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pipdeptree.py b/pipdeptree.py index eccab33..05111b3 100644 --- a/pipdeptree.py +++ b/pipdeptree.py @@ -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):