Skip to content

Commit 5cdc8e9

Browse files
authored
Merge pull request #3 from desultory/dev
3.0, remove threading, add "types" modue
2 parents 8cbfa63 + b4974c9 commit 5cdc8e9

18 files changed

+126
-248
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zenlib"
7-
version = "2.4.1"
7+
version = "3.0.0"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

readme.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,3 @@ If `key` is a dict, the structure will be used to walk the `validate_dict`.
142142
* `message` Set the vailidation failure message.
143143

144144
Additional arguments exist to set a value to compare found keys against
145-
146-
## Threading
147-
148-
> This is not being maintained, please don't use it, it's just here because I used to use it.
149-
150-
### ZenThread
151-
152-
An extension of the builtin thread that sets results to self.return_value and exceptions to self.exception.
153-
154-
Supports re-starting and looping with the self.loop event.
155-
156-
### @threaded
157-
158-
Runs the wrapped function in a thread when called.
159-
160-
Adds the thread to `_threads` within the object.
161-
162-
If an exception is raised, it will be added to `self._threads` in the form `(thread, exception_queue)`.
163-
164-
### @thread_wrapped('threadname')
165-
166-
Meant to be used with `@add_thread`, the argument is the threadname that function is associated with.
167-
168-
### @add_thread('threadname', 'target_function', 'description')
169-
170-
`@add_thread` decorates a class, and adds `create_{threadname}_thread`, `start_` and `stop_` functions which are used to handle thread management of a `thread_wrapped` function.
171-
172-
Once added, a thread will be added to `self.threads[threadname]`.
173-
174-

src/zenlib/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from .logging import ColorLognameFormatter, loggify
2-
from .util import NoDupFlatList, check_dict, handle_plural, pretty_print, replace_file_line, update_init, walk_dict
2+
from .types import NoDupFlatList, validatedDataclass
3+
from .util import check_dict, handle_plural, pretty_print, replace_file_line, update_init, walk_dict
34

45
__all__ = [
56
"ColorLognameFormatter",
67
"loggify",
78
"handle_plural",
89
"NoDupFlatList",
10+
"validatedDataclass",
911
"pretty_print",
1012
"replace_file_line",
1113
"update_init",

src/zenlib/logging/classlogger.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = "desultory"
2-
__version__ = "2.1.0"
2+
__version__ = "2.2.0"
33

4-
from .utils import add_handler_if_not_exists, log_init, log_setattr
4+
from .utils import add_handler_if_not_exists, log_init, handle_additional_logging
55

66
from logging import Logger, getLogger
77

@@ -21,14 +21,8 @@ def __init__(self, *args, **kwargs):
2121
# Log class init if _log_init is passed
2222
log_init(self, args, kwargs)
2323

24-
# add setattr logging
25-
setattr(self, "__setattr__", log_setattr)
24+
# Add logging to _log_setattr if set
25+
handle_additional_logging(self, kwargs)
2626

2727
if super().__class__.__class__ is not type:
2828
super().__init__(*args, **kwargs)
29-
30-
def __setitem__(self, name, value):
31-
""" Add logging to dict setitem. """
32-
if hasattr(super(), '__setitem__'):
33-
super().__setitem__(name, value)
34-
self.logger.log(5, "Setitem '%s' to: %s" % (name, value))

src/zenlib/logging/loggify.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
__author__ = "desultory"
2-
__version__ = "2.4.0"
3-
4-
from .utils import add_handler_if_not_exists, log_init, log_setattr
2+
__version__ = "2.4.2"
53

64
from logging import Logger, getLogger
75

6+
from zenlib.util import merge_class
7+
8+
from .utils import add_handler_if_not_exists, log_init, handle_additional_logging
9+
810

911
def loggify(cls):
1012
class ClassLogger(cls):
1113
def __init__(self, *args, **kwargs):
1214
# Get the parent logger from the root if one was not passed
13-
parent_logger = kwargs.pop('logger') if isinstance(kwargs.get('logger'), Logger) else getLogger()
15+
parent_logger = kwargs.pop("logger") if isinstance(kwargs.get("logger"), Logger) else getLogger()
1416
# Get a child logger from the parent logger, set self.logger
1517
self.logger = parent_logger.getChild(cls.__name__)
1618
# Bump the log level if _log_bump is passed
17-
self.logger.setLevel(self.logger.parent.level + kwargs.pop('_log_bump', 0))
19+
self.logger.setLevel(self.logger.parent.level + kwargs.pop("_log_bump", 0))
1820

1921
# Add a colored stream handler if one does not exist
2022
add_handler_if_not_exists(self.logger)
2123

2224
# Log class init if _log_init is passed
2325
log_init(self, args, kwargs)
2426

25-
# Add setattr logging
26-
setattr(self, "__setattr__", log_setattr)
27+
# Add logging to _log_setattr if set
28+
handle_additional_logging(self, kwargs)
2729

2830
super().__init__(*args, **kwargs)
2931

30-
ClassLogger.__name__ = cls.__name__
31-
ClassLogger.__module__ = cls.__module__
32-
ClassLogger.__doc__ = cls.__doc__
33-
ClassLogger.__qualname__ = cls.__qualname__
32+
merge_class(cls, ClassLogger, ignored_attributes=["__setattr__"])
3433
return ClassLogger

src/zenlib/logging/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def log_init(self, args, kwargs):
2525
class_name = self.__class__.__name__
2626
logger = self.logger
2727
if not kwargs.pop("_log_init", False):
28-
return logger.debug("Init logging disabled for class: %s", class_name)
28+
return logger.log(5, "Init logging disabled for class: %s", class_name)
2929

3030
logger.info("Initializing class: %s", class_name)
3131

@@ -49,6 +49,11 @@ def log_init(self, args, kwargs):
4949
if class_version := getattr(self, '__version__', None):
5050
logger.info("[%s] Class version: %s" % (class_name, class_version))
5151

52+
def handle_additional_logging(self, kwargs):
53+
""" Sets __setattr__ to log_setattr if _log_setattr is in the kwargs and set to True """
54+
if kwargs.pop("_log_setattr", False):
55+
setattr(self, "__setattr__", log_setattr)
56+
5257
def log_setattr(self, name, value):
5358
""" Logs when an attribute is set """
5459
super().__setattr__(name, value)

src/zenlib/threading/__init__.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/zenlib/threading/add_thread.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/zenlib/threading/loop_thread.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/zenlib/threading/threaded.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)