Skip to content

Commit

Permalink
add global debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Oct 9, 2024
1 parent 1d4c52b commit 8375e76
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 2 additions & 3 deletions dlt/cli/_dlt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
deploy_command_wrapper,
telemetry_change_status_command_wrapper,
)
from dlt.cli import debug


DEBUG_FLAG = False
ACTION_EXECUTED = False


Expand Down Expand Up @@ -88,9 +88,8 @@ def __call__(
values: Any,
option_string: str = None,
) -> None:
global DEBUG_FLAG
# will show stack traces (and maybe more debug things)
DEBUG_FLAG = True
debug.enable_debug()


def main() -> int:
Expand Down
5 changes: 2 additions & 3 deletions dlt/cli/command_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
change_telemetry_status_command,
telemetry_status_command,
)
from dlt.cli import debug

try:
from dlt.cli import deploy_command
Expand All @@ -33,13 +34,11 @@
except ModuleNotFoundError:
pass

DEBUG_FLAG = False


def on_exception(ex: Exception, info: str) -> None:
click.secho(str(ex), err=True, fg="red")
fmt.note("Please refer to %s for further assistance" % fmt.bold(info))
if DEBUG_FLAG:
if debug.is_debug_enabled():
raise ex


Expand Down
18 changes: 18 additions & 0 deletions dlt/cli/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Provides a global debug setting for the CLI"""

_DEBUG_FLAG = False


def enable_debug() -> None:
global _DEBUG_FLAG
_DEBUG_FLAG = True


def disable_debug() -> None:
global _DEBUG_FLAG
_DEBUG_FLAG = False


def is_debug_enabled() -> bool:
global _DEBUG_FLAG
return _DEBUG_FLAG
4 changes: 2 additions & 2 deletions tests/cli/common/test_cli_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def test_invoke_pipeline(script_runner: ScriptRunner) -> None:
assert "LoadPackageNotFound" in result.stderr
finally:
# reset debug flag so other tests may pass
from dlt.cli import _dlt
from dlt.cli import debug

_dlt.DEBUG_FLAG = False
debug.disable_debug()


def test_invoke_init_chess_and_template(script_runner: ScriptRunner) -> None:
Expand Down

0 comments on commit 8375e76

Please sign in to comment.