Commit 52939bcc authored by Chris Jerdonek's avatar Chris Jerdonek Committed by Paul Ganssle

Add Distribution._get_version() for DRY

parent 4876dbb7
...@@ -2661,7 +2661,7 @@ class Distribution: ...@@ -2661,7 +2661,7 @@ class Distribution:
try: try:
return self._version return self._version
except AttributeError: except AttributeError:
version = _version_from_file(self._get_metadata(self.PKG_INFO)) version = self._get_version()
if version is None: if version is None:
tmpl = "Missing 'Version:' header and/or %s file" tmpl = "Missing 'Version:' header and/or %s file"
raise ValueError(tmpl % self.PKG_INFO, self) raise ValueError(tmpl % self.PKG_INFO, self)
...@@ -2727,6 +2727,12 @@ class Distribution: ...@@ -2727,6 +2727,12 @@ class Distribution:
for line in self.get_metadata_lines(name): for line in self.get_metadata_lines(name):
yield line yield line
def _get_version(self):
lines = self._get_metadata(self.PKG_INFO)
version = _version_from_file(lines)
return version
def activate(self, path=None, replace=False): def activate(self, path=None, replace=False):
"""Ensure distribution is importable on `path` (default=sys.path)""" """Ensure distribution is importable on `path` (default=sys.path)"""
if path is None: if path is None:
...@@ -2945,7 +2951,7 @@ class EggInfoDistribution(Distribution): ...@@ -2945,7 +2951,7 @@ class EggInfoDistribution(Distribution):
take an extra step and try to get the version number from take an extra step and try to get the version number from
the metadata file itself instead of the filename. the metadata file itself instead of the filename.
""" """
md_version = _version_from_file(self._get_metadata(self.PKG_INFO)) md_version = self._get_version()
if md_version: if md_version:
self._version = md_version self._version = md_version
return self return self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment