ominfra 0.0.0.dev425__py3-none-any.whl → 0.0.0.dev426__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,8 +112,10 @@ TomlParseFloat = ta.Callable[[str], ta.Any] # ta.TypeAlias
112
112
  TomlKey = ta.Tuple[str, ...] # ta.TypeAlias
113
113
  TomlPos = int # ta.TypeAlias
114
114
 
115
- # ../../omlish/lite/cached.py
115
+ # ../../omlish/lite/attrops.py
116
116
  T = ta.TypeVar('T')
117
+
118
+ # ../../omlish/lite/cached.py
117
119
  CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
118
120
 
119
121
  # ../../omlish/lite/check.py
@@ -1830,6 +1832,335 @@ class Abstract:
1830
1832
  update_abstracts(cls, force=True)
1831
1833
 
1832
1834
 
1835
+ ########################################
1836
+ # ../../../omlish/lite/attrops.py
1837
+ """
1838
+ TODO:
1839
+ - dotted paths!
1840
+ - per-attr repr transform / filter
1841
+ - __ne__ ? cases where it still matters
1842
+ - ordering ?
1843
+ """
1844
+
1845
+
1846
+ ##
1847
+
1848
+
1849
+ @ta.final
1850
+ class AttrOps(ta.Generic[T]):
1851
+ @ta.final
1852
+ class Attr:
1853
+ def __init__(
1854
+ self,
1855
+ name: str,
1856
+ *,
1857
+ display: ta.Optional[str] = None,
1858
+
1859
+ repr: bool = True, # noqa
1860
+ hash: bool = True, # noqa
1861
+ eq: bool = True,
1862
+ ) -> None:
1863
+ if '.' in name:
1864
+ raise NotImplementedError('Dotted paths not yet supported')
1865
+ if not name.isidentifier() or name.startswith('__'):
1866
+ raise AttributeError(f'Invalid attr: {name!r}')
1867
+ self._name = name
1868
+
1869
+ if display is None:
1870
+ display = name[1:] if name.startswith('_') and len(name) > 1 else name
1871
+ self._display = display
1872
+
1873
+ self._repr = repr
1874
+ self._hash = hash
1875
+ self._eq = eq
1876
+
1877
+ @classmethod
1878
+ def of(
1879
+ cls,
1880
+ o: ta.Union[
1881
+ str,
1882
+ ta.Tuple[str, str],
1883
+ 'AttrOps.Attr',
1884
+ ],
1885
+ ) -> 'AttrOps.Attr':
1886
+ if isinstance(o, AttrOps.Attr):
1887
+ return o
1888
+ elif isinstance(o, str):
1889
+ return cls(o)
1890
+ else:
1891
+ name, disp = o
1892
+ return cls(
1893
+ name,
1894
+ display=disp,
1895
+ )
1896
+
1897
+ @property
1898
+ def name(self) -> str:
1899
+ return self._name
1900
+
1901
+ @property
1902
+ def display(self) -> str:
1903
+ return self._display
1904
+
1905
+ @property
1906
+ def hash(self) -> bool:
1907
+ return self._hash
1908
+
1909
+ @property
1910
+ def eq(self) -> bool:
1911
+ return self._eq
1912
+
1913
+ @ta.overload
1914
+ def __init__(
1915
+ self,
1916
+ *attrs: ta.Sequence[ta.Union[
1917
+ str,
1918
+ ta.Tuple[str, str],
1919
+ Attr,
1920
+ ]],
1921
+ with_module: bool = False,
1922
+ use_qualname: bool = False,
1923
+ with_id: bool = False,
1924
+ repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = None,
1925
+ recursive: bool = False,
1926
+ subtypes_eq: bool = False,
1927
+ ) -> None:
1928
+ ...
1929
+
1930
+ @ta.overload
1931
+ def __init__(
1932
+ self,
1933
+ attrs_fn: ta.Callable[[T], ta.Tuple[ta.Union[
1934
+ ta.Any,
1935
+ ta.Tuple[str, ta.Any],
1936
+ Attr,
1937
+ ], ...]],
1938
+ /,
1939
+ *,
1940
+ with_module: bool = False,
1941
+ use_qualname: bool = False,
1942
+ with_id: bool = False,
1943
+ repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = None,
1944
+ recursive: bool = False,
1945
+ subtypes_eq: bool = False,
1946
+ ) -> None:
1947
+ ...
1948
+
1949
+ def __init__(
1950
+ self,
1951
+ *args,
1952
+ with_module=False,
1953
+ use_qualname=False,
1954
+ with_id=False,
1955
+ repr_filter=None,
1956
+ recursive=False,
1957
+ subtypes_eq=False,
1958
+ ) -> None:
1959
+ if args and len(args) == 1 and callable(args[0]):
1960
+ self._attrs: ta.Sequence[AttrOps.Attr] = self._capture_attrs(args[0])
1961
+ else:
1962
+ self._attrs = list(map(AttrOps.Attr.of, args))
1963
+
1964
+ self._with_module: bool = with_module
1965
+ self._use_qualname: bool = use_qualname
1966
+ self._with_id: bool = with_id
1967
+ self._repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = repr_filter
1968
+ self._recursive: bool = recursive
1969
+ self._subtypes_eq: bool = subtypes_eq
1970
+
1971
+ @property
1972
+ def attrs(self) -> ta.Sequence[Attr]:
1973
+ return self._attrs
1974
+
1975
+ #
1976
+
1977
+ @ta.final
1978
+ class _AttrCapturer:
1979
+ def __init__(self, fn):
1980
+ self.__fn = fn
1981
+
1982
+ def __getattr__(self, attr):
1983
+ return self.__fn(self, attr)
1984
+
1985
+ @classmethod
1986
+ def _capture_attrs(cls, fn: ta.Callable) -> ta.Sequence[Attr]:
1987
+ def access(parent, attr):
1988
+ dct[(ret := cls._AttrCapturer(access))] = (parent, attr)
1989
+ return ret
1990
+
1991
+ dct: dict = {}
1992
+ raw = fn(root := cls._AttrCapturer(access))
1993
+
1994
+ def rec(cap): # noqa
1995
+ if cap is root:
1996
+ return
1997
+ parent, attr = dct[cap]
1998
+ yield from rec(parent)
1999
+ yield attr
2000
+
2001
+ attrs: ta.List[AttrOps.Attr] = []
2002
+ for o in raw:
2003
+ if isinstance(o, AttrOps.Attr):
2004
+ attrs.append(o)
2005
+ continue
2006
+
2007
+ if isinstance(o, tuple):
2008
+ disp, cap, = o
2009
+ else:
2010
+ disp, cap = None, o
2011
+
2012
+ path = tuple(rec(cap))
2013
+
2014
+ attrs.append(AttrOps.Attr(
2015
+ '.'.join(path),
2016
+ display=disp,
2017
+ ))
2018
+
2019
+ return attrs
2020
+
2021
+ #
2022
+
2023
+ _repr: ta.Callable[[T], str]
2024
+
2025
+ @property
2026
+ def repr(self) -> ta.Callable[[T], str]:
2027
+ try:
2028
+ return self._repr
2029
+ except AttributeError:
2030
+ pass
2031
+
2032
+ def _repr(o: T) -> str:
2033
+ vs = ', '.join(
2034
+ f'{a._display}={v!r}' # noqa
2035
+ for a in self._attrs
2036
+ if a._repr # noqa
2037
+ for v in [getattr(o, a._name)] # noqa
2038
+ if self._repr_filter is None or self._repr_filter(v)
2039
+ )
2040
+
2041
+ return (
2042
+ f'{o.__class__.__module__ + "." if self._with_module else ""}'
2043
+ f'{o.__class__.__qualname__ if self._use_qualname else o.__class__.__name__}'
2044
+ f'{("@" + hex(id(o))[2:]) if self._with_id else ""}'
2045
+ f'({vs})'
2046
+ )
2047
+
2048
+ if self._recursive:
2049
+ _repr = self._reprlib().recursive_repr()(_repr)
2050
+
2051
+ self._repr = _repr
2052
+ return _repr
2053
+
2054
+ _reprlib_: ta.ClassVar[ta.Any]
2055
+
2056
+ @classmethod
2057
+ def _reprlib(cls) -> ta.Any:
2058
+ try:
2059
+ return cls._reprlib_
2060
+ except AttributeError:
2061
+ pass
2062
+
2063
+ import reprlib # noqa
2064
+
2065
+ cls._reprlib_ = reprlib
2066
+ return reprlib
2067
+
2068
+ #
2069
+
2070
+ _hash: ta.Callable[[T], int]
2071
+
2072
+ @property
2073
+ def hash(self) -> ta.Callable[[T], int]:
2074
+ try:
2075
+ return self._hash
2076
+ except AttributeError:
2077
+ pass
2078
+
2079
+ def _hash(o: T) -> int:
2080
+ return hash(tuple(
2081
+ getattr(o, a._name) # noqa
2082
+ for a in self._attrs
2083
+ if a._hash # noqa
2084
+ ))
2085
+
2086
+ self._hash = _hash
2087
+ return _hash
2088
+
2089
+ #
2090
+
2091
+ _eq: ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']]
2092
+
2093
+ @property
2094
+ def eq(self) -> ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']]:
2095
+ try:
2096
+ return self._eq
2097
+ except AttributeError:
2098
+ pass
2099
+
2100
+ def _eq(o: T, x: ta.Any) -> 'ta.Union[bool, types.NotImplementedType]':
2101
+ if self._subtypes_eq:
2102
+ if not isinstance(x, type(o)):
2103
+ return NotImplemented
2104
+ else:
2105
+ if type(x) is not type(o):
2106
+ return NotImplemented
2107
+
2108
+ return all(
2109
+ getattr(o, a._name) == getattr(x, a._name) # noqa
2110
+ for a in self._attrs
2111
+ if a._eq # noqa
2112
+ )
2113
+
2114
+ self._eq = _eq
2115
+ return _eq
2116
+
2117
+ #
2118
+
2119
+ @property
2120
+ def hash_eq(self) -> ta.Tuple[
2121
+ ta.Callable[[T], int],
2122
+ ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']],
2123
+ ]:
2124
+ return (self.hash, self.eq)
2125
+
2126
+ @property
2127
+ def repr_hash_eq(self) -> ta.Tuple[
2128
+ ta.Callable[[T], str],
2129
+ ta.Callable[[T], int],
2130
+ ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']],
2131
+ ]:
2132
+ return (self.repr, self.hash, self.eq)
2133
+
2134
+ #
2135
+
2136
+ def install(
2137
+ self,
2138
+ locals_dct: ta.MutableMapping[str, ta.Any],
2139
+ *,
2140
+ all: bool = False, # noqa
2141
+ repr: bool = False, # noqa
2142
+ hash: bool = False, # noqa
2143
+ eq: bool = False,
2144
+ ) -> 'AttrOps[T]':
2145
+ if repr or all:
2146
+ locals_dct.update(__repr__=self.repr)
2147
+ if hash or all:
2148
+ locals_dct.update(__hash__=self.hash)
2149
+ if eq or all:
2150
+ locals_dct.update(__eq__=self.eq)
2151
+ return self
2152
+
2153
+
2154
+ attr_ops = AttrOps[ta.Any]
2155
+
2156
+
2157
+ ##
2158
+
2159
+
2160
+ def attr_repr(obj: ta.Any, *attrs: str, **kwargs: ta.Any) -> str:
2161
+ return AttrOps(*attrs, **kwargs).repr(obj)
2162
+
2163
+
1833
2164
  ########################################
