diff options
author | rahulp13 | 2020-03-17 14:55:41 +0530 |
---|---|---|
committer | rahulp13 | 2020-03-17 14:55:41 +0530 |
commit | 296443137f4288cb030e92859ccfbe3204bc1088 (patch) | |
tree | ca4798c2da1e7244edc3bc108d81b462b537aea2 /lib/python2.7/site-packages/pip/operations | |
parent | 0db48f6533517ecebfd9f0693f89deca28408b76 (diff) | |
download | KiCad-eSim-296443137f4288cb030e92859ccfbe3204bc1088.tar.gz KiCad-eSim-296443137f4288cb030e92859ccfbe3204bc1088.tar.bz2 KiCad-eSim-296443137f4288cb030e92859ccfbe3204bc1088.zip |
initial commit
Diffstat (limited to 'lib/python2.7/site-packages/pip/operations')
-rw-r--r-- | lib/python2.7/site-packages/pip/operations/__init__.py | 0 | ||||
-rw-r--r-- | lib/python2.7/site-packages/pip/operations/check.py | 49 | ||||
-rw-r--r-- | lib/python2.7/site-packages/pip/operations/freeze.py | 132 |
3 files changed, 181 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/pip/operations/__init__.py b/lib/python2.7/site-packages/pip/operations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/python2.7/site-packages/pip/operations/__init__.py diff --git a/lib/python2.7/site-packages/pip/operations/check.py b/lib/python2.7/site-packages/pip/operations/check.py new file mode 100644 index 0000000..2cf67aa --- /dev/null +++ b/lib/python2.7/site-packages/pip/operations/check.py @@ -0,0 +1,49 @@ + + +def check_requirements(installed_dists): + missing_reqs_dict = {} + incompatible_reqs_dict = {} + + for dist in installed_dists: + key = '%s==%s' % (dist.project_name, dist.version) + + missing_reqs = list(get_missing_reqs(dist, installed_dists)) + if missing_reqs: + missing_reqs_dict[key] = missing_reqs + + incompatible_reqs = list(get_incompatible_reqs( + dist, installed_dists)) + if incompatible_reqs: + incompatible_reqs_dict[key] = incompatible_reqs + + return (missing_reqs_dict, incompatible_reqs_dict) + + +def get_missing_reqs(dist, installed_dists): + """Return all of the requirements of `dist` that aren't present in + `installed_dists`. + + """ + installed_names = set(d.project_name.lower() for d in installed_dists) + missing_requirements = set() + + for requirement in dist.requires(): + if requirement.project_name.lower() not in installed_names: + missing_requirements.add(requirement) + yield requirement + + +def get_incompatible_reqs(dist, installed_dists): + """Return all of the requirements of `dist` that are present in + `installed_dists`, but have incompatible versions. + + """ + installed_dists_by_name = {} + for installed_dist in installed_dists: + installed_dists_by_name[installed_dist.project_name] = installed_dist + + for requirement in dist.requires(): + present_dist = installed_dists_by_name.get(requirement.project_name) + + if present_dist and present_dist not in requirement: + yield (requirement, present_dist) diff --git a/lib/python2.7/site-packages/pip/operations/freeze.py b/lib/python2.7/site-packages/pip/operations/freeze.py new file mode 100644 index 0000000..920c2c1 --- /dev/null +++ b/lib/python2.7/site-packages/pip/operations/freeze.py @@ -0,0 +1,132 @@ +from __future__ import absolute_import + +import logging +import re + +import pip +from pip.req import InstallRequirement +from pip.req.req_file import COMMENT_RE +from pip.utils import get_installed_distributions +from pip._vendor import pkg_resources +from pip._vendor.packaging.utils import canonicalize_name +from pip._vendor.pkg_resources import RequirementParseError + + +logger = logging.getLogger(__name__) + + +def freeze( + requirement=None, + find_links=None, local_only=None, user_only=None, skip_regex=None, + default_vcs=None, + isolated=False, + wheel_cache=None, + skip=()): + find_links = find_links or [] + skip_match = None + + if skip_regex: + skip_match = re.compile(skip_regex).search + + dependency_links = [] + + for dist in pkg_resources.working_set: + if dist.has_metadata('dependency_links.txt'): + dependency_links.extend( + dist.get_metadata_lines('dependency_links.txt') + ) + for link in find_links: + if '#egg=' in link: + dependency_links.append(link) + for link in find_links: + yield '-f %s' % link + installations = {} + for dist in get_installed_distributions(local_only=local_only, + skip=(), + user_only=user_only): + try: + req = pip.FrozenRequirement.from_dist( + dist, + dependency_links + ) + except RequirementParseError: + logger.warning( + "Could not parse requirement: %s", + dist.project_name + ) + continue + installations[req.name] = req + + if requirement: + # the options that don't get turned into an InstallRequirement + # should only be emitted once, even if the same option is in multiple + # requirements files, so we need to keep track of what has been emitted + # so that we don't emit it again if it's seen again + emitted_options = set() + for req_file_path in requirement: + with open(req_file_path) as req_file: + for line in req_file: + if (not line.strip() or + line.strip().startswith('#') or + (skip_match and skip_match(line)) or + line.startswith(( + '-r', '--requirement', + '-Z', '--always-unzip', + '-f', '--find-links', + '-i', '--index-url', + '--pre', + '--trusted-host', + '--process-dependency-links', + '--extra-index-url'))): + line = line.rstrip() + if line not in emitted_options: + emitted_options.add(line) + yield line + continue + + if line.startswith('-e') or line.startswith('--editable'): + if line.startswith('-e'): + line = line[2:].strip() + else: + line = line[len('--editable'):].strip().lstrip('=') + line_req = InstallRequirement.from_editable( + line, + default_vcs=default_vcs, + isolated=isolated, + wheel_cache=wheel_cache, + ) + else: + line_req = InstallRequirement.from_line( + COMMENT_RE.sub('', line).strip(), + isolated=isolated, + wheel_cache=wheel_cache, + ) + + if not line_req.name: + logger.info( + "Skipping line in requirement file [%s] because " + "it's not clear what it would install: %s", + req_file_path, line.strip(), + ) + logger.info( + " (add #egg=PackageName to the URL to avoid" + " this warning)" + ) + elif line_req.name not in installations: + logger.warning( + "Requirement file [%s] contains %s, but that " + "package is not installed", + req_file_path, COMMENT_RE.sub('', line).strip(), + ) + else: + yield str(installations[line_req.name]).rstrip() + del installations[line_req.name] + + yield( + '## The following requirements were added by ' + 'pip freeze:' + ) + for installation in sorted( + installations.values(), key=lambda x: x.name.lower()): + if canonicalize_name(installation.name) not in skip: + yield str(installation).rstrip() |