Skip to content

Commit 0156e24

Browse files
authored
Ensure */extern/__init__.py is in sync with */_vendor/vendored.txt (pypa#4320)
2 parents b1fc698 + 175787e commit 0156e24

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
job:
129129
- diffcov
130130
- docs
131+
- check-extern
131132
runs-on: ubuntu-latest
132133
steps:
133134
- uses: actions/checkout@v4

pkg_resources/_vendor/vendored.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ jaraco.text==3.7.0
99
importlib_resources==5.10.2
1010
# required for importlib_resources on older Pythons
1111
zipp==3.7.0
12+
# required for jaraco.functools
13+
more_itertools==10.2.0
1214
# required for jaraco.context on older Pythons
1315
backports.tarfile

pkg_resources/extern/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@ def install(self):
7070
sys.meta_path.append(self)
7171

7272

73+
# [[[cog
74+
# import cog
75+
# from tools.vendored import yield_root_package
76+
# names = "\n".join(f" {x!r}," for x in yield_root_package('pkg_resources'))
77+
# cog.outl(f"names = (\n{names}\n)")
78+
# ]]]
7379
names = (
7480
'packaging',
7581
'platformdirs',
82+
'typing_extensions',
7683
'jaraco',
7784
'importlib_resources',
85+
'zipp',
7886
'more_itertools',
7987
'backports',
8088
)
89+
# [[[end]]]
8190
VendorImporter(__name__, names).install()

setuptools/extern/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,23 @@ def install(self):
7070
sys.meta_path.append(self)
7171

7272

73+
# [[[cog
74+
# import cog
75+
# from tools.vendored import yield_root_package
76+
# names = "\n".join(f" {x!r}," for x in yield_root_package('setuptools'))
77+
# cog.outl(f"names = (\n{names}\n)")
78+
# ]]]
7379
names = (
7480
'packaging',
7581
'ordered_set',
7682
'more_itertools',
77-
'importlib_metadata',
78-
'zipp',
79-
'importlib_resources',
8083
'jaraco',
84+
'importlib_resources',
85+
'importlib_metadata',
8186
'typing_extensions',
87+
'zipp',
8288
'tomli',
8389
'backports',
8490
)
91+
# [[[end]]]
8592
VendorImporter(__name__, names, 'setuptools._vendor').install()

tools/vendored.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,18 @@ def update_setuptools():
166166
rewrite_more_itertools(vendor / "more_itertools")
167167

168168

169+
def yield_root_package(name):
170+
"""Useful when defining the MetaPathFinder
171+
>>> examples = set(yield_root_package("setuptools")) & {"jaraco", "backports"}
172+
>>> list(sorted(examples))
173+
['backports', 'jaraco']
174+
"""
175+
vendored = Path(f"{name}/_vendor/vendored.txt")
176+
yield from (
177+
line.partition("=")[0].partition(".")[0].replace("-", "_")
178+
for line in vendored.read_text(encoding="utf-8").splitlines()
179+
if line and not line.startswith("#")
180+
)
181+
182+
169183
__name__ == '__main__' and update_vendored()

tox.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ pass_env = *
6969
commands =
7070
python tools/finalize.py
7171

72-
[testenv:vendor]
72+
[testenv:{vendor,check-extern}]
7373
skip_install = True
74+
allowlist_externals = sh
7475
deps =
7576
path
77+
cogapp
7678
commands =
77-
python -m tools.vendored
79+
vendor: python -m tools.vendored
80+
vendor: sh -c "git grep -l -F '\[\[\[cog' | xargs cog -I {toxinidir} -r" # update `*.extern`
81+
check-extern: sh -c "git grep -l -F '\[\[\[cog' | xargs cog -I {toxinidir} --check"
7882

7983
[testenv:generate-validation-code]
8084
skip_install = True

0 commit comments

Comments
 (0)