#34787: The 'runserver' command doesn't work when run from an installed script
on
Windows
-------------------------------------+-------------------------------------
Reporter: jp-larose | Owner: nobody
Type: Bug | Status: new
Component: Core | Version: 4.2
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
My `manage.py` is as follows:
{{{
#!/usr/bin/env python
import os
import sys
def django_manage():
"""Function implementation of python manage.py"""
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"<project_package>.settings.dev")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
if __name__ == "__main__":
django_manage()
}}}
In my `pyproject.toml` I have:
{{{
[project.scripts]
"djm" = "<project_package>.manage:django_manage"
}}}
In Windows this generates a `djm.exe` file.
This allows me to save a few keystrokes when issuing commands from CLI.
And it works for most of the django commands. The only exception I've
encountered so far is with the `runserver` command.
It gives:
{{{
<project_path>\venv\Scripts\python.exe: Error while finding module
specification for '__main__' (ValueError: __main__.__spec__ is None)
}}}
After much debugging and tracing, I found where the issue lies. The
problem is in the `get_child_arguments` function in
`django/utils/autoreload.py`. When you flip the first two `if`-`elif`
blocks, everything works. That is, the check for `not py_script.exists()`
needs to come before the check for `getattr(__main__, "__spec__", None) is
not None`.
I'm not sure if this creates different problems, but it certainly fixes
the one I was having.
--
Ticket URL: <https://code.djangoproject.com/ticket/34787>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018a157a2d16-d2bc6204-72ce-4963-a280-99d75d8009f5-000000%40eu-central-1.amazonses.com.