1834
2165
  # ../../../omlish/lite/cached.py
1835
2166
 
@@ -1848,7 +2179,7 @@ class _AbstractCachedNullary:
1848
2179
  def __call__(self, *args, **kwargs): # noqa
1849
2180
  raise TypeError
1850
2181
 
1851
- def __get__(self, instance, owner): # noqa
2182
+ def __get__(self, instance, owner=None): # noqa
1852
2183
  bound = instance.__dict__[self._fn.__name__] = self.__class__(self._fn.__get__(instance, owner))
1853
2184
  return bound
1854
2185
 
@@ -2409,13 +2740,6 @@ json_dump_compact: ta.Callable[..., None] = functools.partial(json.dump, **JSON_
2409
2740
  json_dumps_compact: ta.Callable[..., str] = functools.partial(json.dumps, **JSON_COMPACT_KWARGS)
2410
2741
 
2411
2742
 
2412
- ########################################
2413
- # ../../../omlish/lite/logs.py
2414
-
2415
-
2416
- log = logging.getLogger(__name__)
2417
-
2418
-
2419
2743
  ########################################
2420
2744
  # ../../../omlish/lite/objects.py
2421
2745
 
@@ -2661,13 +2985,6 @@ def split_keep_delimiter(s, d):
2661
2985
  ##
2662
2986
 
2663
2987
 
2664
- def attr_repr(obj: ta.Any, *attrs: str) -> str:
2665
- return f'{type(obj).__name__}({", ".join(f"{attr}={getattr(obj, attr)!r}" for attr in attrs)})'
2666
-
2667
-
2668
- ##
2669
-
2670
-
2671
2988
  FORMAT_NUM_BYTES_SUFFIXES: ta.Sequence[str] = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']
2672
2989
 
2673
2990
 
@@ -2741,6 +3058,17 @@ def typing_annotations_attr() -> str:
2741
3058
  return _TYPING_ANNOTATIONS_ATTR
2742
3059
 
2743
3060
 
3061
+ ########################################
3062
+ # ../../../omlish/logs/modules.py
3063
+
3064
+
3065
+ ##
3066
+
3067
+
3068
+ def get_module_logger(mod_globals: ta.Mapping[str, ta.Any]) -> logging.Logger:
3069
+ return logging.getLogger(mod_globals.get('__name__'))
3070
+
3071
+
2744
3072
  ########################################
2745
3073
  # ../../../omlish/logs/std/filters.py
2746
3074
 
@@ -5643,6 +5971,7 @@ class _Maybe(Maybe[T], Abstract):
5643
5971
  return op and not sp
5644
5972
 
5645
5973
 
5974
+ @ta.final
5646
5975
  class _JustMaybe(_Maybe[T]):
5647
5976
  __slots__ = ('_v', '_hash')
5648
5977
 
@@ -5680,6 +6009,7 @@ class _JustMaybe(_Maybe[T]):
5680
6009
  )
