Skip to content

Commit 8a38bca

Browse files
authored
Merge pull request #1242 from samdroid-apps/fix-reloader-nixos-2
Do not add python executable to executable scripts when reloading
2 parents 5d80fa2 + 268cad0 commit 8a38bca

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Unreleased
9797
by setting ``e.args = ()``. (`#1395`_)
9898
- Add support for status code 424 :exc:`~exceptions.FailedDependency`.
9999
(`#1358`_)
100+
- The reloader will not prepend the Python executable to the command
101+
line if the Python file is marked executable. This allows the
102+
reloader to work on NixOS. (`#1242`_)
100103

101104
.. _`#209`: https://github.com/pallets/werkzeug/pull/209
102105
.. _`#609`: https://github.com/pallets/werkzeug/pull/609
@@ -112,6 +115,7 @@ Unreleased
112115
.. _`#1231`: https://github.com/pallets/werkzeug/issues/1231
113116
.. _`#1233`: https://github.com/pallets/werkzeug/pull/1233
114117
.. _`#1237`: https://github.com/pallets/werkzeug/pull/1237
118+
.. _`#1242`: https://github.com/pallets/werkzeug/pull/1242
115119
.. _`#1245`: https://github.com/pallets/werkzeug/pull/1245
116120
.. _`#1249`: https://github.com/pallets/werkzeug/issues/1249
117121
.. _`#1252`: https://github.com/pallets/werkzeug/pull/1252

werkzeug/_reloader.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,26 @@ 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]
65-
py_script = sys.argv[0]
67+
py_script = os.path.abspath(sys.argv[0])
68+
6669
if os.name == 'nt' and not os.path.exists(py_script) and \
6770
os.path.exists(py_script + '.exe'):
6871
py_script += '.exe'
69-
if os.path.splitext(rv[0])[1] == '.exe' and os.path.splitext(py_script)[1] == '.exe':
72+
73+
windows_workaround = (
74+
os.path.splitext(rv[0])[1] == '.exe'
75+
and os.path.splitext(py_script)[1] == '.exe'
76+
)
77+
nix_workaround = os.path.isfile(py_script) and os.access(py_script, os.X_OK)
78+
79+
if windows_workaround or nix_workaround:
7080
rv.pop(0)
81+
7182
rv.append(py_script)
7283
rv.extend(sys.argv[1:])
7384
return rv

0 commit comments

Comments
 (0)