Commit Graph

107 Commits

Author SHA1 Message Date
Chris Hunt dcd5cadcfd Expect a plain list in get_csv_rows_for_installed
This makes get_csv_rows_for_installed simpler, because it is not
modifying its arguments. We can also more easily refactor RECORD file
reading since it is now decoupled from getting the installed RECORD file
rows.
2020-07-03 12:25:12 -04:00
Christopher Hunt ea7ee7d8e0
Merge pull request #8526 from chrahunt/reduce-dependence-on-files
Reduce dependence on disk files during Wheel installation
2020-07-03 11:32:38 -04:00
Christopher Hunt cba5f11057
Merge pull request #8524 from chrahunt/remove-always-applicable-comments
Remove encouraging comments
2020-07-03 09:17:53 -04:00
Christopher Hunt 8097de5364
Merge pull request #8528 from chrahunt/simplify-get-entrypoints
Remove redundant entrypoint text normalization
2020-07-03 09:10:10 -04:00
Chris Hunt abed1d6d39 Set `data_dirs` closer to first use
Reducing the scope of variables reduces possible dependencies between
parts of this function, and will make it easier to extract this section
into its own function.
2020-07-03 09:00:07 -04:00
Chris Hunt 01e0d8befb Get data directories directly from zip
This reduces our dependence on the files being extracted to the
filesystem.

Compare the name extraction to the similar code in
`utils.wheel.wheel_dist_info_dir`.

We don't need to give `.data` directories the same strict
treatment (yet) because it isn't inconvenient if there happen
to be multiple of them in a single Wheel file.
2020-07-03 08:59:36 -04:00
Chris Hunt d93b8b3e53 Do not shadow outer variable in loop
`source` is provided as an argument to this function. Shadowing it can
lead to type errors if the intermediate types change.
2020-07-03 08:59:12 -04:00
Chris Hunt 541ce8748a Remove redundant entrypoint text normalization
Currently we do processing in `get_entrypoints` so incoming text is more compatible
with `pkg_resources`. It turns out that `pkg_resources` is already doing the same normalization,
so we can omit it.

This simplifies `get_entrypoints`, opening the way for us to pass it a plain string instead
of a file path.
2020-07-02 21:50:11 -04:00
Chris Hunt 7c2fa59cd3 Add early return in fix_script
No behavior change, just making this function easier to refactor.
2020-07-02 20:57:51 -04:00
Chris Hunt 09d75b8a58 Remove encouraging comments
These comments are relevant to this function, since it is long
overdue for refactoring. This code isn't special in that regard, and we
should feel free to consider any piece of code eligible to be broken up
or put into a class. So we remove these comments in fairness to the rest
of the code, and to remove a distraction during upcoming code reviews.
2020-07-02 20:40:02 -04:00
Pradyun Gedam e774eccf46
Merge pull request #8343 from uranusjr/entrypoint-unicode 2020-06-30 14:33:24 +00:00
Tzu-ping Chung f81fd19a7b Ensure entry points are read as UTF-8
Like the wheel metadata, this is, strictly speaking, unspecified. But
UTF-8 is the de-facto standard, and we should support that.
2020-06-10 20:58:20 +08:00
Stéphane Bidoul 21df86f197
Add REQUESTED support to install_wheel 2020-05-31 18:33:50 +02:00
cjc7373 a9c8dc5468 fix normalize path for Windows 2020-05-22 17:29:51 +08:00
Tzu-ping Chung 0a31845007 Explode the record row for readability 2020-05-19 16:03:51 +08:00
Tzu-ping Chung dd50a03f10 Use unicode for filesystem stuff on Python 2 2020-05-19 16:03:51 +08:00
Tzu-ping Chung dc4171c213 Python 2 works but not tested 2020-05-19 16:03:51 +08:00
Tzu-ping Chung 7a54132b16 Can drop the strict-optional marker now 2020-05-19 16:03:51 +08:00
Tzu-ping Chung 2339a7a859 Fix installation of wheel with non-ASCII entries
This mainly deals with correctly recording the wheel content in the
RECORD metadata. This metadata file must be written in UTF-8, but the
actual files need to be installed to the filesystem, the encoding of
which is not (always) UTF-8. So we need to carefully handle file name
encoding/decoding when comparing RECORD entries to the actual file.

