diff options
| author | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
|---|---|---|
| committer | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
| commit | 68df54d6629ec019142eb149dd037774f2d11e7c (patch) | |
| tree | 345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py | |
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py')
| -rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py new file mode 100644 index 0000000..d523953 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/packaging.py | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | from __future__ import absolute_import | ||
| 2 | |||
| 3 | import logging | ||
| 4 | import sys | ||
| 5 | from email.parser import FeedParser # type: ignore | ||
| 6 | |||
| 7 | from pip._vendor import pkg_resources | ||
| 8 | from pip._vendor.packaging import specifiers, version | ||
| 9 | |||
| 10 | from pip._internal import exceptions | ||
| 11 | |||
| 12 | logger = logging.getLogger(__name__) | ||
| 13 | |||
| 14 | |||
| 15 | def check_requires_python(requires_python): | ||
| 16 | """ | ||
| 17 | Check if the python version in use match the `requires_python` specifier. | ||
| 18 | |||
| 19 | Returns `True` if the version of python in use matches the requirement. | ||
| 20 | Returns `False` if the version of python in use does not matches the | ||
| 21 | requirement. | ||
| 22 | |||
| 23 | Raises an InvalidSpecifier if `requires_python` have an invalid format. | ||
| 24 | """ | ||
| 25 | if requires_python is None: | ||
| 26 | # The package provides no information | ||
| 27 | return True | ||
| 28 | requires_python_specifier = specifiers.SpecifierSet(requires_python) | ||
| 29 | |||
| 30 | # We only use major.minor.micro | ||
| 31 | python_version = version.parse('.'.join(map(str, sys.version_info[:3]))) | ||
| 32 | return python_version in requires_python_specifier | ||
| 33 | |||
| 34 | |||
| 35 | def get_metadata(dist): | ||
| 36 | if (isinstance(dist, pkg_resources.DistInfoDistribution) and | ||
| 37 | dist.has_metadata('METADATA')): | ||
| 38 | return dist.get_metadata('METADATA') | ||
| 39 | elif dist.has_metadata('PKG-INFO'): | ||
| 40 | return dist.get_metadata('PKG-INFO') | ||
| 41 | |||
| 42 | |||
| 43 | def check_dist_requires_python(dist): | ||
| 44 | metadata = get_metadata(dist) | ||
| 45 | feed_parser = FeedParser() | ||
| 46 | feed_parser.feed(metadata) | ||
| 47 | pkg_info_dict = feed_parser.close() | ||
| 48 | requires_python = pkg_info_dict.get('Requires-Python') | ||
| 49 | try: | ||
| 50 | if not check_requires_python(requires_python): | ||
| 51 | raise exceptions.UnsupportedPythonVersion( | ||
| 52 | "%s requires Python '%s' but the running Python is %s" % ( | ||
| 53 | dist.project_name, | ||
| 54 | requires_python, | ||
| 55 | '.'.join(map(str, sys.version_info[:3])),) | ||
| 56 | ) | ||
| 57 | except specifiers.InvalidSpecifier as e: | ||
| 58 | logger.warning( | ||
| 59 | "Package %s has an invalid Requires-Python entry %s - %s", | ||
| 60 | dist.project_name, requires_python, e, | ||
| 61 | ) | ||
| 62 | return | ||
| 63 | |||
| 64 | |||
| 65 | def get_installer(dist): | ||
| 66 | if dist.has_metadata('INSTALLER'): | ||
| 67 | for line in dist.get_metadata_lines('INSTALLER'): | ||
| 68 | if line.strip(): | ||
| 69 | return line.strip() | ||
| 70 | return '' | ||
