Skip to content

Commit df2065b

Browse files
committed
black format with 120 line length
Signed-off-by: Zen <[email protected]>
1 parent e7bc6a0 commit df2065b

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

src/zenlib/util/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
from .dict_check import contains, unset
12
from .handle_plural import handle_plural
3+
from .main_funcs import get_args_n_logger, get_kwargs, get_kwargs_from_args, init_argparser, init_logger, process_args
24
from .nodupflatlist import NoDupFlatList
35
from .pretty_print import pretty_print
46
from .replace_file_line import replace_file_line
5-
from .dict_check import contains, unset
6-
from .main_funcs import init_logger, process_args, init_argparser, get_args_n_logger, get_kwargs_from_args, get_kwargs
77

8-
__all__ = ['handle_plural', 'NoDupFlatList', 'pretty_print', 'replace_file_line',
9-
'init_logger', 'process_args',
10-
'init_argparser', 'get_args_n_logger', 'get_kwargs_from_args', 'get_kwargs',
11-
'contains', 'unset']
8+
__all__ = [
9+
"handle_plural",
10+
"NoDupFlatList",
11+
"pretty_print",
12+
"replace_file_line",
13+
"init_logger",
14+
"process_args",
15+
"init_argparser",
16+
"get_args_n_logger",
17+
"get_kwargs_from_args",
18+
"get_kwargs",
19+
"contains",
20+
"unset",
21+
]

src/zenlib/util/dict_check.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ def contains(key, message=None, is_set=True, raise_exception=False, log_level=10
1717
Returns the message/exception if the key is not found.
1818
If is_set is True, then the key must have a value.
1919
"""
20+
2021
def _dict_contains(func):
2122
@wraps(func)
2223
def _contains(*args, **kwargs):
2324
self = args[0]
2425
msg = f"[{func.__name__}] {message}" if message else None
2526
value = self.get(key)
2627
if key not in self:
27-
return return_check(self, msg or "[%s] Unable to find key: %s." % (func.__name__, key), raise_exception, log_level)
28+
return return_check(
29+
self, msg or "[%s] Unable to find key: %s." % (func.__name__, key), raise_exception, log_level
30+
)
2831
if is_set and (not value or repr(value) == "PosixPath('.')"):
29-
return return_check(self, msg or "[%s] Key is not set: %s." % (func.__name__, key), raise_exception, log_level)
32+
return return_check(
33+
self, msg or "[%s] Key is not set: %s." % (func.__name__, key), raise_exception, log_level
34+
)
3035
self.logger.log(debug_level, "[%s] Contains check passed for: %s" % (func.__name__, key))
3136
return func(*args, **kwargs)
37+
3238
return _contains
39+
3340
return _dict_contains
3441

3542

@@ -38,15 +45,23 @@ def unset(key, message=None, raise_exception=False, log_level=10, debug_level=5)
3845
Ensure that the key does not exist in the dictionary.
3946
If it exists, make sure it is not set.
4047
"""
48+
4149
def _dict_unset(func):
4250
@wraps(func)
4351
def _unset(*args, **kwargs):
4452
self = args[0]
4553
msg = f"[{func.__name__}] {message}" if message else None
4654
value = self.get(key)
4755
if key in self and (repr(value) != "PosixPath('.')" and value):
48-
return return_check(self, msg or "[%s] Key '%s' is set: %s." % (func.__name__, key, repr(value)), raise_exception, log_level)
56+
return return_check(
57+
self,
58+
msg or "[%s] Key '%s' is set: %s." % (func.__name__, key, repr(value)),
59+
raise_exception,
60+
log_level,
61+
)
4962
self.logger.log(debug_level, "[%s] Unset check passed for: %s; %s" % (func.__name__, key, repr(value)))
5063
return func(*args, **kwargs)
64+
5165
return _unset
66+
5267
return _dict_unset

src/zenlib/util/handle_plural.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def handle_plural(function, log_level=10):
1010
The last passed argument should be the iterable.
1111
Logs using the logger attribute if it exists.
1212
"""
13+
1314
def wrapper(self, *args):
1415
def log(msg, level=log_level):
1516
if hasattr(self, "logger"):
@@ -37,8 +38,18 @@ def log(msg, level=log_level):
3738
elif isinstance(focus_arg, dict):
3839
log("Expanding dict: %s" % focus_arg)
3940
for key, value in focus_arg.items():
40-
function(self, *(other_args + (key, value,)))
41+
function(
42+
self,
43+
*(
44+
other_args
45+
+ (
46+
key,
47+
value,
48+
)
49+
),
50+
)
4151
else:
4252
log(f"Arguments were not expanded: {args}", log_level - 5)
4353
return function(self, *args)
54+
4455
return wrapper

src/zenlib/util/nodupflatlist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44

55
from zenlib.logging import loggify
6+
67
from .handle_plural import handle_plural
78

89

910
@loggify
1011
class NoDupFlatList(list):
11-
""" List that automatically filters duplicate elements when appended and concatenated. """
12+
"""List that automatically filters duplicate elements when appended and concatenated."""
13+
1214
def __init__(self, no_warn=False, log_bump=0, *args, **kwargs):
1315
self.no_warn = no_warn
1416
self.logger.setLevel(self.logger.parent.level + log_bump)

src/zenlib/util/pretty_print.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def pretty_print(input_data, indent=0, prefix="", print_out=False):
2626
out += pretty_print(item, indent, prefix="+ ")
2727
elif hasattr(input_data, "name") and hasattr(input_data, "value"):
2828
# If the value is not iterable, it is a single value
29-
if not hasattr(input_data.value, "__getitem__") or isinstance(
30-
input_data.value, str
31-
):
29+
if not hasattr(input_data.value, "__getitem__") or isinstance(input_data.value, str):
3230
out += " " * indent + f"{prefix}{input_data.name}: {input_data.value}\n"
3331
else:
3432
out += (
@@ -37,9 +35,7 @@ def pretty_print(input_data, indent=0, prefix="", print_out=False):
3735
)
3836
elif isinstance(input_data, type):
3937
out += " " * indent + f"{prefix}<{input_data.__name__}>\n"
40-
elif not isinstance(input_data, str) and (
41-
hasattr(input_data, "__getitem__") or hasattr(input_data, "__iter__")
42-
):
38+
elif not isinstance(input_data, str) and (hasattr(input_data, "__getitem__") or hasattr(input_data, "__iter__")):
4339
for key in input_data:
4440
out += pretty_print(key, indent, prefix="+ ")
4541
else:

0 commit comments

Comments
 (0)