-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- OS version and name: ArchLinux (ArchLabs) 5.6.7-arch1-1
- Poetry version: 1.0.5
- Link of a Gist with the contents of your pyproject.toml file: https://github.com/pawamoy/poetry-issue-2369/blob/master/pyproject.toml
Issue
Poetry does not relay the exit code of a script (as in from Poetry's scripts section) when ran with poetry run.
To reproduce, run the following snippet or check the repo directly: https://github.com/pawamoy/poetry-issue-2369
$ git clone https://github.com/pawamoy/poetry-issue-2369
$ cd poetry-issue-2369
$ poetry install -v
$ poetry shell
$ poetry-issue-2369
$ echo $?
1
$ exit
$ poetry run poetry-issue-2369
$ echo $?
0Additional information:
$ poetry run which poetry-issue-2369
/home/pawamoy/.cache/pypoetry/virtualenvs/poetry-issue-2369-Q6VvSue2-py3.8/bin/poetry-issue-2369
$ cat /home/pawamoy/.cache/pypoetry/virtualenvs/poetry-issue-2369-Q6VvSue2-py3.8/bin/poetry-issue-2369
#!/home/pawamoy/.cache/pypoetry/virtualenvs/poetry-issue-2369-Q6VvSue2-py3.8/bin/python
#EASY-INSTALL-ENTRY-SCRIPT: 'poetry-issue-2369','console_scripts','poetry-issue-2369'
__requires__ = 'poetry-issue-2369'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('poetry-issue-2369', 'console_scripts', 'poetry-issue-2369')()
)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 in sys.exit(...).
This allows to run both the installed script with poetry-issue-2369 and the Python module with python -m poetry-issue-2369 seamlessly.
# cli.py
def main(args=None):
return 1# __main__.py
import sys
from poetry_issue_2369.cli import main
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))Solution
It seems to be because this snippet does not wrap the last line in sys.exit(...):
cmd += [
"import sys; "
"from importlib import import_module; "
"sys.argv = {!r}; {}"
"import_module('{}').{}()".format(args, src_in_sys_path, module, callable_)
]The solution would be to wrap it in sys.exit(...):
- "import_module('{}').{}()".format(args, src_in_sys_path, module, callable_)
+ "sys.exit(import_module('{}').{}())".format(args, src_in_sys_path, module, callable_)