Commit Graph

223 Commits

Author SHA1 Message Date
Nguyễn Gia Phong 18c803a413 Check hashes of memoized downloads 2020-08-11 22:40:42 +07:00
Nguyễn Gia Phong 39d296eeb8 Clean up code style and internal interface
Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com>
Co-Authored-By: Chris Hunt <chrahunt@gmail.com>
2020-08-11 22:40:39 +07:00
Nguyễn Gia Phong 078e0effb7 Add memoization mechanism for file download
This is intentionally dependent from caching, which relies on cache dir.
2020-08-11 22:39:42 +07:00
Nguyễn Gia Phong e62f16e969 Make Downloader perform the download 2020-08-11 22:36:08 +07:00
Nguyễn Gia Phong 11f7994a66 Revise method fetching metadata using lazy wheels
* Rename it to fit the fact that it no longer handle
  fetching _not_ using lazy wheels
* Use self as the first parameter
* Unnest the checks with additional logs showing reason
  when lazy wheel is not used
2020-08-06 18:43:02 +07:00
Nguyễn Gia Phong 487d00295c Define RequirementPreparer._session 2020-08-06 18:42:59 +07:00
Chris Hunt 8b838ebb89 Prepare lazy wheels more so they are downloaded
This keeps all knowledge about preparation and types of requirements in
`RequirementPreparer`, so there's one place to look when we're ready to
start breaking it apart later.
2020-08-02 19:36:29 -04:00
Chris Hunt c7ade159d4 Pass link to _fetch_metadata instead of req
Removes dependence on `InstallRequirement`.
2020-08-02 19:36:29 -04:00
Chris Hunt 21db4f3096 Log in one common location
Reduces dependence on `InstallRequirement` being passed to
`_fetch_metadata`.
2020-08-02 19:36:29 -04:00
Chris Hunt 6c4d4f3b78 Move _fetch_metadata to RequirementPreparer
The fact that all of this functionality can be put in terms of the
`RequirementPreparer` indicates that, at least at this point, this is
the cleanest place to put this functionality.
2020-08-02 19:36:29 -04:00
Chris Hunt f0d4df10eb Propagate lazy_wheel option through RequirementPreparer
Reduces dependence on Candidate (and Resolver (and Factory)).
2020-08-02 18:40:11 -04:00
Nguyễn Gia Phong b795c9a7d6 Abstract away AbstractDistribution in higher-level resolver code 2020-07-26 17:13:04 +07:00
gutsytechster 8c267e6e39
feat(pip/_internal/*): Use custom raise_for_status method 2020-07-08 18:08:55 +05:30
Chris Hunt c9f87a645b Inline constant variable 2020-07-06 21:19:43 -04:00
Chris Hunt d3955e7837 Don't unpack wheels during preparation
For some time we have not needed to pre-emptively unpack wheels as part
of metadata processing, but kept the existing logic because the
behavior would start to diverge more for different package types. In
this case, though, removing the special cases for wheels makes this
logic a bit simpler, so it is worth doing.
2020-07-06 21:15:35 -04:00
Pradyun Gedam 343f863785
Apply suggestions from code review 2020-06-17 23:20:55 +05:30
Nguyễn Gia Phong 8b5ff72a13 Make linked req hashes an independant method 2020-06-17 23:11:46 +07:00
Nguyễn Gia Phong eb2deab2f6 Move req.source_dir ensure out 2020-06-17 23:07:29 +07:00
Nguyễn Gia Phong 6bb0d289f8 Move link log from prepare_linked_requirement 2020-06-17 23:03:08 +07:00
Tzu-ping Chung 09a7f271c7 Only attach UUID to build dir for spec candidates
These are the only cases where backtracking can happen. This approach
also accounts for VCS requirements relying on the same ensure function
to do cloning :/
2020-06-04 23:26:19 +08:00
Pradyun Gedam 0bd624275d
Revert "build in place"
This reverts commit 88e6e6bc5c.
2020-05-13 02:50:10 +05:30
Pradyun Gedam 1b90e1bccf
Revert "remove _copy_source_tree and friends"
This reverts commit 873f1e6332.
2020-05-13 02:50:10 +05:30
Stéphane Bidoul 873f1e6332
remove _copy_source_tree and friends 2020-04-12 12:00:57 +02:00
Stéphane Bidoul 88e6e6bc5c
build in place 2020-04-12 12:00:57 +02:00
Miro Hrončok 98aa09cf88 Prevent infinite recursion with pip wheel with $TMPDIR in $PWD
During a build of extension module within `pip wheel` the source directory is
recursively copied in a temporary directory.

See https://github.com/pypa/pip/issues/7555

When the temporary directory is inside the source directory
(for example by setting `TMPDIR=$PWD/tmp`) this caused an infinite recursion
that ended in:

    [Errno 36] File name too long

We prevent that buy never copying the target to the target in _copy_source_tree.

Fixes https://github.com/pypa/pip/issues/7872
2020-03-19 18:07:56 +01:00
Chris Hunt fad99dce4a Inline _copy_file 2020-03-08 18:10:17 -04:00
Chris Hunt cd5d8b7865 Inline unconditional block 2020-03-08 18:10:17 -04:00
Chris Hunt 36d52edeb4 Inline variable 2020-03-08 18:10:17 -04:00
Chris Hunt e1d1b1c192 Remove dead code
Since download_location doesn't exist, this block could've never been
executed.
2020-03-08 18:10:16 -04:00
Chris Hunt b0cd7a7a0b Assert that download_location doesn't exist in _copy_file 2020-03-08 18:04:43 -04:00
Chris Hunt 420a6d26de Pass combined download_location to _copy_file
This makes the function arguments look more like `src` and `dest`,
which makes more sense for a file copying function.
2020-03-08 18:01:49 -04:00
Pradyun Gedam 3c684b5910
Merge pull request #7695 from chrahunt/refactor/remove-confusing-comment
Remove confusing comment from operations.prepare
2020-02-06 18:50:18 +05:30
Chris Hunt 8197a4bbc5 Do not write delete marker file to track source_dir delete preference
Previously we were writing a delete marker file which is checked in
InstallRequirement.remove_temporary_source which is only invoked if the
user did not pass --no-clean (and a PreviousBuildDirError was not
raised). Since our TempDirectory machinery now respects these conditions
we can just wrap our source directory in that instead of using this
ad-hoc mechanism for tracking our delete preference.

This will let us clean up a lot of dead code that only existed for this
use case.
2020-02-05 20:14:44 -05:00
Chris Hunt c7cb3cd81d Calculate autodelete_unpacked earlier in prepare_linked_requirement
We want to use this value to determine whether a globally-managed
source_dir should delegate choosing deletion to the global tempdir
manager, so it needs to be above our call to
InstallRequirement.ensure_has_source_dir.
2020-02-05 20:14:44 -05:00
Chris Hunt e69d10637b Remove confusing comment from operations.prepare
prepare_linked_requirements only handles non-editable requirements, so
this comment seems like its been misplaced over several years of
refactoring.
2020-02-04 21:57:43 -05:00
Chris Hunt 4acc059cfd Remove unused argument 2020-02-04 21:55:42 -05:00
Chris Hunt c825c53f76 Rename unpack_{file,http}_url since they no longer unpack 2020-02-04 21:55:12 -05:00
Chris Hunt ada2f55f13 Inline file variable 2020-02-04 21:49:42 -05:00
Chris Hunt 135f2ac0ef Move unpacking into unpack_url 2020-02-04 21:49:42 -05:00
Chris Hunt 35a52c1397 Hold file in intermediate variable in unpack_url 2020-02-04 21:49:42 -05:00
Chris Hunt 71eaa4658f Return File from unpack_* functions
Since we need both the file path and content type to unpack, and we want
to move unpacking out of the lower-level functions, return all the
information needed so it's easier to move the unpacking out.
2020-02-04 21:49:42 -05:00
Chris Hunt 791725aad9 Move directory handling from unpack_file_url to unpack_url 2020-02-04 21:49:42 -05:00
Chris Hunt 395787bebc Inline link.file_path in unpack_file_url 2020-02-04 21:49:42 -05:00
Chris Hunt 062ccf9dba Use early-return style in unpack_url
This will make it easier to move directory handling up to unpack_url.
2020-02-04 21:49:42 -05:00
Chris Hunt 71e0ea19af Assert req.source_dir is None during linked requirement preparation
req.source_dir is only set by:

1. `InstallRequirement.__init__`
2. `InstallRequirement.ensure_has_source_dir`

`InstallRequirement.__init__` is only called with source_dir for
editable requirements, for which we would not call
`RequirementPreparer.prepare_linked_requirement` (only
`prepare_editable_requirement`).

We will use this assertion for justifying later refactoring.
2020-01-08 20:11:28 -05:00
Stéphane Bidoul (ACSONE) 68e49b9613 Remove redundant expanduser for download_dir in preparer
Since
- download_dir is only set by the download command
- download_dir is
normalized at the beginning of the download command
- path normalization includes expanduser
Therefore expanduser in the preparer is redundant
2020-01-01 18:54:08 +01:00
Stéphane Bidoul (ACSONE) a6d212383b
Remove redundant path normalization in preparer
wheel_download_dir is normalized at the
beginning of the wheel command
2019-12-31 05:32:42 +01:00
Chris Hunt ce9ddbb600 Move download file copying out of unpacking functions
Now our "unpacking" functions aren't also for sometimes populating
the download directory.
2019-12-26 11:12:17 -05:00
Chris Hunt 5c90145462 Switch conditions 2019-12-24 16:59:24 -05:00
Chris Hunt 554db9230d Move directory requirement download logging out of unpack_file_url
One less use of `download_dir` in `unpack_file_url`, which will make it
easier to factor out.
2019-12-24 16:56:24 -05:00
Christopher Hunt ab12706aaa
Merge pull request #7478 from chrahunt/refactor/make-functional-download-tests
Make unpack_* unit tests into functional tests
2019-12-17 07:55:29 +08:00
Chris Hunt 327c295554 Keep path to downloaded archive on InstallRequirement
Now we'll be able to transition other parts of the code to use
pre-existing archives directly instead of relying on unpacked sources.
2019-12-14 11:59:42 -05:00
Christopher Hunt fedde5fa2c
Do not cleanup archive download tempdir immediately (#7479)
* Do not cleanup download tempdir immediately

The previous logic forced us to handle populating the download directory
in this function right next to the download and hash checking. By
extending the lifetime of the directory we can more easily separate the
code.

This also allows for additional optimizations later: by using metadata
from wheels directly instead of unpacking them, we can avoid extracting
wheels unnecessarily. Unpacked files can be easily 3x larger than the
archives themselves, so this should reduce disk utilization and general
IO significantly.
2019-12-14 23:19:25 +08:00
Chris Hunt d30f406c37 Check file actually used against hashes
This makes the behavior of this function easier to test, since we can
use a different file to distinguish the already-downloaded case from the
existing-file-hash-failed case.
2019-12-13 20:30:45 -05:00
Chris Hunt 7dea92e5b3 Replace already_downloaded_path with existence check
These statements are equivalent, so we exchange them. This will make it
easier to factor the download_dir concerns out of these functions.
2019-12-13 00:46:44 -05:00
Chris Hunt 6b0a79501c Assert that target file does not exist
_check_download_dir will only return a falsy value if either:

* the provided path does not exist
* the hash does not match - in which case the file is unlinked

so the file cannot exist at either of these points.
2019-12-12 21:18:03 -05:00
Maxim Kurnikov b69560661b remove disallow_untyped_defs=False for pip._internal.distributions, pip._internal.operations.prepare 2019-12-12 21:35:37 +01:00
Chris Hunt cf743dd245 Remove unnecessary unlink in unpack_http_url
The file is downloaded into a TempDirectory which will get cleaned up at
the end of the `with` block, so no need to explicitly unlink the file.
2019-12-08 22:33:51 +01:00
Chris Hunt 24d2f1e719 Remove unused arguments 2019-12-05 20:29:43 -05:00
Chris Hunt 7db57478a2 Construct Downloader outside RequirementPreparer
Reduces RequirementPreparer responsibilities, and will let us get rid of
some constructor arguments.
2019-12-05 20:26:53 -05:00
Chris Hunt 78a221cf71 Move Downloader to network.download
This will help us move Downloader construction out of
RequirementPreparer, reducing its concerns and making it easier to test
in isolation.
2019-12-04 18:31:53 -05:00
Chris Hunt 3a2ff979de Move _http_get_download to network.download 2019-12-04 18:31:53 -05:00
Chris Hunt e354b728dc Move _get_http_response_filename to network.download 2019-12-04 18:31:53 -05:00
Chris Hunt 762e4a0817 Move parse_content_disposition to network.download 2019-12-04 18:31:53 -05:00
Chris Hunt 32b0fc23ab Move sanitize_content_filename to network.download 2019-12-04 18:31:53 -05:00
Chris Hunt 3fbc991f0c Move _prepare_download to network.download 2019-12-04 18:31:53 -05:00
Chris Hunt 864f78bd96 Add network.download module
This will be home to Dowloader, Download, and associated helper
functions. Since this is an abstraction over PipSession, it makes
sense to keep these functions in a separate module.

Also move a helper function here from operations.prepare.
2019-12-04 18:30:27 -05:00
Chris Hunt aaabdfc2f7 Switch to early-return in _prepare_download
Makes this function simpler by removing a local variable and reduces
overall lines of code.
2019-11-29 10:26:37 -05:00
Chris Hunt d279807a0e Extract chunks into separate variable 2019-11-29 10:24:56 -05:00
Chris Hunt 46adcc89a6 Remove outdated comment in operations.prepare
There are several reasons why we don't trace progress as indicated a few
lines above.
2019-11-29 10:21:24 -05:00
Xavier Fernandez db1a2754bb Fix logging of cached response
Cached responses often (always ?) provide a length meaning they were
never logged as such.
2019-11-25 23:15:00 +01:00
Chris Hunt 59f22068d4 Move Downloader construction to RequirementPreparer.__init__
Just one step away from pulling this out of operations.prepare
altogether.
2019-11-21 19:11:46 -05:00
Chris Hunt 3c8be92c32 Move Downloader out of unpack_url
This simplifies the work done in the operations.prepare helper functions
and also opens up the door to remove session and progress_bar from
RequirementPreparer itself.
2019-11-21 19:11:46 -05:00
Chris Hunt 19806574e5 Move Downloader out of unpack_http_url
Reduces scope of session and progress_bar.
2019-11-21 19:11:46 -05:00
Chris Hunt 4be0a5445a Move Downloader up out of _download_http_url
Reduces exposure of session and progress_bar.
2019-11-21 19:11:46 -05:00
Chris Hunt 3ce317890e Introduce Downloader for progress-showing downloads 2019-11-21 19:05:42 -05:00
Chris Hunt e4d2d34fe1 Represent download as its own type
This abstraction will let us hide details about the actual downloading
and display of progress from most of operations.prepare.
2019-11-21 19:04:28 -05:00
Chris Hunt e706af20fe Simplify writing file chunks
A plain loop is easier to follow than chained generators consumed by
a helper function, and reduces the number of objects being passed around
just to download a file.
2019-11-19 17:06:18 -05:00
Chris Hunt dca556fdaa Check hashes after download is complete
Instead of computing hashes on-the-fly we do it after fully downloading
the file. This step will let us move hash checking to a higher-level
function without introducing a lot of complexity.
2019-11-19 17:06:18 -05:00
Christopher Hunt 9ae2e6440d
Merge pull request #7365 from chrahunt/refactor/cleanup-prepare-2
Cleanup operations.prepare download functions
2019-11-20 06:05:25 +08:00
Ahilya 5051c74d5e Redact passwords from index-url during download
Made changes in _download_url so that it relies on
redact_auth_from_url from misc to redact passwords.

Closes https://github.com/pypa/pip/issues/6783
2019-11-17 20:54:32 +05:30
Chris Hunt 09b19dbbb8 Move actual session.get call into separate function
By moving this call (and its long explanation) to a separate function,
diffs for later refactoring will be easier to review.
2019-11-16 12:37:47 -05:00
Chris Hunt a9997127b9 Don't pass explicit step size to progress indicator
Now the place we construct the progress indicator doesn't need to know
about our strategy for consuming the response, freeing us to extract the
chunk iterator construction into the caller.
2019-11-16 12:37:47 -05:00
Chris Hunt 6e68c8d9ba Retrieve HTTP response size in separate function
Also use `None` as the "no size available" indicator value, which is
already compatible with all of its current uses.
2019-11-16 12:37:44 -05:00
Chris Hunt dd08330ac3 Construct download name in separate function
Later, we will use this to make a dedicated object that represents
our download.
2019-11-16 12:26:54 -05:00
Chris Hunt f5f1761aba Inline content-type retrieval
This makes it easier to factor out the filename calculation.
2019-11-16 12:26:14 -05:00
Pradyun Gedam ccd2ced9bc
Add disallow_any_generics = True to mypy configuration (#7110) 2019-11-14 20:46:21 +05:30
Maxim Kurnikov d1452ffabd add global disallow_any_generics=True 2019-11-12 21:08:48 +03:00
Chris Hunt 16ffd1a9c4 Normalize style 2019-11-11 22:36:46 -05:00
Chris Hunt 95375a5213 Make session a required parameter in operations.prepare 2019-11-11 22:34:52 -05:00
Pradyun Gedam 11b3fc2265
Drop use_user_site argument from prepare_editable_requirement 2019-11-10 13:51:36 +05:30
Pradyun Gedam c9606b86e1
Add use_user_site to RequirementPreparer 2019-11-10 13:51:29 +05:30
Pradyun Gedam 0612685e7e
Stop passing require_hashes to Resolver directly 2019-11-10 01:52:03 +05:30
Pradyun Gedam c0afe5c81d
Add require_hashes to RequirementPreparer 2019-11-09 12:13:29 +05:30
Chris Hunt deac2343dc Don't pass PackageFinder to Preparer from Resolver
Preparer's overall responsibilities align more with having its own
reference to finder, which will help us remove it from resolver later.
2019-11-05 20:57:14 -05:00
Christopher Hunt a0ff620240
Merge pull request #7291 from chrahunt/refactor/cleanup-prepare-1
Cleanup operations.prepare
2019-11-04 19:39:24 +08:00
Chris Hunt 54efa9dbdb Reorder operations.prepare._download_url 2019-11-03 16:26:37 -05:00
Chris Hunt b873df49b0 Factor from_cache check into separate function 2019-11-03 15:29:19 -05:00
Chris Hunt e8976af4e1 Show download size if available
This simplifies the logic for displaying output.
2019-11-03 15:25:59 -05:00
Chris Hunt 5da6abf60d Move resp_chunks to network.utils
This generic piece of code only clutters operations.prepare, making it
harder to refactor.
2019-11-03 15:16:42 -05:00