Skip to content

Commit f444af9

Browse files
committed
Added --debug mode
1 parent f8db075 commit f444af9

7 files changed

Lines changed: 25 additions & 2 deletions

File tree

remove-json-keys/noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_help(session) : session.run('py', '-m', pkg.name, '--help', *session.po
2323
@session
2424
def test_build(session) : session.run('pip', 'install', '-e', '.') ; session.run(pkg.dir, *session.posargs)
2525

26+
@session
27+
def debug(session) : session.run('py', '-m', pkg.name, '--debug', *session.posargs, env={ 'PYTHONPATH': 'src' })
28+
2629
@session
2730
def bump_patch(session) : session.run('py', 'utils/bump.py', '--patch', *session.posargs)
2831
@session

remove-json-keys/src/remove_json_keys/lib/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919

2020
def data(msg, *args, **kwargs) : print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}')
21+
def debug(msg, *args, **kwargs) : print(f'\n{colors.by}DEBUG: {msg.format(*args, **kwargs)}{colors.nc}')
2122
def dim(msg, *args, **kwargs) : print(f'\n{colors.gry}{msg.format(*args, **kwargs)}{colors.nc}')
2223
def error(msg, *args, **kwargs) : print(f'\n{colors.br}ERROR: {msg.format(*args, **kwargs)}{colors.nc}')
2324
def info(msg, *args, end='', **kwargs) : print(f'\n{colors.by}{msg.format(*args, **kwargs)}{colors.nc}', end=end)

remove-json-keys/src/remove_json_keys/lib/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from types import SimpleNamespace as sn
44

5-
from . import data
5+
from . import data, log
66

77
controls = sn(
88
json_dir=sn(
@@ -28,6 +28,10 @@
2828
help=sn(
2929
args=['-h', '--help'],
3030
action='help', help='Show help screen'
31+
),
32+
debug=sn(
33+
args=['--debug'],
34+
action='store_true', help='Show debug logs'
3135
)
3236
)
3337

@@ -49,6 +53,7 @@ def load(cli, caller_file):
4953
cli.config = data.sns.from_dict(data.json.read(cli.config_filepath))
5054
cli.config_filename = filename
5155
break
56+
log.debug(f'Config file loaded!\n{log.colors.gry}{cli.config}' if cli.config_filepath else 'No config file found.')
5257

5358
# Parse CLI args
5459
argp = argparse.ArgumentParser(description=cli.description, add_help=False)
@@ -65,6 +70,7 @@ def load(cli, caller_file):
6570
for key, val in vars(parsed_args).items(): # apply parsed_args to cli.config
6671
if not getattr(cli.config, key, ''):
6772
setattr(cli.config, key, val)
73+
log.debug(f'Args parsed!\n{log.colors.gry}{cli.config}')
6874

6975
# Init all cli.config vals
7076
for name, ctrl in vars(controls).items():
@@ -74,3 +80,4 @@ def load(cli, caller_file):
7480
if val is None and hasattr(ctrl, 'default_val'):
7581
val = ctrl.default_val
7682
setattr(cli.config, name, val)
83+
log.debug(f'All cli.config vals set!\n{log.colors.gry}{cli.config}')

translate-messages/noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_help(session) : session.run('py', '-m', pkg.name, '--help', *session.po
2323
@session
2424
def test_build(session) : session.run('pip', 'install', '-e', '.') ; session.run(pkg.dir, *session.posargs)
2525

26+
@session
27+
def debug(session) : session.run('py', '-m', pkg.name, '--debug', *session.posargs, env={ 'PYTHONPATH': 'src' })
28+
2629
@session
2730
def bump_patch(session) : session.run('py', 'utils/bump.py', '--patch', *session.posargs)
2831
@session

translate-messages/src/translate_messages/lib/init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ def target_langs(cli):
5959
cli.config.target_langs.sort()
6060
if cli.config.exclude_langs:
6161
cli.config.target_langs = [lang for lang in cli.config.target_langs if lang not in cli.config.exclude_langs]
62+
log.debug(f"cli.config.target_langs init'd!\n{log.colors.gry}{cli.config.target_langs}")

translate-messages/src/translate_messages/lib/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919

2020
def data(msg, *args, **kwargs) : print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}')
21+
def debug(msg, *args, **kwargs) : print(f'\n{colors.by}DEBUG: {msg.format(*args, **kwargs)}{colors.nc}')
2122
def dim(msg, *args, **kwargs) : print(f'\n{colors.gry}{msg.format(*args, **kwargs)}{colors.nc}')
2223
def error(msg, *args, **kwargs) : print(f'\n{colors.br}ERROR: {msg.format(*args, **kwargs)}{colors.nc}')
2324
def info(msg, *args, end='', **kwargs) : print(f'\n{colors.by}{msg.format(*args, **kwargs)}{colors.nc}', end=end)

translate-messages/src/translate_messages/lib/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from types import SimpleNamespace as sn
44

5-
from . import data
5+
from . import data, log
66

77
controls = sn(
88
locales_dir=sn(
@@ -44,6 +44,10 @@
4444
help=sn(
4545
args=['-h', '--help'],
4646
action='help', help='Show help screen'
47+
),
48+
debug=sn(
49+
args=['--debug'],
50+
action='store_true', help='Show debug logs'
4751
)
4852
)
4953

@@ -65,6 +69,7 @@ def load(cli, caller_file):
6569
cli.config = data.sns.from_dict(data.json.read(cli.config_filepath))
6670
cli.config_filename = filename
6771
break
72+
log.debug(f'Config file loaded!\n{log.colors.gry}{cli.config}' if cli.config_filepath else 'No config file found.')
6873

6974
# Parse CLI args
7075
argp = argparse.ArgumentParser(description=cli.description, add_help=False)
@@ -81,6 +86,7 @@ def load(cli, caller_file):
8186
for key, val in vars(parsed_args).items(): # apply parsed_args to cli.config
8287
if not getattr(cli.config, key, ''):
8388
setattr(cli.config, key, val)
89+
log.debug(f'Args parsed!\n{log.colors.gry}{cli.config}')
8490

8591
# Init all cli.config vals
8692
for name, ctrl in vars(controls).items():
@@ -90,3 +96,4 @@ def load(cli, caller_file):
9096
if val is None and hasattr(ctrl, 'default_val'):
9197
val = ctrl.default_val
9298
setattr(cli.config, name, val)
99+
log.debug(f'All cli.config vals set!\n{log.colors.gry}{cli.config}')

0 commit comments

Comments
 (0)