Skip to content

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

@k4ml

Description

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

Metadata

Metadata

Assignees

Labels

area/cliRelated to the command linekind/bugSomething isn't working as expectedstatus/duplicateDuplicate issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions