MCPcopy Create free account
hub / github.com/astral-sh/ruff / scripts

Function scripts

scripts/check-scripts.py:54–102  ·  view source on GitHub ↗

Yield paths to Python scripts containing PEP 723 metadata. The paths are relative to the repository root. Files ignored by the root `.gitignore`, symlinks, crate resources, and completion fixtures are excluded. Scripts with invalid metadata are included so `uv lock` can report the e

()

Source from the content-addressed store, hash-verified

52
53
54def scripts() -> Iterator[Path]:
55 """Yield paths to Python scripts containing PEP 723 metadata.
56
57 The paths are relative to the repository root. Files ignored by the root
58 `.gitignore`, symlinks, crate resources, and completion fixtures are
59 excluded. Scripts with invalid metadata are included so `uv lock` can
60 report the error.
61 """
62
63 gitignore = GitIgnoreSpec.from_lines((ROOT / ".gitignore").read_text().splitlines())
64
65 # uv's script listing skips invalid metadata, so find candidates before
66 # asking uv to validate and lock them.
67 #
68 # We use `.walk()` here rather than `.rglob()` because some of our ignored directories are
69 # huge; `.walk()` allows us to lazily inspect whether they're gitignored before recursively
70 # descending into them.
71 for directory, dirnames, filenames in ROOT.walk():
72 dirnames[:] = [
73 dirname
74 for dirname in dirnames
75 if (path := (directory / dirname).relative_to(ROOT)) != Path(".git")
76 and not gitignore.match_file(f"{path.as_posix()}/")
77 ]
78
79 for filename in filenames:
80 if not filename.endswith(".py"):
81 continue
82
83 full_path = directory / filename
84
85 path = full_path.relative_to(ROOT)
86
87 if path.is_relative_to(COMPLETION_FIXTURES):
88 continue
89
90 match full_path.relative_to(ROOT).parts:
91 case ("crates", _, "resources", *_):
92 continue
93
94 if (
95 full_path.is_symlink()
96 or not full_path.is_file()
97 or gitignore.match_file(path)
98 ):
99 continue
100
101 if b"# /// script" in full_path.read_bytes().splitlines():
102 yield path
103
104
105def main() -> int:

Callers 1

mainFunction · 0.85

Calls 6

PathClass · 0.85
is_symlinkMethod · 0.80
walkMethod · 0.45
relative_toMethod · 0.45
match_fileMethod · 0.45
is_fileMethod · 0.45

Tested by

no test coverage detected