Skip to content

fix: avoid dumping globals dictionary to stderr on console script exit - #287

Open
reginaldalfret wants to merge 1 commit into
linkedin:mainfrom
reginaldalfret:fix/console-script-stderr-globals-dump
Open

reginaldalfret wants to merge 1 commit into
linkedin:mainfrom
reginaldalfret:fix/console-script-stderr-globals-dump

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary of Changes

When executing a console script via \env.script, \shiv\ previously passed \partial(runpy.run_path, ...)\ directly to
un(), which invokes \sys.exit(module()).

Because
unpy.run_path\ returns the module globals dictionary upon completion, passing this dictionary directly to \sys.exit(d)\ causes Python to print the string representation of the dictionary to \stderr\ and exit with code 1.

This PR introduces a _run_script\ helper that executes
unpy.run_path\ without returning the globals dictionary, ensuring that \sys.exit(None)\ is invoked on normal script completion (exiting with code 0 cleanly).

Verification

  • Added \ est_run_script\ unit test in \ est/test_bootstrap.py\ verifying that _run_script\ executes the target file, returns \None, and triggers \sys.exit(None).
  • Verified all unit tests in \ est/test_bootstrap.py\ pass (21 passed, 2 skipped).

Resolves #240

When executing a console script with env.script, shiv previously passed
partial(runpy.run_path, ...) directly to run(), which calls sys.exit(module()).
Because runpy.run_path returns the executed module's globals dictionary,
passing a dict to sys.exit() caused Python to print the string representation
of the dictionary to stderr and terminate with exit status 1.

Introduce _run_script helper that invokes runpy.run_path without returning
its globals dict so that sys.exit receives None, cleanly exiting with code 0.
Add regression unit test in test_bootstrap.py.

Resolves linkedin#240

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
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.

Shiv with console script prints the __main__ module dictionary to stderr

1 participant