Skip to content

Python script execution does not relay exit code #5773

Closed

Description

@cwichel
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 10 (Build 19044)
  • Poetry version: 1.2.0b1
  • Link of a Gist with the contents of your pyproject.toml file: Not required.

Issue

Note:

Poetry is not relaying the exit codes when running python scripts on the console:

>  poetry run python -c "import sys; sys.exit(1)"
> echo %errorlevel%
0

But if I execute it directly...

> python -c "import sys; sys.exit(1)"
> echo %errorlevel%
1

Is this the expected behavior?

Activity

  1. added
    kind/bugSomething isn't working as expected
    status/triageThis issue needs to be triaged
    on Jun 5, 2022
  2. dimbleby commented on Jun 5, 2022

    @dimbleby
    Contributor

    Works fine on Linux

    $ poetry run python -c "import sys; sys.exit(13)"
    $ echo $?
    13
    

    relevant code seems to be https://github.com/python-poetry/poetry/blob/865aa94dd3393076f790d3351f6ae18483673e38/src/poetry/utils/env.py#L1501-#L1511.

    I don't have a suitable windows environment to test on but I can tweak the code to force it through the Popen branch anyway, at which point I see two things:

    • this code seems to have been broken by Fix running console scripts of editable dependencies on Windows #3339, I think it has to go cmd = list_to_shell_command(command) if it's going to set shell=True, and then run cmd

      • else I just get a python interpreter when running poetry run python -c "import sys; sys.exit(13)" ...
      • @kevincon is that right?
    • but that bug isn't in 1.2.0b1 so you won't see it, and after tweaking it manually I still get the expected return code when going through that branch on Linux

    So I dunno, some sort of windows-only thing maybe?

  3. kevincon commented on Jun 5, 2022

    @kevincon
    Contributor

    @dimbleby thanks for your analysis! I’m not sure I understand the issue with #3339 since https://stackoverflow.com/a/1253161 suggests that passing a command as a list and setting shell=True on Windows should already convert the sequence to a string, but if it’s causing problems then feel free to revert it. It took over 1.5 years for #3339 to be reviewed and merged, so I won’t be working on that particular issue anymore.

  4. dimbleby commented on Jun 5, 2022

    @dimbleby
    Contributor

    I don't have a windows environment to test in: perhaps this is fine on Windows.

    I guess if it's broken then someone who does use windows will notice soon enough...

  5. radoering commented on Jun 6, 2022

    @radoering
    Member

    I can't reproduce the issue in cmd on Windows with either 1.2.0b1 or master. 🤷

  6. cwichel commented on Jun 6, 2022

    @cwichel
    Author

    I've performed more testing on my side and I've found that the error appears depending on the install mode of poetry...

    1. If I install the last version of poetry (1.2.0b1) using pip (python -m pip install poetry==1.2.0b1) the return code is incorrect (same test as in the example).
    2. If I install the last version of poetry (1.2.0b1) using the recommended mode (curl -sSL https://install.pyt...) the return code is correct.
  7. neersighted commented on Jun 9, 2022

    @neersighted
    Member

    I've performed more testing on my side and I've found that the error appears depending on the install mode of poetry...

    1. If I install the last version of poetry (1.2.0b1) using pip (`python -m pip install poetry==1.2.0b1`) the return code is incorrect (same test as in the example).
    
    2. If I install the last version of poetry (1.2.0b1) using the recommended mode (`curl -sSL https://install.pyt...`) the return code is correct.
    

    Please try again on b2 -- the issue likely is because when installing with pip you're pulling in a stable (instead of pre-release) poetry-core.

  8. cwichel commented on Jun 10, 2022

    @cwichel
    Author

    Tested doing the following:

    1. Created a conda environment for python 3.7:
      > conda create -n py37 python=3.7.11 -y
      > activate py37 
      
    2. Installed poetry 1.2.0b2:
      > pip install poetry==1.2.0b2
      
    3. Running test:
      > poetry run python -c "import sys; sys.exit(1)"
      > echo %errorlevel%
      1 
      

    Everything seems to be working OK now 😄

  9. github-actions commented on Mar 2, 2024

    @github-actions

    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.

  10. locked as resolved and limited conversation to collaborators on Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions