-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Check script lockfiles in CI #29021
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
Merged
+163
−210
Merged
Check script lockfiles in CI #29021
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fad83a7
Check script lockfiles in CI
AlexWaygood 1451ee9
Check script lockfiles and dogfood ty together
AlexWaygood 9689857
Pass script paths to ty via an argument file
AlexWaygood 62faafa
Remove separate script lockfile check
AlexWaygood c128cee
Explain the minimum uv version
AlexWaygood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| #!/usr/bin/env -S uv run --script | ||
| # | ||
| # /// script | ||
| # requires-python = ">=3.12" | ||
| # dependencies = [ | ||
| # "pathspec>=1.1.1", | ||
| # ] | ||
| # | ||
| # [tool.ty.rules] | ||
| # truthiness-test-of-none-union = "warn" | ||
| # blanket-ignore-comment = "warn" | ||
| # missing-type-argument = "warn" | ||
| # possibly-unresolved-reference = "warn" | ||
| # unsound-return-statement = "warn" | ||
| # unsound-yield = "warn" | ||
| # unsupported-dynamic-base = "warn" | ||
| # division-by-zero = "warn" | ||
| # dynamic-function-decorator-return = "warn" | ||
| # unsound-assignment = "warn" | ||
| # redundant-condition-strict = "warn" | ||
| # disjoint-cast = "warn" | ||
| # missing-direct-dependency = "warn" | ||
| # /// | ||
|
|
||
| """Update script lockfiles. | ||
|
|
||
| Run `uv run scripts/check-scripts.py` to update the lockfiles. | ||
| Use `--write-ty-args-file <path>` to write the discovered scripts to an argument file for ty | ||
| instead of updating lockfiles. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import subprocess | ||
| import sys | ||
| from collections.abc import Iterator | ||
| from pathlib import Path | ||
|
|
||
| from pathspec import GitIgnoreSpec | ||
|
|
||
| ROOT = Path(__file__).resolve().parent.parent | ||
| # Crate resources and completion fixtures are inputs, not project scripts. | ||
| COMPLETION_FIXTURES = Path("crates/ty_completion_eval/truth") | ||
|
|
||
|
|
||
| def scripts() -> Iterator[Path]: | ||
|
MichaReiser marked this conversation as resolved.
|
||
| """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 error. | ||
| """ | ||
|
|
||
| gitignore = GitIgnoreSpec.from_lines((ROOT / ".gitignore").read_text().splitlines()) | ||
|
|
||
| # uv's script listing skips invalid metadata, so find candidates before | ||
| # asking uv to validate and lock them. | ||
| # | ||
| # We use `.walk()` here rather than `.rglob()` because some of our ignored directories are | ||
| # huge; `.walk()` allows us to lazily inspect whether they're gitignored before recursively | ||
| # descending into them. | ||
| for directory, dirnames, filenames in ROOT.walk(): | ||
| dirnames[:] = [ | ||
| dirname | ||
| for dirname in dirnames | ||
| if (path := (directory / dirname).relative_to(ROOT)) != Path(".git") | ||
| and not gitignore.match_file(f"{path.as_posix()}/") | ||
| ] | ||
|
|
||
| for filename in filenames: | ||
| if not filename.endswith(".py"): | ||
| continue | ||
|
|
||
| full_path = directory / filename | ||
|
|
||
| path = full_path.relative_to(ROOT) | ||
|
|
||
| if path.is_relative_to(COMPLETION_FIXTURES): | ||
| continue | ||
|
|
||
| match full_path.relative_to(ROOT).parts: | ||
| case ("crates", _, "resources", *_): | ||
| continue | ||
|
|
||
| if ( | ||
| full_path.is_symlink() | ||
| or not full_path.is_file() | ||
| or gitignore.match_file(path) | ||
| ): | ||
| continue | ||
|
|
||
| if b"# /// script" in full_path.read_bytes().splitlines(): | ||
|
AlexWaygood marked this conversation as resolved.
|
||
| yield path | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__, allow_abbrev=False) | ||
| parser.add_argument( | ||
| "--write-ty-args-file", | ||
| type=Path, | ||
| help="Write script paths to an argument file for ty", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| if args.write_ty_args_file is not None: | ||
| args.write_ty_args_file.write_text( | ||
| "".join(f"{script}\n" for script in scripts()), encoding="utf-8" | ||
| ) | ||
| return 0 | ||
|
|
||
| failed = False | ||
|
|
||
| for script in scripts(): | ||
| print(script, flush=True) | ||
| command = ["uv", "lock", "--script", str(script), "--refresh", "--no-locked"] | ||
| result = subprocess.run(command, cwd=ROOT, check=False) | ||
| failed |= result.returncode != 0 | ||
|
|
||
| return int(failed) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| version = 1 | ||
| revision = 3 | ||
| requires-python = ">=3.12" | ||
|
|
||
| [options] | ||
| exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values. | ||
| exclude-newer-span = "P7D" | ||
|
|
||
| [manifest] | ||
| requirements = [{ name = "pathspec", specifier = ">=1.1.1" }] | ||
|
|
||
| [[package]] | ||
| name = "pathspec" | ||
| version = "1.1.1" | ||
| source = { registry = "https://pypi.org/simple" } | ||
| sdist = { url = "https://files.pythonhosted.org/packages/5a/82/42f767fc1c1143d6fd36efb827202a2d997a375e160a71eb2888a925aac1/pathspec-1.1.1.tar.gz", hash = "sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a", size = 135180, upload-time = "2026-04-27T01:46:08.907Z" } | ||
| wheels = [ | ||
| { url = "https://files.pythonhosted.org/packages/f1/d9/7fb5aa316bc299258e68c73ba3bddbc499654a07f151cba08f6153988714/pathspec-1.1.1-py3-none-any.whl", hash = "sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189", size = 57328, upload-time = "2026-04-27T01:46:07.06Z" }, | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.