Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential problem with cog script for vendored #4353

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ def install(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'))
# from tools.vendored import yield_top_level
# names = "\n".join(f" {x!r}," for x in yield_top_level('pkg_resources'))
# cog.outl(f"names = (\n{names}\n)")
# ]]]
names = (
'backports',
'importlib_resources',
'jaraco',
'more_itertools',
'packaging',
'platformdirs',
'jaraco',
'importlib_resources',
'zipp',
'more_itertools',
'backports',
)
# [[[end]]]
VendorImporter(__name__, names).install()
18 changes: 9 additions & 9 deletions setuptools/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ def install(self):

# [[[cog
# import cog
# from tools.vendored import yield_root_package
# names = "\n".join(f" {x!r}," for x in yield_root_package('setuptools'))
# from tools.vendored import yield_top_level
# names = "\n".join(f" {x!r}," for x in yield_top_level('setuptools'))
# cog.outl(f"names = (\n{names}\n)")
# ]]]
names = (
'packaging',
'ordered_set',
'more_itertools',
'jaraco',
'importlib_resources',
'backports',
'importlib_metadata',
'zipp',
'importlib_resources',
'jaraco',
'more_itertools',
'ordered_set',
'packaging',
'tomli',
'backports',
'zipp',
)
# [[[end]]]
VendorImporter(__name__, names, 'setuptools._vendor').install()
29 changes: 17 additions & 12 deletions tools/vendored.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def remove_all(paths):
for path in paths:
path.rmtree() if path.isdir() else path.remove()
path.rmtree() if path.is_dir() else path.remove()


def update_vendored():
Expand Down Expand Up @@ -165,18 +165,23 @@ 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"}
def yield_top_level(name):
"""Iterate over all modules and (top level) packages vendored
>>> roots = set(yield_top_level("setuptools"))
>>> examples = roots & {"jaraco", "backports", "zipp"}
>>> 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("#")
)
['backports', 'jaraco', 'zipp']
"""
vendor = Path(f"{name}/_vendor")
ignore = {"__pycache__", "__init__.py", ".ruff_cache"}

for item in sorted(vendor.iterdir()):
if item.name in ignore:
continue
if item.is_dir() and item.suffix != ".dist-info":
yield str(item.name)
if item.is_file() and item.suffix == ".py":
yield str(item.stem)


__name__ == '__main__' and update_vendored()
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ commands =

[testenv:{vendor,check-extern}]
skip_install = True
allowlist_externals = sh
allowlist_externals = git, sh
deps =
path
cogapp
commands =
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"
sh -c "git grep -l -F '\[\[\[cog' | xargs -t cog -I {toxinidir} -r" # update `*.extern`
check-extern: git diff --exit-code

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