diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-03-20 15:34:18 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-03-20 15:34:18 -0400 |
| commit | acd20ca332bb3f0ad48c7d92f832bfb2121decc1 (patch) | |
| tree | 8411bf0ec08e92f64ff050cc4fee902659651447 /pkg_resources/__init__.py | |
| parent | c21f34b66f67d7948d2f99143636cd1dab7734a6 (diff) | |
| download | python-setuptools-git-acd20ca332bb3f0ad48c7d92f832bfb2121decc1.tar.gz | |
Reindent warning and use short circuits for flatter implementation.
Diffstat (limited to 'pkg_resources/__init__.py')
| -rw-r--r-- | pkg_resources/__init__.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 1bb67a71..f7611472 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -36,6 +36,7 @@ import collections import plistlib import email.parser import tempfile +import textwrap from pkgutil import get_importer PY3 = sys.version_info > (3,) @@ -2505,26 +2506,29 @@ class Distribution(object): return self._parsed_version def _warn_legacy_version(self): - if isinstance( - self._parsed_version, packaging.version.LegacyVersion): - # While an empty version is techincally a legacy version and - # is not a valid PEP 440 version, it's also unlikely to - # actually come from someone and instead it is more likely that - # it comes from setuptools attempting to parse a filename and - # including it in the list. So for that we'll gate this warning - # on if the version is anything at all or not. - if self.version: - warnings.warn( - "'%s (%s)' is being parsed as a legacy, non PEP 440, " - "version. You may find odd behavior and sort order. " - "In particular it will be sorted as less than 0.0. It " - "is recommend to migrate to PEP 440 compatible " - "versions." % ( - self.project_name, self.version, - ), - PEP440Warning, - ) + LV = packaging.version.LegacyVersion + is_legacy = isinstance(self._parsed_version, LV) + if not is_legacy: + return + + # While an empty version is techincally a legacy version and + # is not a valid PEP 440 version, it's also unlikely to + # actually come from someone and instead it is more likely that + # it comes from setuptools attempting to parse a filename and + # including it in the list. So for that we'll gate this warning + # on if the version is anything at all or not. + if not self.version: + return + + tmpl = textwrap.dedent(""" + '%s (%s)' is being parsed as a legacy, non PEP 440, + version. You may find odd behavior and sort order. + In particular it will be sorted as less than 0.0. It + is recommend to migrate to PEP 440 compatible + versions. + """).strip().replace('\n', ' ') + warnings.warn(tmpl % (self.project_name, self.version), PEP440Warning) @property def version(self): |
