aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources/__init__.py
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2019-02-22 04:15:07 -0800
committerPaul Ganssle <paul@ganssle.io>2019-04-03 10:37:22 -0400
commit80ec85c55b1470df6541473f674f41bdc6bc5268 (patch)
treea6384eb909ed8e16a82e362c967b8cc7e8850f97 /pkg_resources/__init__.py
parent52939bcc8f549f6c8fef4bf76e09a20d0bf62e44 (diff)
downloadexternal_python_setuptools-80ec85c55b1470df6541473f674f41bdc6bc5268.tar.gz
external_python_setuptools-80ec85c55b1470df6541473f674f41bdc6bc5268.tar.bz2
external_python_setuptools-80ec85c55b1470df6541473f674f41bdc6bc5268.zip
Include file path when Version: missing
Related to pip's github issue pypa/pip#6194. This has come up in pip's issue tracker (github) multiple times: - pypa/pip#6177 - pypa/pip#6283 - pypa/pip#6194
Diffstat (limited to 'pkg_resources/__init__.py')
-rw-r--r--pkg_resources/__init__.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index e8921f95..97e08d68 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -1403,8 +1403,15 @@ class NullProvider:
def has_resource(self, resource_name):
return self._has(self._fn(self.module_path, resource_name))
+ def _get_metadata_path(self, name):
+ return self._fn(self.egg_info, name)
+
def has_metadata(self, name):
- return self.egg_info and self._has(self._fn(self.egg_info, name))
+ if not self.egg_info:
+ return self.egg_info
+
+ path = self._get_metadata_path(name)
+ return self._has(path)
def get_metadata(self, name):
if not self.egg_info:
@@ -1868,6 +1875,9 @@ class FileMetadata(EmptyProvider):
def __init__(self, path):
self.path = path
+ def _get_metadata_path(self, name):
+ return self.path
+
def has_metadata(self, name):
return name == 'PKG-INFO' and os.path.isfile(self.path)
@@ -2663,8 +2673,12 @@ class Distribution:
except AttributeError:
version = self._get_version()
if version is None:
- tmpl = "Missing 'Version:' header and/or %s file"
- raise ValueError(tmpl % self.PKG_INFO, self)
+ path = self._get_metadata_path_for_display(self.PKG_INFO)
+ msg = (
+ "Missing 'Version:' header and/or {} file at path: {}"
+ ).format(self.PKG_INFO, path)
+ raise ValueError(msg, self)
+
return version
@property
@@ -2722,6 +2736,23 @@ class Distribution:
)
return deps
+ def _get_metadata_path_for_display(self, name):
+ """
+ Return the path to the given metadata file, if available.
+ """
+ try:
+ # We need to access _get_metadata_path() on the provider object
+ # directly rather than through this class's __getattr__()
+ # since _get_metadata_path() is marked private.
+ path = self._provider._get_metadata_path(name)
+
+ # Handle exceptions e.g. in case the distribution's metadata
+ # provider doesn't support _get_metadata_path().
+ except Exception:
+ return '[could not detect]'
+
+ return path
+
def _get_metadata(self, name):
if self.has_metadata(name):
for line in self.get_metadata_lines(name):