Commit Graph

124 Commits

Author SHA1 Message Date
Damian Shaw 68529081c2
Enforce f-strings via Ruff (#12393) 2023-11-07 09:14:56 +00:00
Christian Clauss 69a1e956da Ruff rules C4,C90,PERF 2023-08-28 14:51:13 +02:00
lorddavidiii d89475934c
Norm path before compare (#11719) 2023-03-27 20:03:46 +01:00
Tzu-ping Chung 2c195f9c2c Fix multi-digit version in entry point replacement
Previously, the special case to generate 'pip' and 'easy_install' entry
points with the correct Python version (e.g. 'pip3.9' on Python 3.9)
only accounted for single-digit version segments, and did not work
correctly on Python 3.10 and up. This was missed when Python 3.10 was
released because we (accidentally) generated wheels that did not need
any such replacements, but was exposed in CPython 3.11.0 since it
bundled pip 22.3 generated against Python 3.10.
2022-10-28 01:51:36 +08:00
hauntsaninja b9ec5ddc29 Use --no-implicit-optional for type checking
This makes type checking PEP 484 compliant (as of 2018).
mypy will change its defaults soon.

See:
https://github.com/python/mypy/issues/9091
https://github.com/python/mypy/pull/13401
2022-08-12 18:44:48 -07:00
Роман Донченко e4cd6da6e5 Update the RECORD entry when rewriting the shebang line in a script
The code to do this already exists in `get_csv_rows_for_installed`, but it's
broken due to inconsistent usage of the `_fs_to_record_path` function. When
we build the dictionary of installed files, we call it with a base
directory, while when build the set of modified files, we call it without a
base directory. As a result, the values of `installed` do not match the
elements of `changed`, and `get_csv_rows_for_installed` fails to identify
the rows that should be updated.

Fix this by ensuring that `_fs_to_record_path` is always called with a base
directory. `_record_to_fs_path` also needs a a base directory parameter to
be able to transform the path back into an absolute path, so add one.
2022-06-25 01:27:08 +03:00
q0w 3820b0e52c
Replace Iterator[T] with Generator[T,None, None] (#11007)
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
2022-04-09 16:11:58 +01:00
Jon Dufresne 6fa76c9789 Simplify operations/install/wheel.py
- Remove unnecessary uses of six functions. With Python 2 support
  dropped, the text/bytes boundaries are more explicit and don't require
  type coercion. This allows dropping the types-six dependency.

- Remove Python 2 workarounds and comments describing those workarounds.
2021-09-24 03:52:25 -07:00
Tzu-ping Chung 135faabfd6
Remove direct pkg_resource usages from resolver and preparer 2021-08-23 02:07:33 +08:00
Tzu-ping Chung e483f533fa Switch install scheme backend to sysconfig
This is only done for Python 3.10+ so we don't disrupt too many existing
pip installations.
2021-08-21 00:53:59 +08:00
Pradyun Gedam 94999255d5
Reformat the codebase, with black 2021-08-20 13:37:49 +01:00
Nipunn Koorapati 2aab462b7f Bump mypy to 0.910
This notably gets us on a version of mypy that uses modular typeshed:
https://mypy-lang.blogspot.com/2021/05/the-upcoming-switch-to-modular-typeshed.html
which allows us to have finer control over what version of stubs we pull
in from typeshed. Also contains other routine improvements to mypy.

Required a few minor typing changes.

Add flag --show-error-code so errors look like this

src/pip/_internal/network/auth.py:70: error: Incompatible types in assignment
(expression has type "None", variable has type Module)  [assignment]

rather than

src/pip/_internal/network/auth.py:70: error: Incompatible types in assignment
(expression has type "None", variable has type Module)
2021-08-09 16:47:02 -07:00
harupy 93db97c383 convert type comments 2021-07-23 23:29:29 +09:00
Tzu-ping Chung 28fff1e483 Remove pkg_resources usages in wheel operations 2021-07-22 15:20:49 +08:00
Jon Dufresne 0945809afc Remove typing.TYPE_CHECKING guards
The typing module has been available since Python 3.5. Guarding the
import has been unnecessary since dropping Python 2.

Some guards remain to either:

- Avoid circular imports
- Importing objects that are also guarded by typing.TYPE_CHECKING
- Avoid mypy_extensions dependency
2021-02-19 18:34:21 -08:00
Jon Dufresne a6392bd62e Replace pip._internal.utils.typing with stdlib typing
The stdlib module has been available since Python 3.5 and the
TYPE_CHECKING constant has been available since 3.5.2.

By using stdlib, this removes the need for pip to maintain its own
Python 2 typing compatibility shim.
2021-02-18 19:09:13 -08:00
Inada Naoki fb62f2707a Use `encoding` option or binary mode for open() 2021-02-13 20:45:16 +09:00
Jon Dufresne 089bbcb939 Remove unnecessary type override NamedTemporaryFileResult
The object returned by NamedTemporaryFile delegates all functions calls
to the underlying file so can avoid the type override by relying on IO
methods.
2020-12-27 17:19:28 -08:00
Pradyun Gedam 86afa89043
Merge pull request #9361 from jdufresne/f-strings
Use f-strings for simple string formatting
2020-12-26 10:24:18 +00:00
Jon Dufresne cdcf74fb8e Use f-strings for simple string formatting
Use pyupgrade to convert simple string formatting to use f-string
syntax. pyupgrade is intentionally timid and will not create an f-string
if it would make the expression longer or if the substitution parameters
are anything but simple names or dotted names.
2020-12-25 16:21:20 -08:00
Jon Dufresne 09b3d3a50b Remove object from class definitions
Unnecessary since dropping Python 2 support. In Python 3, all classes
are new style classes.
2020-12-25 15:48:11 -08:00
Jon Dufresne c148bcc1aa Use short Python3 super() syntax 2020-12-24 15:11:51 -08:00
Jon Dufresne f32adaf09b Remove __future__ imports
Unnecessary since dropping Python 2.
2020-12-24 08:38:09 -08:00
Jon Dufresne 53234e578f Remove obsolete "# type: ignore" comments
Obsolete since dropping Python 2 support.

Add the mypy setting "warn_unused_ignores = True" to catch these
earlier.
2020-12-23 15:42:48 -08:00
Hugo van Kemenade 817ee23051 Remove redundant Python 2.7 code 2020-12-22 09:06:26 +02:00
Pradyun Gedam 58c594c06b
Prepare isort for black 2020-09-23 21:47:47 +05:30
Pradyun Gedam 25ab172b55
Update linter: isort 2020-09-23 19:52:28 +05:30
Tzu-ping Chung a12e2f1479 PEP 427 mandates UTF-8, we don't need the fallback 2020-08-03 15:00:58 +08:00
Tzu-ping Chung d4995cb89e Implement heuristics to get non-ASCII ZIP entries 2020-08-03 09:29:19 +08:00
Chris Hunt 3f9b326c11 Provide a reasonable error on invalid scheme keys
Originally we would throw an `AttributeError` if a bad scheme key was
used. After refactoring we would throw a `KeyError`, which isn't much
better. Now we call out the wheel being processed, scheme key we didn't
recognize, and provide a list of the valid scheme keys. This would
likely be useful for people developing/testing the wheel.
2020-07-29 22:24:09 -04:00
Chris Hunt 864f0e0efa Explicitly handle incorrect .data paths during wheel install
Previously our wheel installation process allowed wheels which contained
non-conforming contents in a contained .data directory.

After the refactoring to enable direct-from-wheel installation, pip
throws an exception when encountering these wheels, but does not include
any helpful information to pinpoint the cause.

Now if we encounter such a wheel, we trace an error that includes the
name of the requirement we're trying to install, the path to the wheel
file, the path we didn't understand, and a hint about what we expect.
2020-07-29 18:12:16 -04:00
Nguyễn Gia Phong f8b06a3906 Enable flake8-logging-format 2020-07-17 14:33:19 +07:00
Chris Hunt 677b4e7f11 Remove redundant try ... except 2020-07-11 15:34:06 -04:00
Chris Hunt 145b7add7e Move error message construction into MissingCallableSuffix
Now, we are free to throw MissingCallableSuffix from anywhere and don't
have to worry about catching it in the middle of our processing.
2020-07-11 15:34:06 -04:00
Chris Hunt f48c44e203 Add req description to error in install_wheel
Moving this value up from `_install_wheel` means that we do not need to
pass `req_description` anymore. This will also let us move our
entrypoint error handling around without worrying about losing the
context from the previous message.
2020-07-11 15:34:06 -04:00
Chris Hunt d13ec25361 Prevent path traversal when installing wheels directly 2020-07-09 21:21:35 -04:00
Chris Hunt 4605b32c49 Don't unpack wheel before installing 2020-07-09 18:25:11 -04:00
Chris Hunt 483213a318 Drop unused wheeldir parameter 2020-07-09 18:25:11 -04:00
Chris Hunt df92f25079 Don't use wheeldir for pyc record paths 2020-07-09 18:25:11 -04:00
Chris Hunt 4bdb8bcd7e Extract files directly from wheel 2020-07-09 18:25:10 -04:00
Chris Hunt f9432790de Get list of files directly from wheel
One less dependency on the wheel being extracted.
2020-07-09 18:24:33 -04:00
Chris Hunt e0f95f12b6 Get non-root scheme files from paths, not disk
Now we rely solely on the list of RECORD-like paths derived from the
filesystem, and can easily trade out the implementation for one that
comes from the wheel file directly.
2020-07-09 18:24:30 -04:00
Chris Hunt 8221aac105 Get paths and make files separately
At the beginning of our wheel processing we are going to have the list
of contained files. By splitting this into its own function, and
deriving it from disk in the same way it will appear in the zip, we can
incrementally refactor our approach using the same interface that will
be available at that time.

We start with the root-scheme paths (that end up in lib_dir) first.
2020-07-09 18:23:17 -04:00
Chris Hunt a3b977330a Separate RECORD path from source file path
When we start processing files directly from the wheel, all we will have
are the files with their zip path (which should match a `RECORD`
entry). Separating this from the source file path (used for copying)
and annotating it with our `RecordPath` type makes it clear what the
format of this public property is, and that it should match what is in
`RECORD`.
2020-07-09 18:23:17 -04:00
Chris Hunt 239accb1b6 Inline clobber 2020-07-09 18:23:17 -04:00
Chris Hunt f2239b5488 Combine processing of root- and data-scheme files
With this approach, we can add the rest of our generated files into the
same iterable and they can undergo the same processing.
2020-07-09 18:23:17 -04:00
Chris Hunt e8382871ad Filter files outside of file-finding function
Simplifying the file-finding function will make it easier to drive our
whole wheel installation from a single list of files later.
2020-07-09 18:23:17 -04:00
Chris Hunt f1e906d166 Move script fixing into separate class
This makes `clobber` much simpler, and aligns the interface of
root_scheme files and data_scheme files, so we can process them in the
same way.
2020-07-09 18:23:17 -04:00
Chris Hunt 50f6f8d69b Simplify return type for fix_script
We always pass a file path to this function, so assert as much. We want
the return type to be consistent so we can assign the result to
non-Optional types.
2020-07-09 18:23:17 -04:00
Chris Hunt bf45bd77be Extract "getting files" outside `clobber`
"getting files" is one of the places that requires files to be on disk.
By extracting this out of `clobber` we can make it simpler and then
trade it out for a zip-based implementation.
2020-07-08 21:43:40 -04:00