Skip to content

Commit

Permalink
feat: get rid of internal python paths (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Nov 23, 2024
1 parent 78a644c commit 52b277a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions a_sync/primitives/_debug.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cdef class _LoopBoundMixin(_LoggerMixin):
cdef class _DebugDaemonMixin(_LoopBoundMixin):
cdef object _daemon
cdef object _c_ensure_debug_daemon(self, tuple[object] args, dict[str, object] kwargs)
cdef object _c_start_debug_daemon(self, tuple[object] args, dict[str, object] kwargs)
5 changes: 4 additions & 1 deletion a_sync/primitives/_debug.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ cdef class _DebugDaemonMixin(_LoopBoundMixin):
See Also:
:meth:`_ensure_debug_daemon` for ensuring the daemon is running.
"""
return self._c_start_debug_daemon(args, kwargs)

cdef object _c_start_debug_daemon(self, tuple[object] args, dict[str, object] kwargs):
cdef object loop = self._c_get_loop()
if self.check_debug_logs_enabled() and loop.is_running():
return ccreate_task_simple(self._debug_daemon(*args, **kwargs))
Expand Down Expand Up @@ -159,7 +162,7 @@ cdef class _DebugDaemonMixin(_LoopBoundMixin):
cdef object daemon = self._daemon
if daemon is None:
if self.check_debug_logs_enabled():
self._daemon = self._start_debug_daemon(*args, **kwargs)
self._daemon = self._c_start_debug_daemon(args, kwargs)
self._daemon.add_done_callback(self._stop_debug_daemon)
else:
self._daemon = self._c_get_loop().create_future()
Expand Down
25 changes: 19 additions & 6 deletions a_sync/primitives/_loggable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ cdef class _LoggerMixin:
return self.get_logger()
cdef object get_logger(self):
cdef str logger_id
cdef object logger, cls
cdef str cls_key, name
logger = self._logger
if not logger:
if logger is None:
cls = type(self)
logger_id = "{}.{}".format(cls.__module__, cls.__qualname__)
if hasattr(self, "_name") and self._name:
logger_id += ".{}".format(self._name)
logger = getLogger(logger_id)
name = getattr(self, "_name", "")
if name:
logger = getLogger(f"{cls.__module__}.{cls.__qualname__}.{name}")
else:
logger = _get_logger_for_cls(f"{cls.__module__}.{cls.__qualname__}")
self._logger = logger
return logger
@property
Expand All @@ -81,3 +83,14 @@ cdef class _LoggerMixin:
cdef bint check_debug_logs_enabled(self):
return self.get_logger().isEnabledFor(DEBUG)
cdef dict[str, object] _class_loggers = {}
cdef object _get_logger_for_cls(str cls_key):
cdef object logger = _class_loggers.get(cls_key)
if logger is None:
logger = getLogger(cls_key)
_class_loggers[cls_key] = logger
return logger

0 comments on commit 52b277a

Please sign in to comment.