Skip to content
Permalink
Browse files

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.
  • Loading branch information...
samdroid-apps committed Jan 21, 2018
1 parent 8393ee8 commit 81b011785c6d9d85635f757e25c11c0deb91c9a4
Showing with 9 additions and 2 deletions.
  1. +9 −2 werkzeug/_reloader.py
@@ -59,14 +59,21 @@ def _find_observable_paths(extra_files=None):
def _get_args_for_reloading():
"""Returns the executable. This contains a workaround for windows
if the executable is incorrectly reported to not have the .exe
extension which can cause bugs on reloading.
extension which can cause bugs on reloading. This also contains
a workaround for linux where the file is executable (possibly with
a program other than python)
"""
rv = [sys.executable]
py_script = sys.argv[0]
if os.name == 'nt' and not os.path.exists(py_script) and \
os.path.exists(py_script + '.exe'):
py_script += '.exe'
if os.path.splitext(rv[0])[1] == '.exe' and os.path.splitext(py_script)[1] == '.exe':

windows_workaround = (os.path.splitext(rv[0])[1] == '.exe' and
os.path.splitext(py_script)[1] == '.exe')
nix_workaround = (os.path.isfile(py_script) and
os.access(py_script, os.X_OK))
if windows_workaround or nix_workaround:
rv.pop(0)
rv.append(py_script)
rv.extend(sys.argv[1:])

0 comments on commit 81b0117

Please sign in to comment.
You can’t perform that action at this time.