Commit Graph

183 Commits

Author SHA1 Message Date
Pradyun Gedam 58c594c06b
Prepare isort for black 2020-09-23 21:47:47 +05:30
Nguyễn Gia Phong 4a2e03c4ff Use monkeypatch for env var in wheel unit tests 2020-09-04 15:06:08 +07:00
Chris Hunt 05f2d9ebf6 Make entrypoint error test higher-level
The current tests didn't catch the bug that the new tests do,
so they have been removed. Using higher-level tests can give us more
confidence that things work end-to-end and are less likely to get in
the way of refactoring.

The new test has been marked xfail since the bug is still present.
2020-07-11 15:45:18 -04:00
Chris Hunt d13ec25361 Prevent path traversal when installing wheels directly 2020-07-09 21:21:35 -04:00
Chris Hunt ba96ba3b08 Reduce empty directory test coupling to implementation
Our previous test required that the implementation use a temporary
directory and unpack the wheel in-place. Now we just provide a
conventional empty directory in the wheel file itself.
2020-07-05 20:16:36 -04:00
Chris Hunt a9c7f229b0 Create sample project wheel inline 2020-07-05 20:16:36 -04:00
Chris Hunt 42c01ae97e Normalize Path to str in wheel tests
In our next commit we will use the scheme path to locate files to
byte-compile. If the scheme path is a `Path`, then that causes
`compileall.compile_file` (via `py_compile.compile`) to fail with:

```
.tox/py38/lib/python3.8/site-packages/pip/_internal/operations/install/wheel.py:615: in install_unpacked_wheel
    success = compileall.compile_file(
../../../.pyenv/versions/3.8.0/lib/python3.8/compileall.py:157: in compile_file
    ok = py_compile.compile(fullname, cfile, dfile, True,
../../../.pyenv/versions/3.8.0/lib/python3.8/py_compile.py:162: in compile
    bytecode = importlib._bootstrap_external._code_to_timestamp_pyc(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

code = <code object <module> at 0x7fa7e274f500, file "/tmp/user/1000/pytest-of-chris/pytest-37/test_std_install_with_direct_u0/dest/lib/sample/__init__.py", line 1>, mtime = 1593910285.2200587, source_size = 134

>   ???
E   ValueError: unmarshallable object
```

Debugging in gdb shows that the error is set due to the `Path` object
being present in the code object, which `marshal.dumps` can't handle
(frame 1):

```
 0  w_complex_object (v=<optimized out>, flag=<optimized out>, p=0x7fffffff7160) at Python/marshal.c:564
 1  w_object (v=<Path at remote 0x7fffee51f120>, p=0x7fffffff7160) at Python/marshal.c:370
 2  w_complex_object (v=<code at remote 0x7fffee591710>, flag=<optimized out>, p=0x7fffffff7160) at Python/marshal.c:544
 3  w_object (v=<code at remote 0x7fffee591710>, p=0x7fffffff7160) at Python/marshal.c:370
 4  w_complex_object (v=('1.2.0', <code at remote 0x7fffee591710>, 'main', None), flag=<optimized out>, p=0x7fffffff7160) at Python/marshal.c:475
 5  w_object (v=('1.2.0', <code at remote 0x7fffee591710>, 'main', None), p=0x7fffffff7160) at Python/marshal.c:370
 6  w_complex_object (v=<code at remote 0x7fffee591ea0>, flag=<optimized out>, p=0x7fffffff7160) at Python/marshal.c:539
 7  w_object (p=0x7fffffff7160, v=<code at remote 0x7fffee591ea0>) at Python/marshal.c:370
 8  PyMarshal_WriteObjectToString (version=<optimized out>, x=<code at remote 0x7fffee591ea0>) at Python/marshal.c:1598
 9  marshal_dumps_impl (module=<optimized out>, version=<optimized out>, value=<code at remote 0x7fffee591ea0>) at Python/marshal.c:1739
 10 marshal_dumps (module=<optimized out>, args=<optimized out>, nargs=<optimized out>) at Python/clinic/marshal.c.h:124
```

