Skip to content

Exit code relay fails when run command is a script #6801

@rc-mattschwager

Description

@rc-mattschwager
  • Poetry version: 1.2.2
  • Python version: 3.10.6
  • OS version and name: macOS 12.5.1
  • pyproject.toml: Relevant details below
[tool.poetry.scripts]
toolname = "toolname.__main__:main"
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Hi there,

When using poetry run to run a script defined in the scripts section of pyproject.toml the exit code of the script is not relayed as the final exit code of poetry itself. I originally noticed #5773 and #2369 and was wondering why it wasn't working for me.

Consider the following cases:

$ poetry run python -m toolname --version
0.5.0
$ echo $?
1
$ poetry run toolname --version
0.5.0
$ echo $?
0

It looks like #4456 did not fix #2369 because these are different execution paths. Looking at commands/run.py, running a script (as defined in pyproject.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. Since poetry 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 by builders/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions