MCPcopy
hub / github.com/django/django / get_child_arguments

Function get_child_arguments

django/utils/autoreload.py:224–265  ·  view source on GitHub ↗

Return the executable. This contains a workaround for Windows if the executable is reported to not have the .exe extension which can cause bugs on reloading.

()

Source from the content-addressed store, hash-verified

222
223
224def get_child_arguments():
225 """
226 Return the executable. This contains a workaround for Windows if the
227 executable is reported to not have the .exe extension which can cause bugs
228 on reloading.
229 """
230 import __main__
231
232 py_script = Path(sys.argv[0])
233 exe_entrypoint = py_script.with_suffix(".exe")
234
235 args = [sys.executable] + ["-W%s" % o for o in sys.warnoptions]
236 if sys.implementation.name in ("cpython", "pypy"):
237 args.extend(
238 f"-X{key}" if value is True else f"-X{key}={value}"
239 for key, value in sys._xoptions.items()
240 )
241 # __spec__ is set when the server was started with the `-m` option,
242 # see https://docs.python.org/3/reference/import.html#main-spec
243 # __spec__ may not exist, e.g. when running in a Conda env.
244 if getattr(__main__, "__spec__", None) is not None and not exe_entrypoint.exists():
245 spec = __main__.__spec__
246 if (spec.name == "__main__" or spec.name.endswith(".__main__")) and spec.parent:
247 name = spec.parent
248 else:
249 name = spec.name
250 args += ["-m", name]
251 args += sys.argv[1:]
252 elif not py_script.exists():
253 # sys.argv[0] may not exist for several reasons on Windows.
254 # It may exist with a .exe extension or have a -script.py suffix.
255 if exe_entrypoint.exists():
256 # Should be executed directly, ignoring sys.executable.
257 return [exe_entrypoint, *sys.argv[1:]]
258 script_entrypoint = py_script.with_name("%s-script.py" % py_script.name)
259 if script_entrypoint.exists():
260 # Should be executed as usual.
261 return [*args, script_entrypoint, *sys.argv[1:]]
262 raise RuntimeError("Script %s does not exist." % py_script)
263 else:
264 args += sys.argv
265 return args
266
267
268def trigger_reload(filename):

Callers 1

restart_with_reloaderFunction · 0.85

Calls 3

extendMethod · 0.80
itemsMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected