summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2020-06-18 12:04:10 +0100
committerGitHub <noreply@github.com>2020-06-18 13:04:10 +0200
commit8a902b7ee622ada258d15fb122092c1f02b82698 (patch)
tree908598a5f83b76989e834fe946a6cdbc50131c41 /django/utils
parent7f4db2d82b1385d1026c441e25abd4cb19fcccc6 (diff)
Fixed #31716 -- Fixed detection of console scripts in autoreloader on Windows.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/autoreload.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 873f3d8367..09a696a4f9 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -207,12 +207,26 @@ def get_child_arguments():
on reloading.
"""
import django.__main__
+ django_main_path = Path(django.__main__.__file__)
+ py_script = Path(sys.argv[0])
args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions]
- if sys.argv[0] == django.__main__.__file__:
+ if py_script == django_main_path:
# The server was started with `python -m django runserver`.
args += ['-m', 'django']
args += sys.argv[1:]
+ elif not py_script.exists():
+ # sys.argv[0] may not exist for several reasons on Windows.
+ # It may exist with a .exe extension or have a -script.py suffix.
+ exe_entrypoint = py_script.with_suffix('.exe')
+ if exe_entrypoint.exists():
+ # Should be executed directly, ignoring sys.executable.
+ return [exe_entrypoint, *sys.argv[1:]]
+ script_entrypoint = py_script.with_name('%s-script.py' % py_script.name)
+ if script_entrypoint.exists():
+ # Should be executed as usual.
+ return [*args, script_entrypoint, *sys.argv[1:]]
+ raise RuntimeError('Script %s does not exist.' % py_script)
else:
args += sys.argv
return args