The fix here makes sure we always use the correct encoding by adding
strict type hints. The entries in RECORD is decoded/encoded with UTF-8
on the read/write boundaries to make sure we always deal with text
types. A type-hint-only type RecordPath is introduced to make sure this
is enforced (because Python 2 "helpfully" coerces str to unicode with
the wrong encoding).
2020-05-19 16:03:51 +08:00
Devesh Kumar Singh 60f00b837a Upgrade flake8 to 3.8.1
Co-Authored-By: Anthony Sottile <asottile@umich.edu>
2020-05-18 21:58:26 +05:30
Devesh Kumar Singh 4d208b02b4 Cast record file to typing.IO[str] to appease mypy for python 2 2020-05-18 12:27:26 +05:30
Devesh Kumar Singh bd07bfb8db Cast record_file to io.StringIO for Python 3 to appease mypy 2020-05-14 17:42:03 +05:30
Devesh Kumar Singh 2423d58ea5 Fix generated file mode to use bitwise AND 2020-04-29 10:05:29 +05:30
Tzu-ping Chung 2245fceb3a Make the permission logic more generic 2020-04-27 16:51:01 +08:00
Tzu-ping Chung f1977cfa5f Set permission on manually created metadata files 2020-04-26 18:18:28 +08:00
Tzu-ping Chung 452d39eb2f Wrap wheel file generation in function 2020-04-26 17:43:21 +08:00
Stéphane Bidoul f77944733d
Add DirectUrl support to install_wheel 2020-04-01 22:56:59 +02:00
Nguyễn Gia Phong 209c74f690 Use better temporary files mechanism 2020-04-01 22:02:34 +07:00
Jason R. Coombs 3511d3d493 Convert the remaining '%' formatters to '.format'. Fixes #6973. 2020-03-06 12:43:03 -05:00
Deepak Sharma d31cf696e8 string_formatting 2020-01-30 20:33:00 +05:30
Chris Hunt b263fcc105 Move parse_wheel and supporting functions to utils.wheel
In order to parse metadata from wheel files directly we want to reuse
parse_wheel. Moving it out helps avoid creating an unnecessary
dependence on operations.install.wheel.
2020-01-04 23:11:51 +01:00
Chris Hunt 2f92826081 Extract basic wheel parsing into separate function
This functions as a guard for the rest of our wheel-handling code,
ensuring that we will only get past this point if we have a wheel that
we should be able to handle version-wise.

We return a tuple instead of bundling up the result in a dedicated type
because it's the simplest option. The interface will be easy to update
later if the need arises.
2020-01-01 17:51:25 -05:00
Chris Hunt d5b4c15105 Remove dead code from wheel_metadata
Since we don't pass the source directory anymore, remove the tests
and implementation.
2020-01-01 17:51:24 -05:00
Chris Hunt a2af0f9468 Get WHEEL metadata from wheel file directly 2020-01-01 17:26:20 -05:00
Chris Hunt 2519e9740c Split try block in wheel_metadata
Makes it simpler to substitute in zip-derived WHEEL extraction.
2020-01-01 17:26:20 -05:00
Chris Hunt 62721eb5da Remove dead code
Since we don't pass the source dir anymore, we can simplify the tests
and implementation for wheel_dist_info_dir.
2020-01-01 17:26:20 -05:00
Chris Hunt cd5400ceb9 Determine .dist-info directory from wheel file directly
First example of transitioning a directory-aware function to using a
zipfile directly. Since we will not need to maintain the unpacked dir
going forward, we don't need to worry about making wheel_dist_info_dir
"generic", just that the same tests pass for both cases at each commit.

To do this neatly we use pytest.fixture(params=[...]), which
generates a test for each param. Once we've transitioned the
necessary functions we only need to replace the fixture name and remove
the dead code.
2020-01-01 17:26:20 -05:00
Chris Hunt 513a3162de Pass open zip file for wheel into install_unpacked_wheel
With this parameter we can incrementally update code to rely on the zip
file instead of the unpacked source directory.
2020-01-01 17:26:20 -05:00
Chris Hunt 010c24d64c Take .dist-info dir directly in wheel_metadata
Since retrieval of the .dist-info dir already ensures that a
distribution is found, this reduces responsibility on wheel_metadata and
lets us remove a few tests already covered by the tests for
test_wheel_dist_info_dir_*.
2020-01-01 12:25:01 -05:00
Chris Hunt 6c56557fbe Remove unused req_description from wheel_dist_info_dir 2020-01-01 12:25:01 -05:00
Chris Hunt e1c7de8861 Raise UnsupportedWheel instead of AssertionError, and let caller add name 2020-01-01 12:25:01 -05:00
Chris Hunt a539c8dfe0 Normalize exception message for dist_info_dir check 2020-01-01 12:25:01 -05:00
Chris Hunt 32115b55af Extract getting wheel .dist-info directory into a separate function 2020-01-01 12:10:22 -05:00
Chris Hunt c51f020b98 Read WHEEL from .dist-info instead of using has_metadata
This will make it easier to transition to the already-determined
dist-info directory and reduces some of our dependence on pkg_resources.

