Skip to content

refactor(wheel): convert py_wheel_dist build tool to Rust - #4511

Draft
rickeylev wants to merge 2 commits into
mainfrom
rickeylev/shrubbery/01-py-wheel-dist
Draft

rickeylev wants to merge 2 commits into
mainfrom
rickeylev/shrubbery/01-py-wheel-dist

Conversation

@rickeylev

@rickeylev rickeylev commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Drop the wheel-name validation that the Python tool never had, use
argfile's parse_fromfile directly instead of a per-crate flagfile
parser, and adopt the USAGE constant, flags module, anyhow errors, and
long-only arguments used by the other shrubbery subcommands.

Copying stamped wheel outputs into a dist directory currently spawns a
Python interpreter per `py_wheel_dist` target.

Add `//crates/py_wheel_dist:py_wheel_dist_lib`, register `py_wheel_dist`
on `shrubbery`, and route `PyWheelDistDir` through `get_shrubbery_tool`.
`get_shrubbery_tool` gains `files_to_run` and `is_rust` so rules can pass
the resolved tool straight to `ctx.actions.run` and branch on which
implementation resolved.
@rickeylev

Copy link
Copy Markdown
Collaborator Author

This PR was prepared by an agent under human direction. Review comments are triaged by the human author; agent-drafted replies and changes are reviewed and approved by the author before posting.

This is an agent-generated comment reviewed and approved by the user.

Comment thread crates/py_wheel_dist/src/lib.rs Outdated
///
/// Ensures the trimmed name is non-empty and a valid single file basename without
/// path separators (`/`, `\`) or parent directory traversal (`..`).
pub fn validate_wheel_name(raw_name: &str) -> io::Result<&str> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this logic copied from the python implementation? It seems like over-defensive logic. Justify or remove

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in d24c535. The Python tool just does name_file.read_text().strip() and copies, so create_wheel_dist now trims and copies with no extra validation.

This is an agent-generated comment reviewed and approved by the user.

Comment thread crates/py_wheel_dist/src/lib.rs Outdated
pub output: PathBuf,
}

fn parse_flagfile(content: &str, prefix: char) -> Vec<argfile::Argument> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've seen this same "parse flagfile" logic in several subcommands. Factor out a common library to use instead

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d24c535: dropped the per-crate parse_flagfile and the bare-@ pre-check and call argfile::expand_args_from(..., argfile::parse_fromfile, argfile::PREFIX) directly, same as zipper/zip_main_maker/wheelmaker. The remaining subcommands in the stack get the same treatment on their own levels so there is no bespoke flagfile logic left to factor out.

This is an agent-generated comment reviewed and approved by the user.

Comment thread crates/py_wheel_dist/src/lib.rs Outdated
Comment on lines +109 to +114
Short('h') | Long("help") => {
return Err(
"Usage: py_wheel_dist --wheel <path> --name_file <path> --output <path>"
.to_string(),
);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow the pattern of the other tools and have a USAGE constant instead of an inline usage string

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d24c535: USAGE constant plus Cli::Help, printed to stdout with exit 0 like the other tools.

This is an agent-generated comment reviewed and approved by the user.

Comment thread crates/py_wheel_dist/src/lib.rs Outdated
);
}
Long("wheel") => wheel = Some(parse_non_empty_path(&mut parser, "--wheel")?),
Long("name_file") => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow the pattern of the other tools and use symbolic constants instead of string literals.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d24c535: added a keep-sorted flags module and switched the match arms and error messages to its constants.

This is an agent-generated comment reviewed and approved by the user.

Comment thread crates/py_wheel_dist/src/lib.rs Outdated
}
return Err(format!("unexpected argument: --{other}"));
}
Short(ch) => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother to support short arguments. Keep it simple and just have long arguments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d24c535: the Short(..)/Long(other)/Value(..) arms are replaced by a single _ => bail!("{}", arg.unexpected()). -h stays as the one short flag, matching the other subcommands.

This is an agent-generated comment reviewed and approved by the user.

Drop the wheel-name validation that the Python tool never had, use
argfile's parse_fromfile directly instead of a per-crate flagfile
parser, and adopt the USAGE constant, flags module, anyhow errors, and
long-only arguments used by the other shrubbery subcommands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant