-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning if classifiers do not match the running version
- Loading branch information
1 parent
67f534d
commit 088287b
Showing
4 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import absolute_import | ||
|
||
import logging | ||
import sys | ||
|
||
from pip._vendor import pkg_resources | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_metadata(dist): | ||
if (isinstance(dist, pkg_resources.DistInfoDistribution) and | ||
dist.has_metadata('METADATA')): | ||
return dist.get_metadata('METADATA') | ||
elif dist.has_metadata('PKG-INFO'): | ||
return dist.get_metadata('PKG-INFO') | ||
|
||
|
||
def get_classifiers(metadata): | ||
# It looks like FeedParser can not deal with repeated headers | ||
classifiers = [] | ||
for line in metadata.splitlines(): | ||
if not line: | ||
break | ||
# Classifier: License :: OSI Approved :: MIT License | ||
if line.startswith('Classifier: '): | ||
classifiers.append(line[len('Classifier: '):]) | ||
return classifiers | ||
|
||
|
||
def check_python_classifiers(dist): | ||
classifiers = get_classifiers(get_metadata(dist)) | ||
# Catch: | ||
# Programming Language :: Python :: 3.6 | ||
# but not: | ||
# Programming Language :: Python :: Implementation :: PyPy | ||
supported_versions = [ | ||
# 34 == len('Programming Language :: Python :: ') | ||
classifier[34:] for classifier in classifiers | ||
if ( | ||
classifier.startswith('Programming Language :: Python :: ') and | ||
classifier[34:35].isdigit() | ||
) | ||
] | ||
if not supported_versions: | ||
# The package provides no information | ||
return | ||
major_versions, minor_versions = [], [] | ||
for version in supported_versions: | ||
if '.' in version: | ||
minor_versions.append(tuple(map(int, version.split('.')))) | ||
else: | ||
major_versions.append(int(version)) | ||
if major_versions and sys.version_info[0] not in major_versions: | ||
logger.warning( | ||
"%s is advertised as supporting %s but not Python %s", | ||
dist.project_name, | ||
", ".join(["Python %s" % (version,) | ||
for version in major_versions]), | ||
sys.version_info[0]) | ||
if (minor_versions and sys.version_info[0:2] not in minor_versions and | ||
sys.version_info[0:2] < max(minor_versions)): | ||
logger.warning( | ||
"%s is advertised as supporting %s but not Python %s", | ||
dist.project_name, | ||
", ".join(["Python %s" % ('.'.join(map(str, version)),) | ||
for version in minor_versions]), | ||
"Python %s" % ('.'.join(map(str, sys.version_info[0:2])),)) |