Skip to content

Commit 5fce05a

Browse files
authored
Merge pull request #8334 from pradyunsg/rename-parent-to-template
2 parents 03b11ee + b5a5bcf commit 5fce05a

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@
3838
logger = logging.getLogger(__name__)
3939

4040

41-
def make_install_req_from_link(link, parent):
41+
def make_install_req_from_link(link, template):
4242
# type: (Link, InstallRequirement) -> InstallRequirement
43-
assert not parent.editable, "parent is editable"
44-
if parent.req:
45-
line = str(parent.req)
43+
assert not template.editable, "template is editable"
44+
if template.req:
45+
line = str(template.req)
4646
else:
4747
line = link.url
4848
ireq = install_req_from_line(
4949
line,
50-
comes_from=parent.comes_from,
51-
use_pep517=parent.use_pep517,
52-
isolated=parent.isolated,
53-
constraint=parent.constraint,
50+
comes_from=template.comes_from,
51+
use_pep517=template.use_pep517,
52+
isolated=template.isolated,
53+
constraint=template.constraint,
5454
options=dict(
55-
install_options=parent.install_options,
56-
global_options=parent.global_options,
57-
hashes=parent.hash_options
55+
install_options=template.install_options,
56+
global_options=template.global_options,
57+
hashes=template.hash_options
5858
),
5959
)
6060
if ireq.link is None:
@@ -63,42 +63,42 @@ def make_install_req_from_link(link, parent):
6363
return ireq
6464

6565

66-
def make_install_req_from_editable(link, parent):
66+
def make_install_req_from_editable(link, template):
6767
# type: (Link, InstallRequirement) -> InstallRequirement
68-
assert parent.editable, "parent not editable"
68+
assert template.editable, "template not editable"
6969
return install_req_from_editable(
7070
link.url,
71-
comes_from=parent.comes_from,
72-
use_pep517=parent.use_pep517,
73-
isolated=parent.isolated,
74-
constraint=parent.constraint,
71+
comes_from=template.comes_from,
72+
use_pep517=template.use_pep517,
73+
isolated=template.isolated,
74+
constraint=template.constraint,
7575
options=dict(
76-
install_options=parent.install_options,
77-
global_options=parent.global_options,
78-
hashes=parent.hash_options
76+
install_options=template.install_options,
77+
global_options=template.global_options,
78+
hashes=template.hash_options
7979
),
8080
)
8181

8282

