-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
- 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 (
-vvvoption).
- OS version and name: Linux x1 5.5.13-1-MANJARO Add support for private indices #1 SMP PREEMPT Wed Mar 25 17:14:28 UTC 2020 x86_64 GNU/Linux
- Poetry version: 1.0.5
- **Link of a pyproject.toml
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.