Skip to content

Default package mode to preserve public globals#4

Merged
alvinwan merged 1 commit intomainfrom
dev/alvin/preserve-public-globals-default
Apr 4, 2026
Merged

Default package mode to preserve public globals#4
alvinwan merged 1 commit intomainfrom
dev/alvin/preserve-public-globals-default

Conversation

@alvinwan
Copy link
Copy Markdown
Owner

@alvinwan alvinwan commented Apr 4, 2026

Summary

  • default package-mode CLI behavior to preserve public globals and package-compatible names
  • preserve public top-level functions and classes via generated aliases while still shortening internal references
  • update docs and tests to match the new preserve-by-default, rename-only flag surface

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 build
  • python3 -m pymini --help

@alvinwan alvinwan merged commit 14b578d into main Apr 4, 2026
10 checks passed
@alvinwan alvinwan deleted the dev/alvin/preserve-public-globals-default branch April 4, 2026 09:09
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread pymini/pymini.py
def append_public_aliases(tree, aliases):
root = next(ast.walk(tree))
for node in aliases:
root.body.append(ast.copy_location(node, root))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread pymini/cli.py
Comment on lines +44 to +45
if args[0] in MODES:
return args
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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