-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
poetry run does not relay exit code #2369
Comments
I'm seeing the same issue with Poetry version 1.0.10 on a CentOS 7 system using Python 3.7.6 build via Spack. |
After more digging, I was running into pallets/click#747. Switching from returning values to explicitly calling |
You mean you are now using I don't want to do this because then:
#!/path/to/some/python
# -*- coding: utf-8 -*-
import re
import sys
from my_package.my_module import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
I guess what I could do to solve these points is to duplicate each "script" function: # this one returns an integer
def func_a(args):
return 2
# this one actually sys.exits
def entrypoint_a(args):
sys.exit(func_a(args)) And use the entrypoints in [tool.poetry.scripts]
a = "my_package.my_module:entrypoint_a" |
But since console scripts, when installed, do the |
I agree that having poetry do the sys.exit would be the right thing. But, for better or worse, I'm using click, and since it doesn't do anything with the return value of a function that is a @click.command, it doesn't matter what poetry does, it's getting dropped before it ever gets into poetry's hands. Here's one conversation in the Click repo: pallets/click#747 |
Any news on this? |
Working fix in #2904, but I didn't get feedback on how to properly test the change. Anyway, I'm using PDM now instead of Poetry 🙂 |
What is your feedback on PDM? It looks fairly new and not too popular yet, but a lot closer to |
Care here for this problem. For me, this manifested when I converted a pre-commit hooks project from pip/setup to poetry: Pip/Setup console_scripts do:
Poetry installed scripts do:
So, hooks entrys in .pre-comit-hooks.yml that used to fail, now don't, because they all return int, and used to sys.exit, and now don't. In order to fix this, one could add sys.exit to the of then imported main(), but that means all python (not cli) consumers that call main() will get a hard sys exit, not just the returns int. That then means, one must drop a separate script entry point, like hook(), that calls main() and calls sys.exit with its return. It's all kind of awkword after moving from setup.py and expecting scripts to do the same thing. |
I'm also running into this UX oddity. My pattern is:
def main():
# Do things...
return exit_code
if __name__ == "__main__":
sys.exit(main())
Running the following does not relay the exit code, as mentioned above:
However, since I'm using
It would be nice to reconcile this difference and have |
This should be fixed in the latest preview release (1.2.0b1) by #4456. |
This is needed because Poetry 1.2 is the version that introduced return codes for scripts generated by Poetry, and we depend on the return code of `reuse`. See <python-poetry/poetry#2369>. Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
This is needed because Poetry 1.2 is the version that introduced return codes for scripts generated by Poetry, and we depend on the return code of `reuse`. See <python-poetry/poetry#2369>. Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
This is needed because Poetry 1.2 is the version that introduced return codes for scripts generated by Poetry, and we depend on the return code of `reuse`. See <python-poetry/poetry#2369>. Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue
Poetry does not relay the exit code of a script (as in from Poetry's
scripts
section) when ran withpoetry run
.To reproduce, run the following snippet or check the repo directly: https://github.com/pawamoy/poetry-issue-2369
Additional information:
Note how the installed script wraps the entry-point call into
sys.exit(...)
.It means that, as a best-practice, the entry-point itself should not use
sys.exit(...)
.My main function returns an integer, and it's the
__main__
module that wraps it insys.exit(...)
.This allows to run both the installed script with
poetry-issue-2369
and the Python module withpython -m poetry-issue-2369
seamlessly.Solution
It seems to be because this snippet does not wrap the last line in
sys.exit(...)
:https://github.com/python-poetry/poetry/blob/master/poetry/console/commands/run.py#L42-L47
The solution would be to wrap it in
sys.exit(...)
:The text was updated successfully, but these errors were encountered: