Skip to content

Commit

Permalink
Ensure */extern/__init__.py is in sync with */_vendor/vendored.txt (
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 25, 2024
2 parents b1fc698 + 175787e commit 0156e24
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -128,6 +128,7 @@ jobs:
job:
- diffcov
- docs
- check-extern
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions pkg_resources/_vendor/vendored.txt
Expand Up @@ -9,5 +9,7 @@ jaraco.text==3.7.0
importlib_resources==5.10.2
# required for importlib_resources on older Pythons
zipp==3.7.0
# required for jaraco.functools
more_itertools==10.2.0
# required for jaraco.context on older Pythons
backports.tarfile
9 changes: 9 additions & 0 deletions pkg_resources/extern/__init__.py
Expand Up @@ -70,12 +70,21 @@ def install(self):
sys.meta_path.append(self)


# [[[cog
# import cog
# from tools.vendored import yield_root_package
# names = "\n".join(f" {x!r}," for x in yield_root_package('pkg_resources'))
# cog.outl(f"names = (\n{names}\n)")
# ]]]
names = (
'packaging',
'platformdirs',
'typing_extensions',
'jaraco',
'importlib_resources',
'zipp',
'more_itertools',
'backports',
)
# [[[end]]]
VendorImporter(__name__, names).install()
13 changes: 10 additions & 3 deletions setuptools/extern/__init__.py
Expand Up @@ -70,16 +70,23 @@ def install(self):
sys.meta_path.append(self)


# [[[cog
# import cog
# from tools.vendored import yield_root_package
# names = "\n".join(f" {x!r}," for x in yield_root_package('setuptools'))
# cog.outl(f"names = (\n{names}\n)")
# ]]]
names = (
'packaging',
'ordered_set',
'more_itertools',
'importlib_metadata',
'zipp',
'importlib_resources',
'jaraco',
'importlib_resources',
'importlib_metadata',
'typing_extensions',
'zipp',
'tomli',
'backports',
)
# [[[end]]]
VendorImporter(__name__, names, 'setuptools._vendor').install()
14 changes: 14 additions & 0 deletions tools/vendored.py
Expand Up @@ -166,4 +166,18 @@ def update_setuptools():
rewrite_more_itertools(vendor / "more_itertools")


def yield_root_package(name):
"""Useful when defining the MetaPathFinder
>>> examples = set(yield_root_package("setuptools")) & {"jaraco", "backports"}
>>> list(sorted(examples))
['backports', 'jaraco']
"""
vendored = Path(f"{name}/_vendor/vendored.txt")
yield from (
line.partition("=")[0].partition(".")[0].replace("-", "_")
for line in vendored.read_text(encoding="utf-8").splitlines()
if line and not line.startswith("#")
)


__name__ == '__main__' and update_vendored()
8 changes: 6 additions & 2 deletions tox.ini
Expand Up @@ -69,12 +69,16 @@ pass_env = *
commands =
python tools/finalize.py

[testenv:vendor]
[testenv:{vendor,check-extern}]
skip_install = True
allowlist_externals = sh
deps =
path
cogapp
commands =
python -m tools.vendored
vendor: python -m tools.vendored
vendor: sh -c "git grep -l -F '\[\[\[cog' | xargs cog -I {toxinidir} -r" # update `*.extern`
check-extern: sh -c "git grep -l -F '\[\[\[cog' | xargs cog -I {toxinidir} --check"

[testenv:generate-validation-code]
skip_install = True
Expand Down

0 comments on commit 0156e24

Please sign in to comment.