Skip to content

Propagate exit code through Python __main__ wrapper#776

Merged
charliermarsh merged 1 commit intoastral-sh:mainfrom
andersk:wrapper-exit
Nov 16, 2022
Merged

Propagate exit code through Python __main__ wrapper#776
charliermarsh merged 1 commit intoastral-sh:mainfrom
andersk:wrapper-exit

Conversation

@andersk
Copy link
Contributor

@andersk andersk commented Nov 16, 2022

Fixes #775.

ruff/__main__.py Outdated
if __name__ == "__main__":
ruff = os.path.join(sysconfig.get_path("scripts"), "ruff")
os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]])
exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))
Copy link
Contributor

Choose a reason for hiding this comment

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

exit() is not a built-in function and is only defined if the site module is imported during Python's initialization (which, for example, can be disabled with -S option passed to the interpreter). You should use sys.exit() instead:

Suggested change
exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))
sys.exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks. (Ruff should have a rule for this!)

@charliermarsh charliermarsh merged commit f1fee5d into astral-sh:main Nov 16, 2022
@andersk andersk deleted the wrapper-exit branch November 20, 2022 01:59
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.

0 exit code when used as a module

3 participants