Skip to content
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

Python script execution does not relay exit code #5773

Closed
2 of 3 tasks
cwichel opened this issue Jun 5, 2022 · 8 comments
Closed
2 of 3 tasks

Python script execution does not relay exit code #5773

cwichel opened this issue Jun 5, 2022 · 8 comments
Labels
kind/bug Something isn't working as expected

Comments

@cwichel
Copy link

cwichel commented Jun 5, 2022

  • 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?

@cwichel cwichel added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 5, 2022
@dimbleby
Copy link
Contributor

dimbleby commented Jun 5, 2022

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?

@kevincon
Copy link
Contributor

kevincon commented Jun 5, 2022

@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.

@dimbleby
Copy link
Contributor

dimbleby commented Jun 5, 2022

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...

@radoering
Copy link
Member

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

@cwichel
Copy link
Author

cwichel commented Jun 6, 2022

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.

@neersighted
Copy link
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.

@cwichel
Copy link
Author

cwichel commented Jun 10, 2022

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 😄

Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

6 participants