Skip to content

Commit

Permalink
Fixed execution under pdb (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Dec 24, 2020
1 parent 455fff6 commit 884b08a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .flake8
Expand Up @@ -6,6 +6,7 @@ exclude =
,dist
,tools/configen/example/gen
,tools/configen/tests/test_modules/expected
,temp

# flake8-copyright does not support unicode, savoirfairelinux/flake8-copyright#15
,examples/plugins/example_configsource_plugin/hydra_plugins/example_configsource_plugin/example_configsource_plugin.py
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ __pycache__
/.nox
/report.json
/.coverage
/temp
.mypy_cache
pip-wheel-metadata
.ipynb_checkpoints
Expand Down
1 change: 1 addition & 0 deletions .yamllint
Expand Up @@ -36,6 +36,7 @@ ignore: |
**/multirun.yaml
.*
.nox
temp
# yamllint does not support unicode
# https://github.com/adrienverge/yamllint/issues/238
tests/standalone_apps/namespace_pkg_config_source_test/some_namespace/namespace_test/dir/config_with_unicode.yaml
Expand Down
18 changes: 17 additions & 1 deletion hydra/_internal/utils.py
Expand Up @@ -157,6 +157,22 @@ def compute_search_path_dir(
return search_path_dir


def is_under_debugger() -> bool:
"""
Attempts to detect if running under a debugger
"""
frames = inspect.stack()
if len(frames) >= 3:
filename = frames[-3].filename
if filename.endswith("/pdb.py"):
return True
elif filename.endswith("/pydevd.py"):
return True

# unknown debugging will sometimes set sys.trace
return sys.gettrace() is not None


def create_automatic_config_search_path(
calling_file: Optional[str],
calling_module: Optional[str],
Expand Down Expand Up @@ -195,7 +211,7 @@ def run_and_report(func: Any) -> Any:
try:
return func()
except Exception as ex:
if _is_env_set("HYDRA_FULL_ERROR"):
if _is_env_set("HYDRA_FULL_ERROR") or is_under_debugger():
raise ex
else:
if isinstance(ex, CompactHydraException):
Expand Down
1 change: 1 addition & 0 deletions news/1237.bugfix
@@ -0,0 +1 @@
No longer modifies exception stack trace when running under a debugger
1 change: 1 addition & 0 deletions tests/scripts/test_bash_dot_in_path.bash
@@ -1,4 +1,5 @@
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved

# Navigate to app with minimal configuration
cd tests/test_apps/app_with_cfg/
Expand Down

0 comments on commit 884b08a

Please sign in to comment.