Skip to content

Commit 81b0117

Browse files
committed
Do not add python executable to executable scripts when reloading
Sometimes, the file in `sys.argv[0]` may use an interpreter other than python. For example; NixOs replaces `sys.argv[0]` to a wrapper shell script which changes the environment variables before running the main entrypoint. Currently, the reloader assumes that all scripts need the python interpreter appended their command line. This patch changes that to check if the script is set as executable, and does not use the python command if it is.
1 parent 8393ee8 commit 81b0117

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

werkzeug/_reloader.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ def _find_observable_paths(extra_files=None):
5959
def _get_args_for_reloading():
6060
"""Returns the executable. This contains a workaround for windows
6161
if the executable is incorrectly reported to not have the .exe
62-
extension which can cause bugs on reloading.
62+
extension which can cause bugs on reloading. This also contains
63+
a workaround for linux where the file is executable (possibly with
64+
a program other than python)
6365
"""
6466
rv = [sys.executable]
6567
py_script = sys.argv[0]
6668
if os.name == 'nt' and not os.path.exists(py_script) and \
6769
os.path.exists(py_script + '.exe'):
6870
py_script += '.exe'
69-
if os.path.splitext(rv[0])[1] == '.exe' and os.path.splitext(py_script)[1] == '.exe':
71+
72+
windows_workaround = (os.path.splitext(rv[0])[1] == '.exe' and
73+
os.path.splitext(py_script)[1] == '.exe')
74+
nix_workaround = (os.path.isfile(py_script) and
75+
os.access(py_script, os.X_OK))
76+
if windows_workaround or nix_workaround:
7077
rv.pop(0)
7178
rv.append(py_script)
7279
rv.extend(sys.argv[1:])

0 commit comments

Comments
 (0)