In the interest of easy git bisects, we commit this fix before the code
that would expose the bug.
2020-07-05 09:38:08 -04:00
Chris Hunt 3930e4b063 Drop unused argument 2020-07-03 19:46:45 -04:00
Chris Hunt d49d97f19f Pass Wheel distribution to install.wheel.get_entrypoints
Right now we're just wiring up the arguments. Next we will actually use
them.
2020-07-03 19:46:45 -04:00
Chris Hunt a953787152 Extract entrypoint test text construction into variable
We need this to construct the new argument to `get_entrypoints`.
2020-07-03 19:46:45 -04:00
Chris Hunt 3fad029b77 Test `get_entrypoints` when none are expected 2020-07-03 17:49:56 -04:00
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
Pradyun Gedam e774eccf46
Merge pull request #8343 from uranusjr/entrypoint-unicode 2020-06-30 14:33:24 +00:00
Tzu-ping Chung b0c1308d64 Always Unicode 2020-06-10 20:58:21 +08: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 c9a445762c
Mark top level requirements as REQUESTED 2020-05-31 18:33:51 +02:00
Stéphane Bidoul 21df86f197
Add REQUESTED support to install_wheel 2020-05-31 18:33:50 +02:00
Tzu-ping Chung aef15104c3 Fix test comment 2020-05-19 16:03:51 +08:00
Tzu-ping Chung 776a55a419 Fix unit tests on module-internal functions 2020-05-19 16:03:51 +08:00
Devesh Kumar Singh 8dccece9c0 Combine setting new umask and getting old one into one 2020-04-29 11:57:11 +05:30
Devesh Kumar Singh 9319703ad9 Add unit test for checking permissions with custom umask 2020-04-29 11:46:43 +05:30
Tzu-ping Chung adef52610e Fix assertion 2020-04-26 18:22:21 +08:00
Tzu-ping Chung 9af0b3daeb Use oct for better error message 2020-04-26 18:17:33 +08:00
Tzu-ping Chung 388ca923ef Add persumably failing permission check 2020-04-26 18:14:38 +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
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 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 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 452acd5e76 Add files in .dist-info directory tests
Since zips don't typically contain directory entries, we want to
only operate on files. Adding files to the .dist-info tests means we
will be able to reuse them for both cases, while they coexist.
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 fc48a17206 Simplify positive wheel_version unit test 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 32115b55af Extract getting wheel .dist-info directory into a separate function 2020-01-01 12:10:22 -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 ca729c89de Simplify wheel_version tests 2019-12-31 12:35:53 -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
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
Pradyun Gedam 37f3fd7087
Move legacy wheel build process 2019-12-25 17:52:39 +05:30
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
Christopher Hunt d7eaede434
Revert "Add new option: pip wheel --save-wheel-names (#6377)" (#7420)
This reverts commit bcad1b1cb5, reversing
changes made to f86490317a.

As discussed, we should rethink the interface of this command output as
part of larger CLI usability review. In the interim, the same
functionality can be achieved using straightforward shell commands.
2019-12-13 07:57:05 +08: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
Chris Hunt b8c16a0dc8 Move Wheel tests 2019-12-02 11:52:51 +08:00
Chris Hunt 60f6ed9387 Move wheel.Wheel to models.wheel.Wheel
This aligns more closely with how the class is used and makes it easier
to move the rest of the wheel module to a dedicated module for
installation.
2019-12-02 11:52:51 +08:00
Chris Hunt bf26185d55 Import Wheel in tests directly 2019-12-02 11:52:51 +08:00
Chris Hunt 1abf978e88 Move format_tag to pep425tags
This is a more appropriate place for the function, since it is more
related to tags than wheels, and will make it easier to refactor Wheel
into its own module.
2019-12-02 11:52:51 +08:00