Skip to content

Commit

Permalink
Add Distribution._get_version() for DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek authored and pganssle committed Mar 31, 2019
1 parent d8b901b commit 1371ea1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ def version(self):
try:
return self._version
except AttributeError:
version = _version_from_file(self._get_metadata(self.PKG_INFO))
version = self._get_version()
if version is None:
tmpl = "Missing 'Version:' header and/or %s file"
raise ValueError(tmpl % self.PKG_INFO, self)
Expand Down Expand Up @@ -2727,6 +2727,12 @@ def _get_metadata(self, name):
for line in self.get_metadata_lines(name):
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):
"""Ensure distribution is importable on `path` (default=sys.path)"""
if path is None:
Expand Down Expand Up @@ -2945,7 +2951,7 @@ def _reload_version(self):
take an extra step and try to get the version number from
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:
self._version = md_version
return self
Expand Down

0 comments on commit 1371ea1

Please sign in to comment.