Default package mode to preserve public globals#4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a991ea71e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def append_public_aliases(tree, aliases): | ||
| root = next(ast.walk(tree)) | ||
| for node in aliases: | ||
| root.body.append(ast.copy_location(node, root)) |
There was a problem hiding this comment.
Insert public aliases before import-time API discovery
Appending aliases at module end changes import-time semantics for modules that inspect globals() before EOF (for example dynamic __all__ construction). After top-level defs are renamed, append_public_aliases adds old_name = new_name only at the end, so code executed earlier sees only the minified name and can publish the wrong API surface (e.g., star exports missing the original public symbol), which violates the new "preserve public globals" default.
Useful? React with 👍 / 👎.
| if args[0] in MODES: | ||
| return args |
There was a problem hiding this comment.
Disambiguate legacy paths named package or bundle
The legacy-compatibility path injection now treats a first positional token equal to package/bundle as an explicit mode, so pymini package -o out (where package is the source directory) fails with a missing path argument instead of processing that directory. This is a behavioral regression from the previous CLI for users with those common directory names unless they rewrite invocations (e.g., ./package or explicit mode + path).
Useful? React with 👍 / 👎.
Summary
Why
The CLI had both preserve and rename flags even though the intended safe default for package mode is compatibility. This change makes preservation the default and keeps aggressive renaming behind explicit opt-in flags.
Validation
.venv/bin/python -m pytest.venv/bin/python -m buildpython3 -m pymini --help