Skip to content

Commit

Permalink
debug: Emit log lines for calls to capture_output() and exec_or_return()
Browse files Browse the repository at this point in the history
Invocations of these two workhorses of the codebase are often useful to
see during debugging and development.

Debug logging is still very primitive in this codebase.

Related-to: <#201>
  • Loading branch information
tsibley committed May 25, 2023
1 parent 9c4c65b commit c0ee999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nextstrain/cli/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
parent exceptions in an exception chain are omitted from handled errors.
"""
from os import environ
from sys import stderr

DEBUGGING = bool(environ.get("NEXTSTRAIN_DEBUG"))

if DEBUGGING:
def debug(*args):
print("DEBUG:", *args, file = stderr)
else:
def debug(*args):
pass
5 changes: 5 additions & 0 deletions nextstrain/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from textwrap import dedent, indent
from wcmatch.glob import globmatch, GLOBSTAR, EXTGLOB, BRACE, MATCHBASE, NEGATE
from .__version__ import __version__
from .debug import debug
from .types import RunnerModule, RunnerTestResults


Expand Down Expand Up @@ -276,6 +277,8 @@ def capture_output(argv, extra_env: Mapping = {}):
If an *extra_env* mapping is passed, the provided keys and values are
overlayed onto the current environment.
"""
debug(f"capture_output({argv!r}, {extra_env!r})")

env = os.environ.copy()

if extra_env:
Expand Down Expand Up @@ -308,6 +311,8 @@ def exec_or_return(argv: List[str], extra_env: Mapping = {}) -> int:
¹ https://bugs.python.org/issue9148
"""
debug(f"exec_or_return({argv!r}, {extra_env!r})")

env = os.environ.copy()

if extra_env:
Expand Down

0 comments on commit c0ee999

Please sign in to comment.