From ac7f7eab0fad18fffc465bc4fdc092bcb2de2d80 Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Thu, 18 Jun 2020 12:04:10 +0100 Subject: [3.1.x] Fixed #31716 -- Fixed detection of console scripts in autoreloader on Windows. Backport of 8a902b7ee622ada258d15fb122092c1f02b82698 from master --- django/utils/autoreload.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'django') 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 -- cgit v1.3