Skip to content

Commit 8b4acd2

Browse files
authored
Merge pull request #4457 from pypa/debt/2825-devendor
Simplify vendoring and declare dependencies optionally
2 parents e304e4d + 9eb89de commit 8b4acd2

File tree

398 files changed

+22159
-20007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+22159
-20007
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ jobs:
129129
job:
130130
- diffcov
131131
- docs
132-
- check-extern
133132
runs-on: ubuntu-latest
134133
steps:
135134
- uses: actions/checkout@v4

conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ def pytest_configure(config):
3232
'setuptools/tests/mod_with_constant.py',
3333
'setuptools/_distutils',
3434
'_distutils_hack',
35-
'setuptools/extern',
36-
'pkg_resources/extern',
3735
'pkg_resources/tests/data',
3836
'setuptools/_vendor',
39-
'pkg_resources/_vendor',
4037
'setuptools/config/_validate_pyproject',
4138
'setuptools/modified.py',
4239
'setuptools/tests/bdist_wheel_testdata',

mypy.ini

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exclude = (?x)(
1212
| ^.tox/
1313
| ^.eggs/
1414
| ^pkg_resources/tests/data/my-test-package-source/setup.py$ # Duplicate module name
15-
| ^.+?/(_vendor|extern)/ # Vendored
15+
| ^setuptools/_vendor/ # Vendored
1616
| ^setuptools/_distutils/ # Vendored
1717
| ^setuptools/config/_validate_pyproject/ # Auto-generated
1818
| ^setuptools/tests/bdist_wheel_testdata/ # Duplicate module name
@@ -31,15 +31,14 @@ disable_error_code = attr-defined
3131
[mypy-pkg_resources.tests.*]
3232
disable_error_code = import-not-found
3333

34-
# - Avoid raising issues when importing from "extern" modules, as those are added to path dynamically.
35-
# https://github.com/pypa/setuptools/pull/3979#discussion_r1367968993
3634
# - distutils._modified has different errors on Python 3.8 [import-untyped], on Python 3.9+ [import-not-found]
3735
# - All jaraco modules are still untyped
3836
# - _validate_project sometimes complains about trove_classifiers (#4296)
39-
[mypy-pkg_resources.extern.*,setuptools.extern.*,distutils._modified,jaraco.*,trove_classifiers]
37+
# - wheel appears to be untyped
38+
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*]
4039
ignore_missing_imports = True
4140

42-
# Even when excluding vendored/generated modules, there might be problems: https://github.com/python/mypy/issues/11936#issuecomment-1466764006
43-
[mypy-setuptools._vendor.packaging._manylinux,setuptools.config._validate_pyproject.*]
41+
# Even when excluding generated modules, there might be problems: https://github.com/python/mypy/issues/11936#issuecomment-1466764006
42+
[mypy-setuptools.config._validate_pyproject.*]
4443
follow_imports = silent
4544
# silent => ignore errors when following imports

newsfragments/2825.removal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now setuptools declares its own dependencies in the ``core`` extra. Dependencies are still vendored for bootstrapping purposes, but setuptools will prefer installed dependencies if present. The ``core`` extra is used for informational purposes and should *not* be declared in package metadata (e.g. ``build-requires``). Downstream packagers can de-vendor by simply removing the ``setuptools/_vendor`` directory.

pkg_resources/__init__.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474

7575
import _imp
7676

77+
sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip
78+
7779
# capture these to bypass sandboxing
7880
from os import utime
7981
from os import open as os_open
@@ -87,16 +89,17 @@
8789
# no write support, probably under GAE
8890
WRITE_SUPPORT = False
8991

