-
Notifications
You must be signed in to change notification settings - Fork 12.7k
[codex] Make justfile recipes Windows-aware #24983
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
Open
iceweasel-oai
wants to merge
11
commits into
main
Choose a base branch
from
codex/windows-justfile-recipes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−16
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f4cc03
Make justfile recipes Windows-aware
iceweasel-oai d5a70cf
Address Windows justfile review feedback
iceweasel-oai 5810eed
Format SDK justfile test update
iceweasel-oai 24c4114
Format SDK justfile test
iceweasel-oai 101855e
Require pwsh for Windows just recipes
iceweasel-oai c28620a
Use cross-platform just shell adapter
iceweasel-oai d6ce694
Simplify just shell adapter lookup
iceweasel-oai 65a0210
Unify bazel lock update recipe
iceweasel-oai 957aca2
Unify argument comment lint source recipe
iceweasel-oai fce27d4
Unify fmt just recipe
iceweasel-oai 1ed627c
Fix justfile CI checks
iceweasel-oai 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
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||
| #!/usr/bin/env python3 | ||||||||||||
| """Cross-platform shell launcher for `just` recipes. | ||||||||||||
|
|
||||||||||||
| This keeps recipe bodies as normal shell snippets while giving the justfile one | ||||||||||||
| portable placeholder, `{args}`, for forwarding variadic recipe arguments. | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| from __future__ import annotations | ||||||||||||
|
|
||||||||||||
| import os | ||||||||||||
| import shutil | ||||||||||||
| import subprocess | ||||||||||||
| import sys | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| ARGS_TOKEN = "{args}" | ||||||||||||
| STDERR_NULL_TOKEN = "{stderr-null}" | ||||||||||||
| POWERSHELL_ARGS = "@($args | Select-Object -Skip 1)" | ||||||||||||
| POWERSHELL_STDERR_NULL = '2>$null; exit $LASTEXITCODE' | ||||||||||||
| SH_ARGS = '"$@"' | ||||||||||||
| SH_STDERR_NULL = "2>/dev/null" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def main() -> int: | ||||||||||||
| if len(sys.argv) < 2: | ||||||||||||
| print("just shell adapter expected a recipe command.", file=sys.stderr) | ||||||||||||
| return 1 | ||||||||||||
|
|
||||||||||||
| command = sys.argv[1] | ||||||||||||
| recipe_name = sys.argv[2] if len(sys.argv) > 2 else "" | ||||||||||||
| recipe_args = sys.argv[3:] | ||||||||||||
|
|
||||||||||||
| if os.name == "nt": | ||||||||||||
| return run_powershell(command, recipe_name, recipe_args) | ||||||||||||
| else: | ||||||||||||
| return run_sh(command, recipe_name, recipe_args) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def run_sh(command: str, recipe_name: str, recipe_args: list[str]) -> int: | ||||||||||||
| command = command.replace(ARGS_TOKEN, SH_ARGS) | ||||||||||||
| command = command.replace(STDERR_NULL_TOKEN, SH_STDERR_NULL) | ||||||||||||
| return subprocess.run( | ||||||||||||
| ["sh", "-cu", command, recipe_name, *recipe_args], | ||||||||||||
| check=False, | ||||||||||||
| ).returncode | ||||||||||||
|
Comment on lines
+42
to
+45
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use
Suggested change
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def run_powershell(command: str, recipe_name: str, recipe_args: list[str]) -> int: | ||||||||||||
| pwsh = shutil.which("pwsh.exe") or shutil.which("pwsh") | ||||||||||||
| if pwsh is None: | ||||||||||||
| print( | ||||||||||||
| "PowerShell ('pwsh') is required for Windows just recipes. " | ||||||||||||
| "Run 'just install' to install it.", | ||||||||||||
| file=sys.stderr, | ||||||||||||
| ) | ||||||||||||
| return 1 | ||||||||||||
|
|
||||||||||||
| command = command.replace(ARGS_TOKEN, POWERSHELL_ARGS) | ||||||||||||
| command = command.replace(STDERR_NULL_TOKEN, POWERSHELL_STDERR_NULL) | ||||||||||||
| return subprocess.run( | ||||||||||||
| [ | ||||||||||||
| pwsh, | ||||||||||||
| "-NoLogo", | ||||||||||||
| "-NoProfile", | ||||||||||||
| "-CommandWithArgs", | ||||||||||||
| command, | ||||||||||||
| recipe_name, | ||||||||||||
| *recipe_args, | ||||||||||||
| ], | ||||||||||||
| check=False, | ||||||||||||
| ).returncode | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| if __name__ == "__main__": | ||||||||||||
| raise SystemExit(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 |
|---|---|---|
|
|
@@ -81,14 +81,16 @@ def test_root_fmt_recipe_formats_rust_and_python_sdk() -> None: | |
| fmt_recipe = lines[fmt_index:next_recipe_index] | ||
| actual = { | ||
| "working_directory": lines[0], | ||
| "previous_attribute": lines[fmt_index - 1], | ||
| "previous_comment": next( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this file have to change because of changes to the |
||
| line for line in reversed(lines[:fmt_index]) if line.startswith("#") | ||
| ), | ||
| "commands": [line.strip() for line in fmt_recipe[1:] if line.strip()], | ||
| } | ||
| expected = { | ||
| "working_directory": 'set working-directory := "codex-rs"', | ||
| "previous_attribute": "# Format Rust and Python SDK code.", | ||
| "previous_comment": "# Format Rust and Python SDK code.", | ||
| "commands": [ | ||
| "cargo fmt -- --config imports_granularity=Item 2>/dev/null", | ||
| "cargo fmt -- --config imports_granularity=Item {stderr-null}", | ||
| "uv run --frozen --project ../sdk/python --extra dev ruff check --fix --fix-only ../sdk/python", | ||
| "uv run --frozen --project ../sdk/python --extra dev ruff format ../sdk/python", | ||
| ], | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done in a follow-up, but maybe this should be a platform-independent Python script?