Despite the name, the `egg_info` member is also populated for
.dist-info dirs.

ensure_str uses encoding='utf-8' and errors='strict' for Python 3
by default, which matches the behavior in
`pkg_resources.NullProvider.get_metadata`.
2020-01-01 12:10:20 -05:00
Chris Hunt c9b0742508 Remove old root_is_purelib
The _invalidversion_ tests are not applicable to the new function since
we do not use a regex to find the applicable folder.
2019-12-31 12:49:08 -05:00
Chris Hunt 42c6dd78b9 Use WHEEL metadata to determine Root-Is-Purelib 2019-12-31 12:47:01 -05:00
Chris Hunt d66bc398be Split wheel_metadata from wheel_version
This will let us re-use the wheel_metadata for other parts of
processing, and by parameterizing checks in terms of metadata we will be
able to substitute in metadata derived directly from the zip.
2019-12-31 12:35:52 -05:00
Chris Hunt 918b154518 Move info_dir calculation up
This will let us use the value for later processing.
2019-12-31 12:12:17 -05:00
Christopher Hunt 69143848b0
Make WHEEL file errors more explicit (#7529)
* Raise exception on exception in finding wheel dist

We plan to replace this code with direct extraction from a zip, so no
point catching anything more precise.

* Raise exception if no dist is found in wheel_version
* Catch file read errors when reading WHEEL

get_metadata delegates to the underlying implementation which tries
to locate and read the file, throwing an IOError (Python 2) or OSError
subclass on any errors.

Since the new explicit test checks the same case as brokenwheel in
test_wheel_version we remove the redundant test.

* Check for WHEEL decoding errors explicitly

This was the last error that could be thrown by get_metadata, so we can
also remove the catch-all except block.

* Move WHEEL parsing outside try...except

This API does not raise an exception, but returns any errors on the
message object itself. We are preserving the original behavior, and can
decide later whether to start warning or raising our own exception.

* Raise explicit error if Wheel-Version is missing

`email.message.Message.__getitem__` returns None on missing values, so
we have to check for ourselves explicitly.

* Raise explicit exception on failure to parse Wheel-Version

This is also the last exception that can be raised, so we remove
`except Exception`.

* Remove dead code

Since wheel_version never returns None, this exception will never be
raised.
2019-12-31 23:17:41 +08:00
Christopher Hunt 8c888a2287
Simplify getting info directories for wheel installation (#7526)
* Edit subdirs of top-level instead of checking in each directory

Previously, we were checking whether the top of the relative path ended
with .data. Now, we do not recurse into those directories, so there's no
need to check every time.

* Store info_dir in separate variable

Instead of working with a list everywhere, we use the single info_dir.

* Separate variables for info_dir and the destination path
* Use destination .dist-info dir only when needed

By initially storing just the name of the folder we ensure our code is
agnostic to the destination, so it'll be easier to install from a zip
later.

* Use os.listdir instead of os.walk for wheel dir population

Since we only execute any code when basedir == '', we only need the
top-level directories.

* Inline data_dirs calculation
* Inline info_dirs calculation
2019-12-30 23:59:23 +08:00
Chris Hunt 93900e1199 Only check for .dist-info directories at the top-level
Previously we were restricting to a single .dist-info directory anywhere
in the unpacked wheel directory. That was incorrect since only a
top-level .dist-info directory indicates a contained "package". Now we
limit our restriction to top-level .dist-info directories.
2019-12-28 15:49:08 -05:00
Chris Hunt e5495cf6a1 Raise UnsupportedWheel when .dist-info doesn't match name
This aligns with the previous behavior that would have enforced the
found .dist-info directory starting with the name of the package.

We raise UnsupportedWheel because it looks better in output than the
AssertionError (which includes traceback).
2019-12-21 21:27:49 -05:00
Chris Hunt de217b54af Only allow one top-level .dist-info directory in wheels 2019-12-21 10:50:20 -05:00
Chris Hunt c565d7a1b2 Switch to install_wheel in unit tests
Since it tests install_unpacked_wheel, the coverage should be the same.
2019-12-14 11:38:31 -05:00
Chris Hunt 3f912ad48e Add function to install directly from wheel files
This will help us avoid some complicated directory-changing logic in
WheelBuilder.
2019-12-14 11:38:31 -05:00
Remi Rampin 04d8841ace Update links in docs 2019-12-11 22:23:34 +01:00
Christopher Hunt 830e29e189
Move wheel to operations.install.wheel (#7421)
* Update documentation

For now just fixing the paths and adding a sub-package docstring.
2019-12-04 06:02:39 +08:00
Renamed from src/pip/_internal/wheel.py (Browse further)