Commit dae610b
Use PEP 508 rules when setting deps from extras (#724)
* Use PEP 426 rules when setting deps from extras
This commit addresses issue #720.
[PEP 426](https://peps.python.org/pep-0426/#name) states that distribution
names are case-insensitive and "-" is interchangeable with "_".
The `pip-compile` command creates a lockfile where all package names are lowercase.
The tool may also modify interchangeable characters.
The following examples are all valid `requirements.txt` or `requirements_lock.txt` entries:
```
SQLAlchemy[postgresql_psycopg2binary]==1.4.36
sqlalchemy[postgresql_psycopg2binary]==1.4.36
sentry_sdk[flask]==1.5.8
sentry-sdk[flask]==1.5.8
```
A distribution's `METADATA` file contains the stylization chosen by the publisher.
By applying a "sanitise" function when building the `extras` dict and when performing lookups
we can eliminate this difference as a concern.
* Use PEP 503 rules when sanitising extras
* Normalize distribution name with pkg_resources
`pypa/installer` is used to parse Wheel metadata, but does not currently
provide a method for normalizing distribution names:
- pypa/installer#97
`pypa/pkg_resources` provides `Requirement.parse` which returns an instance
of `Requirement` where `.key` is the canonical distribution name per PEP 503.
The `Requirement` class can also parse `extras`, but it returns a normalized
form that I believe could break the installation of the extras.
* Use Requirement.parse to populate extra reqs
* Revert "Use Requirement.parse to populate extra reqs"
This reverts commit f0faa97.
* Test for distribution name normalization in extras
* Replace pkg_resources with packaging.utils
This replaces `pkg_resources.Requirement.parse` with
`packaging.utils.canonicalize_name`. Doing this pulls in a vendored
requirement from `pip`, which may be undesirable.
The code we want is just:
```
re.sub(r"[-_.]+", "-", name).lower()
```
This commit also leaves a reference to `pkg_resources` in `wheel.py` which
does not canonicalize the name.
Co-authored-by: Jonathon Belotti <[email protected]>
Co-authored-by: Alex Eagle <[email protected]>1 parent c98bc8f commit dae610b
File tree
3 files changed
+8
-2
lines changed- python/pip_install/extract_wheels/lib
3 files changed
+8
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
0 commit comments