90-
from pkg_resources.extern.jaraco.text import (
92+
import packaging.specifiers
93+
from jaraco.text import (
9194
yield_lines,
9295
drop_comment,
9396
join_continuation,
9497
)
95-
from pkg_resources.extern.packaging import markers as _packaging_markers
96-
from pkg_resources.extern.packaging import requirements as _packaging_requirements
97-
from pkg_resources.extern.packaging import utils as _packaging_utils
98-
from pkg_resources.extern.packaging import version as _packaging_version
99-
from pkg_resources.extern.platformdirs import user_cache_dir as _user_cache_dir
98+
from packaging import markers as _packaging_markers
99+
from packaging import requirements as _packaging_requirements
100+
from packaging import utils as _packaging_utils
101+
from packaging import version as _packaging_version
102+
from platformdirs import user_cache_dir as _user_cache_dir
100103

101104
if TYPE_CHECKING:
102105
from _typeshed import BytesPath, StrPath, StrOrBytesPath
@@ -538,8 +541,7 @@ def get_distribution(dist: Distribution | _PkgReqType) -> Distribution:
538541
if isinstance(dist, str):
539542
dist = Requirement.parse(dist)
540543
if isinstance(dist, Requirement):
541-
# Bad type narrowing, dist has to be a Requirement here, so get_provider has to return Distribution
542-
dist = get_provider(dist) # type: ignore[assignment]
544+
dist = get_provider(dist)
543545
if not isinstance(dist, Distribution):
544546
raise TypeError("Expected str, Requirement, or Distribution", dist)
545547
return dist
@@ -1117,11 +1119,10 @@ def markers_pass(self, req: Requirement, extras: tuple[str, ...] | None = None):
11171119
Return False if the req has a marker and fails
11181120
evaluation. Otherwise, return True.
11191121
"""
1120-
extra_evals = (
1122+
return not req.marker or any(
11211123
req.marker.evaluate({'extra': extra})
1122-
for extra in self.get(req, ()) + (extras or (None,))
1124+
for extra in self.get(req, ()) + (extras or ("",))
11231125
)
1124-
return not req.marker or any(extra_evals)
11251126

11261127

11271128
class Environment:
@@ -3430,15 +3431,18 @@ class RequirementParseError(_packaging_requirements.InvalidRequirement):
34303431

34313432

34323433
class Requirement(_packaging_requirements.Requirement):
3434+
# prefer variable length tuple to set (as found in
3435+
# packaging.requirements.Requirement)
3436+
extras: tuple[str, ...] # type: ignore[assignment]
3437+
34333438
def __init__(self, requirement_string: str):
34343439
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
34353440
super().__init__(requirement_string)
34363441
self.unsafe_name = self.name
34373442
project_name = safe_name(self.name)
34383443
self.project_name, self.key = project_name, project_name.lower()
34393444
self.specs = [(spec.operator, spec.version) for spec in self.specifier]
3440-
# packaging.requirements.Requirement uses a set for its extras. We use a variable-length tuple
3441-
self.extras: tuple[str] = tuple(map(safe_extra, self.extras))
3445+
self.extras = tuple(map(safe_extra, self.extras))
34423446
self.hashCmp = (
34433447
self.key,
34443448
self.url,
@@ -3454,17 +3458,24 @@ def __eq__(self, other: object):
34543458
def __ne__(self, other):
34553459
return not self == other
34563460

3457-
def __contains__(self, item: Distribution | str | tuple[str, ...]) -> bool:
3461+
def __contains__(
3462+
self, item: Distribution | packaging.specifiers.UnparsedVersion
3463+
) -> bool:
34583464
if isinstance(item, Distribution):
34593465
if item.key != self.key:
34603466
return False
34613467

3462-
item = item.version
3468+
version = item.version
3469+
else:
3470+
version = item
34633471

34643472
# Allow prereleases always in order to match the previous behavior of
34653473
# this method. In the future this should be smarter and follow PEP 440
34663474
# more accurately.
3467-
return self.specifier.contains(item, prereleases=True)
3475+
return self.specifier.contains(
3476+
version,
3477+
prereleases=True,
3478+
)
34683479

34693480
def __hash__(self):
34703481
return self.__hash

pkg_resources/_vendor/backports.tarfile-1.0.0.dist-info/RECORD

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)