Skip to content

Commit

Permalink
Merge pull request #1610 from pallets/reloader-args
Browse files Browse the repository at this point in the history
work around issue using pydevd with the reloader
  • Loading branch information
davidism committed Jul 10, 2019
2 parents 51accff + e686ae7 commit 978255d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Expand Up @@ -13,7 +13,9 @@ Unreleased
message to the description if ``e.show_exception`` is set to
``True``. This is a more secure default than the original 0.15.0
behavior and makes it easier to control without losing information.
(:pr:`1592`)
:pr:`1592`
- Work around an issue in some external debuggers that caused the
reloader to fail. :issue:`1607`


Version 0.15.4
Expand Down
17 changes: 12 additions & 5 deletions src/werkzeug/_reloader.py
Expand Up @@ -68,13 +68,15 @@ def _get_args_for_reloading():
a program other than python)
"""
rv = [sys.executable]
py_script = os.path.abspath(sys.argv[0])
py_script = sys.argv[0]
args = sys.argv[1:]
# Need to look at main module to determine how it was executed.
__main__ = sys.modules["__main__"]

if __main__.__package__ is None:
# Executed a file, like "python app.py".
py_script = os.path.abspath(py_script)

if os.name == "nt":
# Windows entry points have ".exe" extension and should be
# called directly.
Expand All @@ -101,11 +103,16 @@ def _get_args_for_reloading():
# TODO remove this once Flask no longer misbehaves
args = sys.argv
else:
py_module = __main__.__package__
name = os.path.splitext(os.path.basename(py_script))[0]
if os.path.isfile(py_script):
# Rewritten by Python from "-m script" to "/path/to/script.py".
py_module = __main__.__package__
name = os.path.splitext(os.path.basename(py_script))[0]

if name != "__main__":
py_module += "." + name
if name != "__main__":
py_module += "." + name
else:
# Incorrectly rewritten by pydevd debugger from "-m script" to "script".
py_module = py_script

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

Expand Down

0 comments on commit 978255d

Please sign in to comment.