5681
6010
 
5682
6011
 
6012
+ @ta.final
5683
6013
  class _EmptyMaybe(_Maybe[T]):
5684
6014
  __slots__ = ()
5685
6015
 
@@ -8640,6 +8970,9 @@ class Dispatchers(KeyedCollection[Fd, FdioHandler]):
8640
8970
  # ../dispatchersimpl.py
8641
8971
 
8642
8972
 
8973
+ log = get_module_logger(globals()) # noqa
8974
+
8975
+
8643
8976
  ##
8644
8977
 
8645
8978
 
@@ -9067,6 +9400,9 @@ class PidHistory(ta.Dict[Pid, Process]):
9067
9400
  # ../setupimpl.py
9068
9401
 
9069
9402
 
9403
+ log = get_module_logger(globals()) # noqa
9404
+
9405
+
9070
9406
  ##
9071
9407
 
9072
9408
 
@@ -9541,6 +9877,9 @@ class ProcessGroupManager(
9541
9877
  # ../io.py
9542
9878
 
9543
9879
 
9880
+ log = get_module_logger(globals()) # noqa
9881
+
9882
+
9544
9883
  ##
9545
9884
 
9546
9885
 
@@ -9789,6 +10128,9 @@ class ProcessSpawningFactory(Func1[Process, ProcessSpawning]):
9789
10128
  pass
9790
10129
 
9791
10130
 
10131
+ log = get_module_logger(globals()) # noqa
10132
+
10133
+
9792
10134
  ##
9793
10135
 
9794
10136
 
@@ -10265,6 +10607,9 @@ class ProcessImpl(Process):
10265
10607
  # ../signals.py
10266
10608
 
10267
10609
 
10610
+ log = get_module_logger(globals()) # noqa
10611
+
10612
+
10268
10613
  ##
10269
10614
 
10270
10615
 
@@ -10637,6 +10982,9 @@ def check_execv_args(
10637
10982
  # ../supervisor.py
10638
10983
 
10639
10984
 
10985
+ log = get_module_logger(globals()) # noqa
10986
+
10987
+
10640
10988
  ##
10641
10989
 
10642
10990
 
@@ -5,7 +5,7 @@ import os
5
5
  import typing as ta
6
6
 
7
7
  from omlish.lite.abstract import Abstract
8
- from omlish.lite.logs import log
8
+ from omlish.logs.modules import get_module_logger
9
9
 
10
10
  from .configs import ProcessConfig
11
11
  from .configs import ServerConfig
@@ -26,6 +26,9 @@ from .utils.strings import find_prefix_at_end
26
26
  from .utils.strings import strip_escapes
27
27
 
28
28
 
29
+ log = get_module_logger(globals()) # noqa
30
+
31
+
29
32
  ##
30
33
 
31
34
 
ominfra/supervisor/io.py CHANGED
@@ -2,7 +2,7 @@
2
2
  import typing as ta
3
3
 
4
4
  from omlish.io.fdio.pollers import FdioPoller
5
- from omlish.lite.logs import log
5
+ from omlish.logs.modules import get_module_logger
6
6
 
7
7
  from .dispatchers import Dispatchers
8
8
  from .types import ExitNow
@@ -10,6 +10,9 @@ from .types import HasDispatchers
10
10
  from .utils.ostypes import Fd
11
11
 
12
12
 
13
+ log = get_module_logger(globals()) # noqa
14
+
15
+
13
16
  ##
14
17
 
15
18
 
@@ -7,8 +7,8 @@ import traceback
7
7
  import typing as ta
8
8
 
9
9
  from omlish.lite.check import check
10
- from omlish.lite.logs import log
11
10
  from omlish.lite.typing import Func1
11
+ from omlish.logs.modules import get_module_logger
12
12
 
13
13
  from .configs import ProcessConfig
14
14
  from .configs import RestartUnconditionally
@@ -36,6 +36,9 @@ class ProcessSpawningFactory(Func1[Process, ProcessSpawning]):
36
36
  pass
37
37
 
38
38
 
39
+ log = get_module_logger(globals()) # noqa
40
+
41
+
39
42
  ##
40
43
 
41
44
 
@@ -6,7 +6,7 @@ import typing as ta
6
6
  import warnings
7
7
 
8
8
  from omlish.lite.cached import cached_nullary
9
- from omlish.lite.logs import log
9
+ from omlish.logs.modules import get_module_logger
10
10
 
11
11
  from .configs import ServerConfig
12
12
  from .privileges import drop_privileges
@@ -19,6 +19,9 @@ from .utils.os import real_exit
19
19
  from .utils.ostypes import Rc
20
20
 
21
21
 
22
+ log = get_module_logger(globals()) # noqa
23
+
24
+
22
25
  ##
23
26
 
24
27
 
@@ -1,7 +1,7 @@
1
1
  # ruff: noqa: UP006 UP007 UP045
2
2
  import signal
3
3
 
4
- from omlish.lite.logs import log
4
+ from omlish.logs.modules import get_module_logger
5
5
 
6
6
  from .groups import ProcessGroupManager
7
7
  from .states import SupervisorState
@@ -11,6 +11,9 @@ from .utils.signals import SignalReceiver
11
11
  from .utils.signals import sig_name
12
12
 
13
13
 
14
+ log = get_module_logger(globals()) # noqa
15
+
16
+
14
17
  ##
15
18
 
16
19
 
@@ -4,8 +4,8 @@ import typing as ta
4
4
 
5
5
  from omlish.io.fdio.pollers import FdioPoller
6
6
  from omlish.lite.check import check
7
- from omlish.lite.logs import log
8
7
  from omlish.lite.typing import Func1
8
+ from omlish.logs.modules import get_module_logger
9
9
 
10
10
  from .configs import ProcessGroupConfig
11
11
  from .configs import ServerConfig
@@ -27,6 +27,9 @@ from .utils.os import decode_wait_status
27
27
  from .utils.os import waitpid
28
28
 
29
29
 
30
+ log = get_module_logger(globals()) # noqa
31
+
32
+
30
33
  ##
31
34
 
32
35
 
ominfra/threadworkers.py CHANGED
@@ -18,13 +18,16 @@ import typing as ta
18
18
 
19
19
  from omlish.lite.abstract import Abstract
20
20
  from omlish.lite.contextmanagers import ExitStacked
21
- from omlish.lite.logs import log
21
+ from omlish.logs.modules import get_module_logger
22
22
 
23
23
 
24
24
  T = ta.TypeVar('T')
25
25
  ThreadWorkerT = ta.TypeVar('ThreadWorkerT', bound='ThreadWorker')
26
26
 
27
27
 
28
+ log = get_module_logger(globals()) # noqa
29
+
30
+
28
31
  ##
29
32
 
30
33
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ominfra
3
- Version: 0.0.0.dev425
3
+ Version: 0.0.0.dev426
4
4
  Summary: ominfra
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: >=3.13
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: omdev==0.0.0.dev425
18
- Requires-Dist: omlish==0.0.0.dev425
17
+ Requires-Dist: omdev==0.0.0.dev426
18
+ Requires-Dist: omlish==0.0.0.dev426
19
19
  Provides-Extra: all
20
20
  Requires-Dist: paramiko~=4.0; extra == "all"
21
21
  Requires-Dist: asyncssh~=2.21; extra == "all"