Skip to content

refactor(entry_points): convert py_console_script_gen build tool to Rust - #4512

Draft
rickeylev wants to merge 3 commits into
rickeylev/shrubbery/01-py-wheel-distfrom
rickeylev/shrubbery/02-py-console-script-gen
Draft

rickeylev wants to merge 3 commits into
rickeylev/shrubbery/01-py-wheel-distfrom
rickeylev/shrubbery/02-py-console-script-gen

Conversation

@rickeylev

@rickeylev rickeylev commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Generating console script entry points via Python requires executing a
full Python binary during py_console_script_gen actions.

Add //crates/py_console_script_gen:py_console_script_gen_lib with an
entry_points.txt reader and PEP 503 distribution name normalizer,
register py_console_script_gen on shrubbery, and wire the rule to
get_shrubbery_tool.

Work towards #4250

@rickeylev

rickeylev commented Nov 16, 2026 •

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 unreviewed by the user.

Generating console script entry points via Python requires executing a
full Python binary during `py_console_script_gen` actions.

Add `//crates/py_console_script_gen:py_console_script_gen_lib` with an
`entry_points.txt` reader and PEP 503 distribution name normalizer,
register `py_console_script_gen` on `shrubbery`, and wire the rule to
`get_shrubbery_tool`.
Comment thread crates/py_console_script_gen/src/lib.rs Outdated
}

/// Expands `@flagfile` arguments into `OsString` values via `argfile`.
pub fn expand_args<I, T>(args: I) -> Result<Vec<OsString>, 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.

the parent pr has a similar function. reconcile.

@rickeylev rickeylev Nov 16, 2026 •

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.

Reconciled in fe584c3: the per-crate expand_args is gone; like the parent PR this now calls argfile::expand_args_from(..., argfile::parse_fromfile, argfile::PREFIX) directly.

This is an agent-generated comment unreviewed by the user.

Comment thread crates/py_console_script_gen/src/lib.rs Outdated
match arg {
Short('h') | Long("help") => {
return Err(
"Usage: py_console_script_gen [--console-script <str>] --console-script-guess <str> [--shebang <str>] <ENTRY_POINTS_TXT> <OUT>"

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.

same comment here as in parent pr.

several comments in the parent pr apply to this pr: fix and reconcile

@rickeylev rickeylev Nov 16, 2026 •

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.

Applied in fe584c3: USAGE constant + Cli::Help, keep-sorted flags module, anyhow errors with {err:#}, long-only arguments with a single arg.unexpected() fall-through, run_with_options folded into run(&Options). The same conventions are folded into every later level of the stack (03–07) so the whole stack now shares one arg-parsing shape.

This is an agent-generated comment unreviewed by the user.

Comment thread crates/py_console_script_gen/src/lib.rs Outdated
);
}
Long("console-script") => {
let val = parser

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.

similar comment here as in parent pr: this same logic is done by almost all the sub commands. reconcile/unify arg parsing logic for whole stack

@rickeylev rickeylev Nov 16, 2026 •

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.

Unified across the stack in fe584c3 (and the corresponding commits on 03–07): every subcommand now uses the identical argfile → lexopt::Parser → flags::* match → bail!(arg.unexpected()) pattern with anyhow ? instead of per-call map_err chains; parser.value()?.string()? is the only per-flag logic left.

This is an agent-generated comment unreviewed by the user.

Comment thread crates/py_console_script_gen/src/lib.rs Outdated
Comment on lines +154 to +156
if trimmed.is_empty() || trimmed.starts_with(['#', ';']) {
continue;
}

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.

a prior PR mentioned using chaining of iterators to do this type of pre-filtering: respect that. apply throughout stack

@rickeylev rickeylev Nov 16, 2026 •

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 b27e846: parse_console_scripts now pre-filters with lines().map(trim).filter(!empty && !comment) instead of the continue guard. The only other continue-style pre-filter in the stack was sanitize_extract_path in 03 (extract_wheel_files), which now uses split(...).filter(...) + extend.

This is an agent-generated comment unreviewed by the user.

Comment thread crates/py_console_script_gen/src/lib.rs Outdated
format!(
"{shebang_prefix}import sys

# See @rules_python//python/private:py_console_script_gen.py for explanation

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.

this comment is outdated

@rickeylev rickeylev Nov 16, 2026 •

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.

Fixed in b27e846: the generated script now says # See @rules_python//crates/py_console_script_gen for explanation, and the sys.path explanation from the Python module's docstring is carried over into this crate's module docs so the pointer stays meaningful once the Python fallback goes away.

This is an agent-generated comment unreviewed by the user.

Use argfile's parse_fromfile directly instead of a per-crate flagfile
wrapper, adopt the USAGE constant, flags module, anyhow errors, and
long-only arguments used by the other shrubbery subcommands, and fold
run_with_options into run(&Options).
@rickeylev
rickeylev force-pushed the rickeylev/shrubbery/02-py-console-script-gen branch from 727ea34 to fe584c3 Compare November 16, 2026 05:09
Pre-filter blank and comment lines via lines().map().filter() instead of
early continue guards, and point the generated script's comment at this
crate (with the sys.path explanation carried over into the crate docs)
now that the Python module is only a fallback.

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