Skip to content

Commit e198918

Browse files
committed
Added missing lib/env.py + import + log.debug()
1 parent e1f2bcf commit e198918

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

project-markers/utils/lib/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
3+
def is_debug_mode() -> bool:
4+
return any(arg in ('--debug', '-V') for arg in sys.argv[1:])

project-markers/utils/lib/log.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import os, sys
22
from types import SimpleNamespace as sn
3+
from typing import Optional
34
if sys.platform == 'win32' : import colorama ; colorama.init() # enable ANSI color support
45

6+
from . import env
7+
58
try : terminal_width = os.get_terminal_size()[0]
69
except OSError : terminal_width = 80
710

@@ -29,6 +32,27 @@ def success(msg: str, *args, **kwargs) -> None : print(f'\n{colors.bg}{msg.forma
2932
def tip(msg: str, *args, **kwargs) -> None : print(f'\n{colors.bc}TIP: {msg.format(*args, **kwargs)}{colors.nc}')
3033
def warn(msg: str, *args, **kwargs) -> None : print(f'\n{colors.bo}WARNING: {msg.format(*args, **kwargs)}{colors.nc}')
3134

35+
def debug(msg: str, cli: Optional[sn] = None, *args, **kwargs) -> None:
36+
if not env.is_debug_mode() : return
37+
38+
# Init --debug [target]
39+
debug_key=None
40+
debug_argidx = sys.argv.index('--debug') if '--debug' in sys.argv else sys.argv.index('-V')
41+
if debug_argidx +1 < len(sys.argv) and not sys.argv[debug_argidx +1].startswith('-'):
42+
debug_key = sys.argv[debug_argidx +1].replace('-', '_')
43+
44+
if cli: # init data line
45+
if debug_key:
46+
data_val = getattr(cli.config, debug_key, f'cli.config key {debug_key!r} {cli.msgs.warn_NOT_FOUND.lower()}')
47+
else:
48+
data_val = cli.config
49+
msg += f'\n{colors.gry}{data_val}{colors.nc}'
50+
51+
if args: # use 'em
52+
msg = msg.format(*args, **kwargs)
53+
54+
print(f'\n{colors.by}DEBUG: {msg}{colors.nc}')
55+
3256
def trunc(msg: str, end: str = '\n') -> None:
3357
truncated_lines = [
3458
line if len(line) < terminal_width else line[:terminal_width -4] + '...' for line in msg.splitlines()]

0 commit comments

Comments
 (0)