Skip to content

Commit 714e7d1

Browse files
committed
Merge remote-tracking branch 'upstream/master' into issue-6222
2 parents f6f54da + 084d797 commit 714e7d1

File tree

17 files changed

+381
-132
lines changed

17 files changed

+381
-132
lines changed

docs/html/development/architecture/package-finding.rst

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ file to download for a package, given a requirement:
2424
is an HTML page of anchor links.
2525
2. Collect together all of the links (e.g. by parsing the anchor links
2626
from the HTML pages) and create ``Link`` objects from each of these.
27+
The :ref:`LinkCollector <link-collector-class>` class is responsible
28+
for both this step and the previous.
2729
3. Determine which of the links are minimally relevant, using the
2830
:ref:`LinkEvaluator <link-evaluator-class>` class. Create an
2931
``InstallationCandidate`` object (aka candidate for install) for each
@@ -39,6 +41,7 @@ The remainder of this section is organized by documenting some of the
3941
classes inside ``index.py``, in the following order:
4042

4143
* the main :ref:`PackageFinder <package-finder-class>` class,
44+
* the :ref:`LinkCollector <link-collector-class>` class,
4245
* the :ref:`LinkEvaluator <link-evaluator-class>` class,
4346
* the :ref:`CandidateEvaluator <candidate-evaluator-class>` class,
4447
* the :ref:`CandidatePreferences <candidate-preferences-class>` class, and
@@ -95,18 +98,47 @@ links.
9598
One of ``PackageFinder``'s main top-level methods is
9699
``find_best_candidate()``. This method does the following two things:
97100

98-
1. Calls its ``find_all_candidates()`` method, which reads and parses all the
99-
index URL's provided by the user, constructs a :ref:`LinkEvaluator
100-
<link-evaluator-class>` object to filter out some of those links, and then
101-
returns a list of ``InstallationCandidates`` (aka candidates for install).
102-
This corresponds to steps 1-3 of the :ref:`Overview <index-py-overview>`
103-
above.
101+
1. Calls its ``find_all_candidates()`` method, which gathers all
102+
possible package links by reading and parsing the index URL's and
103+
locations provided by the user (the :ref:`LinkCollector
104+
<link-collector-class>` class's ``collect_links()`` method), constructs a
105+
:ref:`LinkEvaluator <link-evaluator-class>` object to filter out some of
106+
those links, and then returns a list of ``InstallationCandidates`` (aka
107+
candidates for install). This corresponds to steps 1-3 of the
108+
:ref:`Overview <index-py-overview>` above.
104109
2. Constructs a ``CandidateEvaluator`` object and uses that to determine
105110
the best candidate. It does this by calling the ``CandidateEvaluator``
106111
class's ``compute_best_candidate()`` method on the return value of
107112
``find_all_candidates()``. This corresponds to steps 4-5 of the Overview.
108113

109114

115+
.. _link-collector-class:
116+
117+
The ``LinkCollector`` class
118+
***************************
119+
120+
The :ref:`LinkCollector <link-collector-class>` class is the class
121+
responsible for collecting the raw list of "links" to package files
122+
(represented as ``Link`` objects). An instance of the class accesses the
123+
various `PEP 503`_ HTML "simple repository" pages, parses their HTML,
124+
extracts the links from the anchor elements, and creates ``Link`` objects
125+
from that information. The ``LinkCollector`` class is "unintelligent" in that
126+
it doesn't do any evaluation of whether the links are relevant to the
127+
original requirement; it just collects them.
128+
129+
The ``LinkCollector`` class takes into account the user's :ref:`--find-links
130+
<--find-links>`, :ref:`--extra-index-url <--extra-index-url>`, and related
131+
options when deciding which locations to collect links from. The class's main
132+
method is the ``collect_links()`` method. The :ref:`PackageFinder
133+
<package-finder-class>` class invokes this method as the first step of its
134+
``find_all_candidates()`` method.
135+
136+
The ``LinkCollector`` class is the only class in the ``index.py`` module that
137+
makes network requests and is the only class in the module that depends
138+
directly on ``PipSession``, which stores pip's configuration options and
139+
state for making requests.
140+
141+
110142
.. _link-evaluator-class:
111143

112144
The ``LinkEvaluator`` class
@@ -191,7 +223,8 @@ The ``BestCandidateResult`` class
191223
The ``BestCandidateResult`` class is a convenience "container" class that
192224
encapsulates the result of finding the best candidate for a requirement.
193225
(By "container" we mean an object that simply contains data and has no
194-
business logic or state-changing methods of its own.)
226+
business logic or state-changing methods of its own.) It stores not just the
227+
final result but also intermediate values used to determine the result.
195228

196229
The class is the return type of both the ``CandidateEvaluator`` class's
197230
``compute_best_candidate()`` method and the ``PackageFinder`` class's

src/pip/_internal/cli/req_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class RequirementCommand(IndexGroupCommand):
141141

142142
@staticmethod
143143
def make_requirement_preparer(
144-
temp_directory, # type: TempDirectory
144+
temp_build_dir, # type: TempDirectory
145145
options, # type: Values
146146
req_tracker, # type: RequirementTracker
147147
download_dir=None, # type: str
@@ -151,8 +151,10 @@ def make_requirement_preparer(
151151
"""
152152
Create a RequirementPreparer instance for the given parameters.
153153
"""
154+
temp_build_dir_path = temp_build_dir.path
155+
assert temp_build_dir_path is not None
154156
return RequirementPreparer(
155-
build_dir=temp_directory.path,
157+
build_dir=temp_build_dir_path,
156158
src_dir=options.src_dir,
157159
download_dir=download_dir,
158160
wheel_download_dir=wheel_download_dir,

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def run(self, options, args):
125125
)
126126

127127
preparer = self.make_requirement_preparer(
128-
temp_directory=directory,
128+
temp_build_dir=directory,
129129
options=options,
130130
req_tracker=req_tracker,
131131
download_dir=options.download_dir,

src/pip/_internal/commands/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def run(self, options, args):
358358
wheel_cache
359359
)
360360
preparer = self.make_requirement_preparer(
361-
temp_directory=directory,
361+
temp_build_dir=directory,
362362
options=options,
363363
req_tracker=req_tracker,
364364
)

src/pip/_internal/commands/wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def run(self, options, args):
136136
)
137137

138138
preparer = self.make_requirement_preparer(
139-
temp_directory=directory,
139+
temp_build_dir=directory,
140140
options=options,
141141
req_tracker=req_tracker,
142142
wheel_download_dir=options.wheel_dir,

0 commit comments

Comments
 (0)