83-
def make_install_req_from_dist(dist, parent):
83+
def make_install_req_from_dist(dist, template):
8484
# type: (Distribution, InstallRequirement) -> InstallRequirement
8585
project_name = canonicalize_name(dist.project_name)
86-
if parent.req:
87-
line = str(parent.req)
88-
elif parent.link:
89-
line = "{} @ {}".format(project_name, parent.link.url)
86+
if template.req:
87+
line = str(template.req)
88+
elif template.link:
89+
line = "{} @ {}".format(project_name, template.link.url)
9090
else:
9191
line = "{}=={}".format(project_name, dist.parsed_version)
9292
ireq = install_req_from_line(
9393
line,
94-
comes_from=parent.comes_from,
95-
use_pep517=parent.use_pep517,
96-
isolated=parent.isolated,
97-
constraint=parent.constraint,
94+
comes_from=template.comes_from,
95+
use_pep517=template.use_pep517,
96+
isolated=template.isolated,
97+
constraint=template.constraint,
9898
options=dict(
99-
install_options=parent.install_options,
100-
global_options=parent.global_options,
101-
hashes=parent.hash_options
99+
install_options=template.install_options,
100+
global_options=template.global_options,
101+
hashes=template.hash_options
102102
),
103103
)
104104
ireq.satisfied_by = dist
@@ -236,7 +236,7 @@ class LinkCandidate(_InstallRequirementBackedCandidate):
236236
def __init__(
237237
self,
238238
link, # type: Link
239-
parent, # type: InstallRequirement
239+
template, # type: InstallRequirement
240240
factory, # type: Factory
241241
name=None, # type: Optional[str]
242242
version=None, # type: Optional[_BaseVersion]
@@ -246,11 +246,11 @@ def __init__(
246246
if cache_entry is not None:
247247
logger.debug("Using cached wheel link: %s", cache_entry.link)
248248
link = cache_entry.link
249-
ireq = make_install_req_from_link(link, parent)
249+
ireq = make_install_req_from_link(link, template)
250250

251251
if (cache_entry is not None and
252252
cache_entry.persistent and
253-
parent.link is parent.original_link):
253+
template.link is template.original_link):
254254
ireq.original_link_is_in_wheel_cache = True
255255

256256
super(LinkCandidate, self).__init__(
@@ -270,15 +270,15 @@ class EditableCandidate(_InstallRequirementBackedCandidate):
270270
def __init__(
271271
self,
272272
link, # type: Link
273-
parent, # type: InstallRequirement
273+
template, # type: InstallRequirement
274274
factory, # type: Factory
275275
name=None, # type: Optional[str]
276276
version=None, # type: Optional[_BaseVersion]
277277
):
278278
# type: (...) -> None
279279
super(EditableCandidate, self).__init__(
280280
link=link,
281-
ireq=make_install_req_from_editable(link, parent),
281+
ireq=make_install_req_from_editable(link, template),
282282
factory=factory,
283283
name=name,
284284
version=version,
@@ -295,12 +295,12 @@ class AlreadyInstalledCandidate(Candidate):
295295
def __init__(
296296
self,
297297
dist, # type: Distribution
298-
parent, # type: InstallRequirement
298+
template, # type: InstallRequirement
299299
factory, # type: Factory
300300
):
301301
# type: (...) -> None
302302
self.dist = dist
303-
self._ireq = make_install_req_from_dist(dist, parent)
303+
self._ireq = make_install_req_from_dist(dist, template)
304304
self._factory = factory
305305

306306
# This is just logging some messages, so we can do it eagerly.

src/pip/_internal/resolution/resolvelib/factory.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def _make_candidate_from_dist(
106106
self,
107107
dist, # type: Distribution
108108
extras, # type: FrozenSet[str]
109-
parent, # type: InstallRequirement
109+
template, # type: InstallRequirement
110110
):
111111
# type: (...) -> Candidate
112-
base = AlreadyInstalledCandidate(dist, parent, factory=self)
112+
base = AlreadyInstalledCandidate(dist, template, factory=self)
113113
if extras:
114114
return ExtrasCandidate(base, extras)
115115
return base
@@ -118,23 +118,23 @@ def _make_candidate_from_link(
118118
self,
119119
link, # type: Link
120120
extras, # type: FrozenSet[str]
121-
parent, # type: InstallRequirement
121+
template, # type: InstallRequirement
122122
name, # type: Optional[str]
123123
version, # type: Optional[_BaseVersion]
124124
):
125125
# type: (...) -> Candidate
126126
# TODO: Check already installed candidate, and use it if the link and
127127
# editable flag match.
128-
if parent.editable:
128+
if template.editable:
129129
if link not in self._editable_candidate_cache:
130130
self._editable_candidate_cache[link] = EditableCandidate(
131-
link, parent, factory=self, name=name, version=version,
131+
link, template, factory=self, name=name, version=version,
132132
)
133133
base = self._editable_candidate_cache[link] # type: BaseCandidate
134134
else:
135135
if link not in self._link_candidate_cache:
136136
self._link_candidate_cache[link] = LinkCandidate(
137-
link, parent, factory=self, name=name, version=version,
137+
link, template, factory=self, name=name, version=version,
138138
)
139139
base = self._link_candidate_cache[link]
140140
if extras:
@@ -151,11 +151,11 @@ def _iter_found_candidates(
151151
return ()
152152

153153
# The InstallRequirement implementation requires us to give it a
154-
# "parent", which doesn't really fit with graph-based resolution.
155-
# Here we just choose the first requirement to represent all of them.
154+
# "template". Here we just choose the first requirement to represent
155+
# all of them.
156156
# Hopefully the Project model can correct this mismatch in the future.
157-
parent = ireqs[0]
158-
name = canonicalize_name(parent.req.name)
157+
template = ireqs[0]
158+
name = canonicalize_name(template.req.name)
159159

160160
hashes = Hashes()
161161
extras = frozenset() # type: FrozenSet[str]
@@ -182,7 +182,7 @@ def _iter_found_candidates(
182182
candidate = self._make_candidate_from_dist(
183183
dist=installed_dist,
184184
extras=extras,
185-
parent=parent,
185+
template=template,
186186
)
187187
candidates[installed_version] = candidate
188188

@@ -197,7 +197,7 @@ def _iter_found_candidates(
197197
candidate = self._make_candidate_from_link(
198198
link=ican.link,
199199
extras=extras,
200-
parent=parent,
200+
template=template,
201201
name=name,
202202
version=ican.version,
203203
)
@@ -240,7 +240,7 @@ def make_requirement_from_install_req(self, ireq):
240240
cand = self._make_candidate_from_link(
241241
ireq.link,
242242
extras=frozenset(ireq.extras),
243-
parent=ireq,
243+
template=ireq,
244244
name=canonicalize_name(ireq.name) if ireq.name else None,
245245
version=None,
246246
)
@@ -328,15 +328,15 @@ def should_reinstall(self, candidate):
328328
def _report_requires_python_error(
329329
self,
330330
requirement, # type: RequiresPythonRequirement
331-
parent, # type: Candidate
331+
template, # type: Candidate
332332
):
333333
# type: (...) -> UnsupportedPythonVersion
334-
template = (
334+
message_format = (
335335
"Package {package!r} requires a different Python: "
336336
"{version} not in {specifier!r}"
337337
)
338-
message = template.format(
339-
package=parent.name,
338+
message = message_format.format(
339+
package=template.name,
340340
version=self._python_candidate.version,
341341
specifier=str(requirement.specifier),
342342
)

0 commit comments

Comments
 (0)