summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
committerShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
commit68df54d6629ec019142eb149dd037774f2d11e7c (patch)
tree345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py164
1 files changed, 164 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py
new file mode 100644
index 0000000..78b7d32
--- /dev/null
+++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/req/req_set.py
@@ -0,0 +1,164 @@
1from __future__ import absolute_import
2
3import logging
4from collections import OrderedDict
5
6from pip._internal.exceptions import InstallationError
7from pip._internal.utils.logging import indent_log
8from pip._internal.wheel import Wheel
9
10logger = logging.getLogger(__name__)
11
12
13class RequirementSet(object):
14
15 def __init__(self, require_hashes=False):
16 """Create a RequirementSet.
17
18 :param wheel_cache: The pip wheel cache, for passing to
19 InstallRequirement.
20 """
21
22 self.requirements = OrderedDict()
23 self.require_hashes = require_hashes
24
25 # Mapping of alias: real_name
26 self.requirement_aliases = {}
27 self.unnamed_requirements = []
28 self.successfully_downloaded = []
29 self.reqs_to_cleanup = []
30
31 def __str__(self):
32 reqs = [req for req in self.requirements.values()
33 if not req.comes_from]
34 reqs.sort(key=lambda req: req.name.lower())
35 return ' '.join([str(req.req) for req in reqs])
36
37 def __repr__(self):
38 reqs = [req for req in self.requirements.values()]
39 reqs.sort(key=lambda req: req.name.lower())
40 reqs_str = ', '.join([str(req.req) for req in reqs])
41 return ('<%s object; %d requirement(s): %s>'
42 % (self.__class__.__name__, len(reqs), reqs_str))
43
44 def add_requirement(self, install_req, parent_req_name=None,
45 extras_requested=None):
46 """Add install_req as a requirement to install.
47
48 :param parent_req_name: The name of the requirement that needed this
49 added. The name is used because when multiple unnamed requirements
50 resolve to the same name, we could otherwise end up with dependency
51 links that point outside the Requirements set. parent_req must
52 already be added. Note that None implies that this is a user
53 supplied requirement, vs an inferred one.
54 :param extras_requested: an iterable of extras used to evaluate the
55 environment markers.
56 :return: Additional requirements to scan. That is either [] if
57 the requirement is not applicable, or [install_req] if the
58 requirement is applicable and has just been added.
59 """
60 name = install_req.name
61 if not install_req.match_markers(extras_requested):
62 logger.info("Ignoring %s: markers '%s' don't match your "
63 "environment", install_req.name,
64 install_req.markers)
65 return [], None
66
67 # This check has to come after we filter requirements with the
68 # environment markers.
69 if install_req.link and install_req.link.is_wheel:
70 wheel = Wheel(install_req.link.filename)
71 if not wheel.supported():
72 raise InstallationError(
73 "%s is not a supported wheel on this platform." %
74 wheel.filename
75 )
76
77 # This next bit is really a sanity check.
78 assert install_req.is_direct == (parent_req_name is None), (
79 "a direct req shouldn't have a parent and also, "
80 "a non direct req should have a parent"
81 )
82
83 if not name:
84 # url or path requirement w/o an egg fragment
85 self.unnamed_requirements.append(install_req)
86 return [install_req], None
87 else:
88 try:
89 existing_req = self.get_requirement(name)
90 except KeyError:
91 existing_req = None
92 if (parent_req_name is None and existing_req and not
93 existing_req.constraint and
94 existing_req.extras == install_req.extras and not
95 existing_req.req.specifier == install_req.req.specifier):
96 raise InstallationError(
97 'Double requirement given: %s (already in %s, name=%r)'
98 % (install_req, existing_req, name))
99 if not existing_req:
100 # Add requirement
101 self.requirements[name] = install_req
102 # FIXME: what about other normalizations? E.g., _ vs. -?
103 if name.lower() != name:
104 self.requirement_aliases[name.lower()] = name
105 result = [install_req]
106 else:
107 # Assume there's no need to scan, and that we've already
108 # encountered this for scanning.
109 result = []
110 if not install_req.constraint and existing_req.constraint:
111 if (install_req.link and not (existing_req.link and
112 install_req.link.path == existing_req.link.path)):
113 self.reqs_to_cleanup.append(install_req)
114 raise InstallationError(
115 "Could not satisfy constraints for '%s': "
116 "installation from path or url cannot be "
117 "constrained to a version" % name,
118 )
119 # If we're now installing a constraint, mark the existing
120 # object for real installation.
121 existing_req.constraint = False
122 existing_req.extras = tuple(
123 sorted(set(existing_req.extras).union(
124 set(install_req.extras))))
125 logger.debug("Setting %s extras to: %s",
126 existing_req, existing_req.extras)
127 # And now we need to scan this.
128 result = [existing_req]
129 # Canonicalise to the already-added object for the backref
130 # check below.
131 install_req = existing_req
132
133 # We return install_req here to allow for the caller to add it to
134 # the dependency information for the parent package.
135 return result, install_req
136
137 def has_requirement(self, project_name):
138 name = project_name.lower()
139 if (name in self.requirements and
140 not self.requirements[name].constraint or
141 name in self.requirement_aliases and
142 not self.requirements[self.requirement_aliases[name]].constraint):
143 return True
144 return False
145
146 @property
147 def has_requirements(self):
148 return list(req for req in self.requirements.values() if not
149 req.constraint) or self.unnamed_requirements
150
151 def get_requirement(self, project_name):
152 for name in project_name, project_name.lower():
153 if name in self.requirements:
154 return self.requirements[name]
155 if name in self.requirement_aliases:
156 return self.requirements[self.requirement_aliases[name]]
157 raise KeyError("No project with the name %r" % project_name)
158
159 def cleanup_files(self):
160 """Clean up files, remove builds."""
161 logger.debug('Cleaning up...')
162 with indent_log():
163 for req in self.reqs_to_cleanup:
164 req.remove_temporary_source()