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

poetry run script doesn't run the actual executable script #2435

Closed
3 tasks done
k4ml opened this issue May 17, 2020 · 2 comments
Closed
3 tasks done

poetry run script doesn't run the actual executable script #2435

k4ml opened this issue May 17, 2020 · 2 comments
Assignees
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/duplicate Duplicate issues

Comments

@k4ml
Copy link

k4ml commented May 17, 2020

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

Issue

I'm trying to run django management command not through python manage.py command as usual, so that I can have single entry-point to my django app. I prefer to write my cli using Click instead of django management command framework which having to many boilerplate. This basically works perfectly fine. Example of the script is https://github.com/k4ml/cutepony/blob/master/cutepony/cli/cutepony.py. I can run any command with the following:-

poetry run cutepony manage <any_django_command>

The problem is with runserver command when running with autoreload (the default). The way autoreload is implemented is that it will re-execute the command using subprocess and to do that, it will re-collect the original command, using sys.executable and sys.argv. But using poetry run above, the resulting command that django will see is like:-

['/home/kamal/.cache/pypoetry/virtualenvs/cutepony-U1m74Vcq-py3.8/bin/python', 'cutepony', 'manage', 'runserver']

and will fail with the following error:-

/home/kamal/.cache/pypoetry/virtualenvs/cutepony-U1m74Vcq-py3.8/bin/python: can't find '__main__' module in 'cutepony'

This is because it try to run cutepony as python module. The correct command that django should see is:-

['/home/kamal/.cache/pypoetry/virtualenvs/cutepony-U1m74Vcq-py3.8/bin/python', '/home/kamal/.cache/pypoetry/virtualenvs/cutepony-U1m74Vcq-py3.8/bin/cutepony', 'manage', 'runserver']

The fix for this seem quite simple, in poetry/console/commands/run.py:RunCommand.run_script(), we can fix args[0] to be an absolute path to the script executable.

@k4ml k4ml added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 17, 2020
@0xMRTT 0xMRTT added area/cli Related to the command line good first issue and removed status/triage This issue needs to be triaged labels Oct 2, 2022
@logan-bobo logan-bobo self-assigned this Nov 4, 2022
@wagnerluis1982
Copy link
Contributor

This is a duplicate of #965

@radoering radoering added status/duplicate Duplicate issues and removed good first issue labels Jan 21, 2023
@radoering radoering closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2023
Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/duplicate Duplicate issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants