Skip to content

Commit 978255d

Browse files
authored
Merge pull request #1610 from pallets/reloader-args
work around issue using pydevd with the reloader
2 parents 51accff + e686ae7 commit 978255d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Unreleased
1313
message to the description if ``e.show_exception`` is set to
1414
``True``. This is a more secure default than the original 0.15.0
1515
behavior and makes it easier to control without losing information.
16-
(:pr:`1592`)
16+
:pr:`1592`
17+
- Work around an issue in some external debuggers that caused the
18+
reloader to fail. :issue:`1607`
1719

1820

1921
Version 0.15.4

src/werkzeug/_reloader.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ def _get_args_for_reloading():
6868
a program other than python)
6969
"""
7070
rv = [sys.executable]
71-
py_script = os.path.abspath(sys.argv[0])
71+
py_script = sys.argv[0]
7272
args = sys.argv[1:]
7373
# Need to look at main module to determine how it was executed.
7474
__main__ = sys.modules["__main__"]
7575

7676
if __main__.__package__ is None:
7777
# Executed a file, like "python app.py".
78+
py_script = os.path.abspath(py_script)
79+
7880
if os.name == "nt":
7981
# Windows entry points have ".exe" extension and should be
8082
# called directly.
@@ -101,11 +103,16 @@ def _get_args_for_reloading():
101103
# TODO remove this once Flask no longer misbehaves
102104
args = sys.argv
103105
else:
104-
py_module = __main__.__package__
105-
name = os.path.splitext(os.path.basename(py_script))[0]
106+
if os.path.isfile(py_script):
107+
# Rewritten by Python from "-m script" to "/path/to/script.py".
108+
py_module = __main__.__package__
109+
name = os.path.splitext(os.path.basename(py_script))[0]
106110

107-
if name != "__main__":
108-
py_module += "." + name
111+
if name != "__main__":
112+
py_module += "." + name
113+
else:
114+
# Incorrectly rewritten by pydevd debugger from "-m script" to "script".
115+
py_module = py_script
109116

110117
rv.extend(("-m", py_module.lstrip(".")))
111118

0 commit comments

Comments
 (0)