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

Function scripts

scripts/check-scripts.py:36–84  ·  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

34
35
36def scripts() -> Iterator[Path]:
37 """Yield paths to Python scripts containing PEP 723 metadata.
38
39 The paths are relative to the repository root. Files ignored by the root
40 `.gitignore`, symlinks, crate resources, and completion fixtures are
41 excluded. Scripts with invalid metadata are included so `uv lock` can
42 report the error.
43 """
44
45 gitignore = GitIgnoreSpec.from_lines((ROOT / ".gitignore").read_text().splitlines())
46
47 # uv's script listing skips invalid metadata, so find candidates before
48 # asking uv to validate and lock them.
49 #
50 # We use `.walk()` here rather than `.rglob()` because some of our ignored directories are
51 # huge; `.walk()` allows us to lazily inspect whether they're gitignored before recursively
52 # descending into them.
53 for directory, dirnames, filenames in ROOT.walk():
54 dirnames[:] = [
55 dirname
56 for dirname in dirnames
57 if (path := (directory / dirname).relative_to(ROOT)) != Path(".git")
58 and not gitignore.match_file(f"{path.as_posix()}/")
59 ]
60
61 for filename in filenames:
62 if not filename.endswith(".py"):
63 continue
64
65 full_path = directory / filename
66
67 path = full_path.relative_to(ROOT)
68
69 if path.is_relative_to(COMPLETION_FIXTURES):
70 continue
71
72 match full_path.relative_to(ROOT).parts:
73 case ("crates", _, "resources", *_):
74 continue
75
76 if (
77 full_path.is_symlink()
78 or not full_path.is_file()
79 or gitignore.match_file(path)
80 ):
81 continue
82
83 if b"# /// script" in full_path.read_bytes().splitlines():
84 yield path
85
86
87def 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