Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.operations.prepare Namespace Reference

Data Structures

class  File
 
class  RequirementPreparer
 

Functions

BaseDistribution _get_prepared_distribution (InstallRequirement req, BuildTracker build_tracker, PackageFinder finder, bool build_isolation, bool check_build_deps)
 
None unpack_vcs_link (Link link, str location, int verbosity)
 
File get_http_url (Link link, Downloader download, Optional[str] download_dir=None, Optional[Hashes] hashes=None)
 
File get_file_url (Link link, Optional[str] download_dir=None, Optional[Hashes] hashes=None)
 
Optional[Fileunpack_url (Link link, str location, Downloader download, int verbosity, Optional[str] download_dir=None, Optional[Hashes] hashes=None)
 
Optional[str] _check_download_dir (Link link, str download_dir, Optional[Hashes] hashes, bool warn_on_hash_mismatch=True)
 

Variables

 logger = logging.getLogger(__name__)
 

Detailed Description

Prepares a distribution for installation

Function Documentation

◆ _check_download_dir()

Optional[str] _check_download_dir ( Link  link,
str  download_dir,
Optional[Hashes hashes,
bool   warn_on_hash_mismatch = True 
)
protected
Check download_dir for previously downloaded file with correct hash
If a correct file is found return its path else None

Definition at line 181 of file prepare.py.

186) -> Optional[str]:
187 """Check download_dir for previously downloaded file with correct hash
188 If a correct file is found return its path else None
189 """
190 download_path = os.path.join(download_dir, link.filename)
191
192 if not os.path.exists(download_path):
193 return None
194
195 # If already downloaded, does its hash match?
196 logger.info("File was already downloaded %s", download_path)
197 if hashes:
198 try:
199 hashes.check_against_path(download_path)
200 except HashMismatch:
201 if warn_on_hash_mismatch:
203 "Previously-downloaded file %s has bad hash. Re-downloading.",
204 download_path,
205 )
206 os.unlink(download_path)
207 return None
208 return download_path
209
210
for i

References i.

Referenced by pip._internal.operations.prepare.get_file_url(), pip._internal.operations.prepare.get_http_url(), RequirementPreparer.prepare_linked_requirement(), and RequirementPreparer.prepare_linked_requirements_more().

Here is the caller graph for this function:

◆ _get_prepared_distribution()

BaseDistribution _get_prepared_distribution ( InstallRequirement  req,
BuildTracker  build_tracker,
PackageFinder  finder,
bool  build_isolation,
bool  check_build_deps 
)
protected
Prepare a distribution for installation.

Definition at line 59 of file prepare.py.

65) -> BaseDistribution:
66 """Prepare a distribution for installation."""
67 abstract_dist = make_distribution_for_install_requirement(req)
68 with build_tracker.track(req):
70 finder, build_isolation, check_build_deps
71 )
73
74

References i.

Referenced by RequirementPreparer._prepare_linked_requirement(), and RequirementPreparer.prepare_editable_requirement().

Here is the caller graph for this function:

◆ get_file_url()

File get_file_url ( Link  link,
Optional[str]   download_dir = None,
Optional[Hashes]   hashes = None 
)
Get file and optionally check its hash.

Definition at line 114 of file prepare.py.

116) -> File:
117 """Get file and optionally check its hash."""
118 # If a download dir is specified, is the file already there and valid?
119 already_downloaded_path = None
120 if download_dir:
121 already_downloaded_path = _check_download_dir(link, download_dir, hashes)
122
123 if already_downloaded_path:
124 from_path = already_downloaded_path
125 else:
126 from_path = link.file_path
127
128 # If --require-hashes is off, `hashes` is either empty, the
129 # link's embedded hash, or MissingHashes; it is required to
130 # match. If --require-hashes is on, we are satisfied by any
131 # hash in `hashes` matching: a URL-based or an option-based
132 # one; no internet-sourced hash will be in `hashes`.
133 if hashes:
135 return File(from_path, None)
136
137

References pip._internal.operations.prepare._check_download_dir(), and i.

Referenced by pip._internal.operations.prepare.unpack_url().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_http_url()

File get_http_url ( Link  link,
Downloader  download,
Optional[str]   download_dir = None,
Optional[Hashes]   hashes = None 
)

Definition at line 90 of file prepare.py.

95) -> File:
96 temp_dir = TempDirectory(kind="unpack", globally_managed=True)
97 # If a download dir is specified, is the file already downloaded there?
98 already_downloaded_path = None
99 if download_dir:
100 already_downloaded_path = _check_download_dir(link, download_dir, hashes)
101
102 if already_downloaded_path:
103 from_path = already_downloaded_path
104 content_type = None
105 else:
106 # let's download to a tmp dir
107 from_path, content_type = download(link, temp_dir.path)
108 if hashes:
110
111 return File(from_path, content_type)
112
113

References pip._internal.operations.prepare._check_download_dir(), and i.

Referenced by RequirementPreparer._fetch_metadata_using_link_data_attr(), and pip._internal.operations.prepare.unpack_url().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unpack_url()

Optional[File] unpack_url ( Link  link,
str  location,
Downloader  download,
int  verbosity,
Optional[str]   download_dir = None,
Optional[Hashes]   hashes = None 
)
Unpack link into location, downloading if required.

:param hashes: A Hashes object, one of whose embedded hashes must match,
    or HashMismatch will be raised. If the Hashes is empty, no matches are
    required, and unhashable types of requirements (like VCS ones, which
    would ordinarily raise HashUnsupported) are allowed.

Definition at line 138 of file prepare.py.

145) -> Optional[File]:
146 """Unpack link into location, downloading if required.
147
148 :param hashes: A Hashes object, one of whose embedded hashes must match,
149 or HashMismatch will be raised. If the Hashes is empty, no matches are
150 required, and unhashable types of requirements (like VCS ones, which
151 would ordinarily raise HashUnsupported) are allowed.
152 """
153 # non-editable vcs urls
154 if link.is_vcs:
155 unpack_vcs_link(link, location, verbosity=verbosity)
156 return None
157
158 assert not link.is_existing_dir()
159
160 # file urls
161 if link.is_file:
162 file = get_file_url(link, download_dir, hashes=hashes)
163
164 # http urls
165 else:
166 file = get_http_url(
167 link,
168 download,
169 download_dir,
170 hashes=hashes,
171 )
172
173 # unpack the archive to the build dir location. even when only downloading
174 # archives, they have to be unpacked to parse dependencies, except wheels
175 if not link.is_wheel:
176 unpack_file(file.path, location, file.content_type)
177
178 return file
179
180

References pip._internal.operations.prepare.get_file_url(), pip._internal.operations.prepare.get_http_url(), i, and pip._internal.operations.prepare.unpack_vcs_link().

Referenced by RequirementPreparer._prepare_linked_requirement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unpack_vcs_link()

None unpack_vcs_link ( Link  link,
str  location,
int  verbosity 
)

Definition at line 75 of file prepare.py.

75def unpack_vcs_link(link: Link, location: str, verbosity: int) -> None:
77 assert vcs_backend is not None
78 vcs_backend.unpack(location, url=hide_url(link.url), verbosity=verbosity)
79
80

References i.

Referenced by pip._internal.operations.prepare.unpack_url().

Here is the caller graph for this function:

Variable Documentation

◆ logger

logger = logging.getLogger(__name__)

Definition at line 56 of file prepare.py.