summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2020-06-18 12:04:10 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-06-18 13:04:44 +0200
commitac7f7eab0fad18fffc465bc4fdc092bcb2de2d80 (patch)
tree109e695a526c80326995d4879d9b92ae22c80174 /django/utils
parent928f6a90e404cc2433399e84ba73d83ace5eac2f (diff)
[3.1.x] Fixed #31716 -- Fixed detection of console scripts in autoreloader on Windows.
Backport of 8a902b7ee622ada258d15fb122092c1f02b82698 from master
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 845c46c8d4..1ef10a15f9 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