-
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
Exit code relay fails when run command is a script #6801
Comments
works fine for me, can you put together a reproduction eg in a dockerfile? $ cat toolname/__main__.py
#!/usr/bin/env python3
def main():
import sys
print("hello")
sys.exit(4)
if __name__ == "__main__":
main()
|
oh I see, you don't mean that the exit code is not relayed, you mean that the return code is not relayed, as an exit code. (Apologies if this seems pedantic, but this is what confused me) I expect an MR would be welcome, either of the approaches that you suggest sounds reasonable. |
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. |
1.2.2
3.10.6
-vvv
option) and have included the output below.Issue
Hi there,
When using
poetry run
to run a script defined in thescripts
section ofpyproject.toml
the exit code of the script is not relayed as the final exit code ofpoetry
itself. I originally noticed #5773 and #2369 and was wondering why it wasn't working for me.Consider the following cases:
It looks like #4456 did not fix #2369 because these are different execution paths. Looking at
commands/run.py
, running a script (as defined inpyproject.toml
) is a different execution path than running non-scripts. As mentioned in #2369, I believe the fix would be:f"import_module('{module}').{callable_}()"
->f"sys.exit(import_module('{module}').{callable_}())"
I made this change locally and it fixed this issue for me.
Alternatively, I believe another fix would be removing the
RunCommand.run_script
special-case code. Sincepoetry
knows where the script is ($VIRTUALENV/bin/
), it could include this directory in the$PATH
when executing the command.poetry
would then execute the script generated bybuilders/editable.py
.There may be reasons these two code paths are distinct that I don't understand, but if they can be unified to a single path that would ease maintenance burden and help alleviate situations like this where one path is updated but the other is forgotten.
The text was updated successfully, but these errors were encountered: