ominfra 0.0.0.dev425__py3-none-any.whl → 0.0.0.dev427__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.
@@ -2,7 +2,10 @@
2
2
  import os.path
3
3
  import typing as ta
4
4
 
5
- from omlish.lite.logs import log
5
+ from omlish.logs.modules import get_module_logger
6
+
7
+
8
+ log = get_module_logger(globals()) # noqa
6
9
 
7
10
 
8
11
  ##
@@ -40,8 +40,8 @@ import typing as ta
40
40
  from omlish.lite.cached import cached_nullary
41
41
  from omlish.lite.check import check
42
42
  from omlish.lite.contextmanagers import ExitStacked
43
- from omlish.lite.logs import log
44
43
  from omlish.lite.runtime import is_debugger_attached
44
+ from omlish.logs.modules import get_module_logger
45
45
  from omlish.os.pidfiles.pidfile import Pidfile
46
46
 
47
47
  from ....journald.messages import JournalctlMessage # noqa
@@ -53,6 +53,9 @@ from .cursor import JournalctlToAwsCursor
53
53
  from .poster import JournalctlToAwsPosterWorker
54
54
 
55
55
 
56
+ log = get_module_logger(globals()) # noqa
57
+
58
+
56
59
  ##
57
60
 
58
61
 
@@ -9,7 +9,7 @@ import time
9
9
  import typing as ta
10
10
  import urllib.request
11
11
 
12
- from omlish.lite.logs import log
12
+ from omlish.logs.modules import get_module_logger
13
13
 
14
14
  from ....journald.messages import JournalctlMessage # noqa
15
15
  from ....threadworkers import ThreadWorker
@@ -18,6 +18,9 @@ from ..logs import AwsPutLogEventsResponse
18
18
  from .cursor import JournalctlToAwsCursor
19
19
 
20
20
 
21
+ log = get_module_logger(globals()) # noqa
22
+
23
+
21
24
  ##
22
25
 
23
26
 
@@ -6,7 +6,10 @@ import typing as ta
6
6
 
7
7
  from omlish.io.buffers import DelimitingBuffer
8
8
  from omlish.lite.check import check
9
- from omlish.lite.logs import log
9
+ from omlish.logs.modules import get_module_logger
10
+
11
+
12
+ log = get_module_logger(globals()) # noqa
10
13
 
11
14
 
12
15
  ##
@@ -409,7 +409,7 @@ import typing as ta
409
409
 
410
410
  from omlish.lite.cached import cached_nullary
411
411
  from omlish.lite.check import check
412
- from omlish.lite.logs import log
412
+ from omlish.logs.modules import get_module_logger
413
413
  from omlish.subprocesses.utils import subprocess_close
414
414
  from omlish.subprocesses.wrap import subprocess_shell_wrap_exec
415
415
 
@@ -418,6 +418,9 @@ from .messages import JournalctlMessage # noqa
418
418
  from .messages import JournalctlMessageBuilder
419
419
 
420
420
 
421
+ log = get_module_logger(globals()) # noqa
422
+
423
+
421
424
  ##
422
425
 
423
426
 
@@ -1,7 +1,7 @@
1
1
  # ruff: noqa: UP006 UP007 UP045
2
2
  import dataclasses as dc
3
3
 
4
- from omlish.lite.logs import log
4
+ from omlish.logs.modules import get_module_logger
5
5
 
6
6
  from ..commands.base import Command
7
7
  from ..commands.base import CommandExecutor
@@ -9,6 +9,9 @@ from .deploy import DeployDriverFactory
9
9
  from .specs import DeploySpec
10
10
 
11
11
 
12
+ log = get_module_logger(globals()) # noqa
13
+
14
+
12
15
  ##
13
16
 
14
17
 
ominfra/manage/main.py CHANGED
@@ -18,10 +18,10 @@ from omlish.argparse.cli import argparse_cmd
18
18
  from omlish.lite.cached import cached_nullary
19
19
  from omlish.lite.check import check
20
20
  from omlish.lite.configs import load_config_file_obj
21
- from omlish.lite.logs import log # noqa
22
21
  from omlish.lite.marshal import ObjMarshalerManager
23
22
  from omlish.lite.marshal import ObjMarshalOptions
24
23
  from omlish.lite.pycharm import PycharmRemoteDebug
24
+ from omlish.logs.modules import get_module_logger
25
25
 
26
26
  from .bootstrap import MainBootstrap
27
27
  from .bootstrap_ import main_bootstrap
@@ -33,6 +33,9 @@ from .targets.connection import ManageTargetConnector
33
33
  from .targets.targets import ManageTarget
34
34
 
35
35
 
36
+ log = get_module_logger(globals()) # noqa
37
+
38
+
36
39
  ##
37
40
 
38
41
 
@@ -13,9 +13,9 @@ from omlish.asyncs.asyncio.streams import asyncio_open_stream_writer
13
13
  from omlish.lite.cached import cached_nullary
14
14
  from omlish.lite.check import check
15
15
  from omlish.lite.inject import Injector
16
- from omlish.lite.logs import log
17
16
  from omlish.lite.marshal import ObjMarshalerManager
18
17
  from omlish.lite.pycharm import pycharm_debug_connect
18
+ from omlish.logs.modules import get_module_logger
19
19
  from omlish.os.deathsig import set_process_deathsig
20
20
 
21
21
  from ...pyremote import pyremote_bootstrap_finalize
@@ -33,6 +33,9 @@ else:
33
33
  main_bootstrap: ta.Any = None
34
34
 
35
35
 
36
+ log = get_module_logger(globals()) # noqa
37
+
38
+
36
39
  ##
37
40
 
38
41
 
@@ -12,7 +12,7 @@ import typing as ta
12
12
 
13
13
  from omlish.lite.abstract import Abstract
14
14
  from omlish.lite.check import check
15
- from omlish.lite.logs import log
15
+ from omlish.logs.modules import get_module_logger
16
16
 
17
17
  from ..commands.base import Command
18
18
  from ..commands.base import CommandException
@@ -25,6 +25,9 @@ from .channel import RemoteChannel
25
25
  T = ta.TypeVar('T')
26
26
 
27
27
 
28
+ log = get_module_logger(globals()) # noqa
29
+
30
+
28
31
  ##
29
32
 
30
33
 
@@ -3,7 +3,7 @@ import dataclasses as dc
3
3
  import typing as ta
4
4
 
5
5
  from omlish.lite.check import check
6
- from omlish.lite.logs import log
6
+ from omlish.logs.modules import get_module_logger
7
7
 
8
8
  from ..commands.base import Command
9
9
  from ..commands.base import CommandExecutor
@@ -11,6 +11,9 @@ from .packages import SystemPackage
11
11
  from .packages import SystemPackageManager
12
12
 
13
13
 
14
+ log = get_module_logger(globals()) # noqa
15
+
16
+
14
17
  ##
15
18
 
16
19
 
@@ -3,10 +3,13 @@ import sys
3
3
 
4
4
  from omlish.lite.abstract import Abstract
5
5
  from omlish.lite.cached import cached_nullary
6
- from omlish.lite.logs import log
6
+ from omlish.logs.modules import get_module_logger
7
7
  from omlish.os.linux import LinuxOsRelease
8
8
 
9
9
 
10
+ log = get_module_logger(globals()) # noqa
11
+
12
+
10
13
  ##
11
14
 
12
15
 
@@ -67,8 +67,10 @@ TomlParseFloat = ta.Callable[[str], ta.Any] # ta.TypeAlias
67
67
  TomlKey = ta.Tuple[str, ...] # ta.TypeAlias
68
68
  TomlPos = int # ta.TypeAlias
69
69
 
70
- # ../../../../omlish/lite/cached.py
70
+ # ../../../../omlish/lite/attrops.py
71
71
  T = ta.TypeVar('T')
72
+
73
+ # ../../../../omlish/lite/cached.py
72
74
  CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
73
75
 
74
76
  # ../../../../omlish/lite/check.py
@@ -1304,6 +1306,335 @@ class Abstract:
1304
1306
  update_abstracts(cls, force=True)
1305
1307
 
1306
1308
 
1309
+ ########################################
1310
+ # ../../../../../omlish/lite/attrops.py
1311
+ """
1312
+ TODO:
1313
+ - dotted paths!
1314
+ - per-attr repr transform / filter
1315
+ - __ne__ ? cases where it still matters
1316
+ - ordering ?
1317
+ """
1318
+
1319
+
1320
+ ##
1321
+
1322
+
1323
+ @ta.final
1324
+ class AttrOps(ta.Generic[T]):
1325
+ @ta.final
1326
+ class Attr:
1327
+ def __init__(
1328
+ self,
1329
+ name: str,
1330
+ *,
1331
+ display: ta.Optional[str] = None,
1332
+
1333
+ repr: bool = True, # noqa
1334
+ hash: bool = True, # noqa
1335
+ eq: bool = True,
1336
+ ) -> None:
1337
+ if '.' in name:
1338
+ raise NotImplementedError('Dotted paths not yet supported')
1339
+ if not name.isidentifier() or name.startswith('__'):
1340
+ raise AttributeError(f'Invalid attr: {name!r}')
1341
+ self._name = name
1342
+
1343
+ if display is None:
1344
+ display = name[1:] if name.startswith('_') and len(name) > 1 else name
1345
+ self._display = display
1346
+
1347
+ self._repr = repr
1348
+ self._hash = hash
1349
+ self._eq = eq
1350
+
1351
+ @classmethod
1352
+ def of(
1353
+ cls,
1354
+ o: ta.Union[
1355
+ str,
1356
+ ta.Tuple[str, str],
1357
+ 'AttrOps.Attr',
1358
+ ],
1359
+ ) -> 'AttrOps.Attr':
1360
+ if isinstance(o, AttrOps.Attr):
1361
+ return o
1362
+ elif isinstance(o, str):
1363
+ return cls(o)
1364
+ else:
1365
+ name, disp = o
1366
+ return cls(
1367
+ name,
1368
+ display=disp,
1369
+ )
1370
+
1371
+ @property
1372
+ def name(self) -> str:
1373
+ return self._name
1374
+
1375
+ @property
1376
+ def display(self) -> str:
1377
+ return self._display
1378
+
1379
+ @property
1380
+ def hash(self) -> bool:
1381
+ return self._hash
1382
+
1383
+ @property
1384
+ def eq(self) -> bool:
1385
+ return self._eq
1386
+
1387
+ @ta.overload
1388
+ def __init__(
1389
+ self,
1390
+ *attrs: ta.Sequence[ta.Union[
1391
+ str,
1392
+ ta.Tuple[str, str],
1393
+ Attr,
1394
+ ]],
1395
+ with_module: bool = False,
1396
+ use_qualname: bool = False,
1397
+ with_id: bool = False,
1398
+ repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = None,
1399
+ recursive: bool = False,
1400
+ subtypes_eq: bool = False,
1401
+ ) -> None:
1402
+ ...
1403
+
1404
+ @ta.overload
1405
+ def __init__(
1406
+ self,
1407
+ attrs_fn: ta.Callable[[T], ta.Tuple[ta.Union[
1408
+ ta.Any,
1409
+ ta.Tuple[str, ta.Any],
1410
+ Attr,
1411
+ ], ...]],
1412
+ /,
1413
+ *,
1414
+ with_module: bool = False,
1415
+ use_qualname: bool = False,
1416
+ with_id: bool = False,
1417
+ repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = None,
1418
+ recursive: bool = False,
1419
+ subtypes_eq: bool = False,
1420
+ ) -> None:
1421
+ ...
1422
+
1423
+ def __init__(
1424
+ self,
1425
+ *args,
1426
+ with_module=False,
1427
+ use_qualname=False,
1428
+ with_id=False,
1429
+ repr_filter=None,
1430
+ recursive=False,
1431
+ subtypes_eq=False,
1432
+ ) -> None:
1433
+ if args and len(args) == 1 and callable(args[0]):
1434
+ self._attrs: ta.Sequence[AttrOps.Attr] = self._capture_attrs(args[0])
1435
+ else:
1436
+ self._attrs = list(map(AttrOps.Attr.of, args))
1437
+
1438
+ self._with_module: bool = with_module
1439
+ self._use_qualname: bool = use_qualname
1440
+ self._with_id: bool = with_id
1441
+ self._repr_filter: ta.Optional[ta.Callable[[ta.Any], bool]] = repr_filter
1442
+ self._recursive: bool = recursive
1443
+ self._subtypes_eq: bool = subtypes_eq
1444
+
1445
+ @property
1446
+ def attrs(self) -> ta.Sequence[Attr]:
1447
+ return self._attrs
1448
+
1449
+ #
1450
+
1451
+ @ta.final
1452
+ class _AttrCapturer:
1453
+ def __init__(self, fn):
1454
+ self.__fn = fn
1455
+
1456
+ def __getattr__(self, attr):
1457
+ return self.__fn(self, attr)
1458
+
1459
+ @classmethod
1460
+ def _capture_attrs(cls, fn: ta.Callable) -> ta.Sequence[Attr]:
1461
+ def access(parent, attr):
1462
+ dct[(ret := cls._AttrCapturer(access))] = (parent, attr)
1463
+ return ret
1464
+
1465
+ dct: dict = {}
1466
+ raw = fn(root := cls._AttrCapturer(access))
1467
+
1468
+ def rec(cap): # noqa
1469
+ if cap is root:
1470
+ return
1471
+ parent, attr = dct[cap]
1472
+ yield from rec(parent)
1473
+ yield attr
1474
+
1475
+ attrs: ta.List[AttrOps.Attr] = []
1476
+ for o in raw:
1477
+ if isinstance(o, AttrOps.Attr):
1478
+ attrs.append(o)
1479
+ continue
1480
+
1481
+ if isinstance(o, tuple):
1482
+ disp, cap, = o
1483
+ else:
1484
+ disp, cap = None, o
1485
+
1486
+ path = tuple(rec(cap))
1487
+
1488
+ attrs.append(AttrOps.Attr(
1489
+ '.'.join(path),
1490
+ display=disp,
1491
+ ))
1492
+
1493
+ return attrs
1494
+
1495
+ #
1496
+
1497
+ _repr: ta.Callable[[T], str]
1498
+
1499
+ @property
1500
+ def repr(self) -> ta.Callable[[T], str]:
1501
+ try:
1502
+ return self._repr
1503
+ except AttributeError:
1504
+ pass
1505
+
1506
+ def _repr(o: T) -> str:
1507
+ vs = ', '.join(
1508
+ f'{a._display}={v!r}' # noqa
1509
+ for a in self._attrs
1510
+ if a._repr # noqa
1511
+ for v in [getattr(o, a._name)] # noqa
1512
+ if self._repr_filter is None or self._repr_filter(v)
1513
+ )
1514
+
1515
+ return (
1516
+ f'{o.__class__.__module__ + "." if self._with_module else ""}'
1517
+ f'{o.__class__.__qualname__ if self._use_qualname else o.__class__.__name__}'
1518
+ f'{("@" + hex(id(o))[2:]) if self._with_id else ""}'
1519
+ f'({vs})'
1520
+ )
1521
+
1522
+ if self._recursive:
1523
+ _repr = self._reprlib().recursive_repr()(_repr)
1524
+
1525
+ self._repr = _repr
1526
+ return _repr
1527
+
1528
+ _reprlib_: ta.ClassVar[ta.Any]
1529
+
1530
+ @classmethod
1531
+ def _reprlib(cls) -> ta.Any:
1532
+ try:
1533
+ return cls._reprlib_
1534
+ except AttributeError:
1535
+ pass
1536
+
1537
+ import reprlib # noqa
1538
+
1539
+ cls._reprlib_ = reprlib
1540
+ return reprlib
1541
+
1542
+ #
1543
+
1544
+ _hash: ta.Callable[[T], int]
1545
+
1546
+ @property
1547
+ def hash(self) -> ta.Callable[[T], int]:
1548
+ try:
1549
+ return self._hash
1550
+ except AttributeError:
1551
+ pass
1552
+
1553
+ def _hash(o: T) -> int:
1554
+ return hash(tuple(
1555
+ getattr(o, a._name) # noqa
1556
+ for a in self._attrs
1557
+ if a._hash # noqa
1558
+ ))
1559
+
1560
+ self._hash = _hash
1561
+ return _hash
1562
+
1563
+ #
1564
+
1565
+ _eq: ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']]
1566
+
1567
+ @property
1568
+ def eq(self) -> ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']]:
1569
+ try:
1570
+ return self._eq
1571
+ except AttributeError:
1572
+ pass
1573
+
1574
+ def _eq(o: T, x: ta.Any) -> 'ta.Union[bool, types.NotImplementedType]':
1575
+ if self._subtypes_eq:
1576
+ if not isinstance(x, type(o)):
1577
+ return NotImplemented
1578
+ else:
1579
+ if type(x) is not type(o):
1580
+ return NotImplemented
1581
+
1582
+ return all(
1583
+ getattr(o, a._name) == getattr(x, a._name) # noqa
1584
+ for a in self._attrs
1585
+ if a._eq # noqa
1586
+ )
1587
+
1588
+ self._eq = _eq
1589
+ return _eq
1590
+
1591
+ #
1592
+
1593
+ @property
1594
+ def hash_eq(self) -> ta.Tuple[
1595
+ ta.Callable[[T], int],
1596
+ ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']],
1597
+ ]:
1598
+ return (self.hash, self.eq)
1599
+
1600
+ @property
1601
+ def repr_hash_eq(self) -> ta.Tuple[
1602
+ ta.Callable[[T], str],
1603
+ ta.Callable[[T], int],
1604
+ ta.Callable[[T, ta.Any], ta.Union[bool, 'types.NotImplementedType']],
1605
+ ]:
1606
+ return (self.repr, self.hash, self.eq)
1607
+
1608
+ #
1609
+
1610
+ def install(
1611
+ self,
1612
+ locals_dct: ta.MutableMapping[str, ta.Any],
1613
+ *,
1614
+ all: bool = False, # noqa
1615
+ repr: bool = False, # noqa
1616
+ hash: bool = False, # noqa
1617
+ eq: bool = False,
1618
+ ) -> 'AttrOps[T]':
1619
+ if repr or all:
1620
+ locals_dct.update(__repr__=self.repr)
1621
+ if hash or all:
1622
+ locals_dct.update(__hash__=self.hash)
1623
+ if eq or all:
1624
+ locals_dct.update(__eq__=self.eq)
1625
+ return self
1626
+
1627
+
1628
+ attr_ops = AttrOps[ta.Any]
1629
+
1630
+
1631
+ ##
1632
+
1633
+
1634
+ def attr_repr(obj: ta.Any, *attrs: str, **kwargs: ta.Any) -> str:
1635
+ return AttrOps(*attrs, **kwargs).repr(obj)
1636
+
1637
+
1307
1638
  ########################################
1308
1639
  # ../../../../../omlish/lite/cached.py
1309
1640
 
@@ -1322,7 +1653,7 @@ class _AbstractCachedNullary:
1322
1653
  def __call__(self, *args, **kwargs): # noqa
1323
1654
  raise TypeError
1324
1655
 
1325
- def __get__(self, instance, owner): # noqa
1656
+ def __get__(self, instance, owner=None): # noqa
1326
1657
  bound = instance.__dict__[self._fn.__name__] = self.__class__(self._fn.__get__(instance, owner))
1327
1658
  return bound
1328
1659
 
@@ -2081,13 +2412,6 @@ json_dump_compact: ta.Callable[..., None] = functools.partial(json.dump, **JSON_
2081
2412
  json_dumps_compact: ta.Callable[..., str] = functools.partial(json.dumps, **JSON_COMPACT_KWARGS)
2082
2413
 
2083
2414
 
2084
- ########################################
2085
- # ../../../../../omlish/lite/logs.py
2086
-
2087
-
2088
- log = logging.getLogger(__name__)
2089
-
2090
-
2091
2415
  ########################################
2092
2416
  # ../../../../../omlish/lite/objects.py
2093
2417
 
@@ -2333,13 +2657,6 @@ def split_keep_delimiter(s, d):
2333
2657
  ##
2334
2658
 
2335
2659
 
2336
- def attr_repr(obj: ta.Any, *attrs: str) -> str:
2337
- return f'{type(obj).__name__}({", ".join(f"{attr}={getattr(obj, attr)!r}" for attr in attrs)})'
2338
-
2339
-
2340
- ##
2341
-
2342
-
2343
2660
  FORMAT_NUM_BYTES_SUFFIXES: ta.Sequence[str] = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']
2344
2661
 
2345
2662
 
@@ -2355,6 +2672,17 @@ def format_num_bytes(num_bytes: int) -> str:
2355
2672
  return f'{num_bytes / 1024 ** (len(FORMAT_NUM_BYTES_SUFFIXES) - 1):.2f}{FORMAT_NUM_BYTES_SUFFIXES[-1]}'
2356
2673
 
2357
2674
 
2675
+ ########################################
2676
+ # ../../../../../omlish/logs/modules.py
2677
+
2678
+
2679
+ ##
2680
+
2681
+
2682
+ def get_module_logger(mod_globals: ta.Mapping[str, ta.Any]) -> logging.Logger:
2683
+ return logging.getLogger(mod_globals.get('__name__'))
2684
+
2685
+
2358
2686
  ########################################
2359
2687
  # ../../../../../omlish/logs/std/filters.py
2360
2688
 
@@ -3068,6 +3396,9 @@ class AwsDataclassMeta:
3068
3396
  # ../cursor.py
3069
3397
 
3070
3398
 
3399
+ log = get_module_logger(globals()) # noqa
3400
+
3401
+
3071
3402
  ##
3072
3403
 
3073
3404
 
@@ -3127,6 +3458,9 @@ TODO:
3127
3458
  """
3128
3459
 
3129
3460
 
3461
+ log = get_module_logger(globals()) # noqa
3462
+
3463
+
3130
3464
  ##
3131
3465
 
3132
3466
 
@@ -4849,6 +5183,9 @@ class AwsLogMessageBuilder:
4849
5183
  # ../../../../journald/messages.py
4850
5184
 
4851
5185
 
5186
+ log = get_module_logger(globals()) # noqa
5187
+
5188
+
4852
5189
  ##
4853
5190
 
4854
5191
 
@@ -5110,6 +5447,9 @@ TODO:
5110
5447
  """
5111
5448
 
5112
5449
 
5450
+ log = get_module_logger(globals()) # noqa
5451
+
5452
+
5113
5453
  ##
5114
5454
 
5115
5455
 
@@ -5589,6 +5929,9 @@ $SYSTEMD_URLIFY
5589
5929
  """
5590
5930
 
5591
5931
 
5932
+ log = get_module_logger(globals()) # noqa
5933
+
5934
+
5592
5935
  ##
5593
5936
 
5594
5937
 
@@ -5732,6 +6075,9 @@ class Journald2AwsConfig:
5732
6075
  """
5733
6076
 
5734
6077
 
6078
+ log = get_module_logger(globals()) # noqa
6079
+
6080
+
5735
6081
  ##
5736
6082
 
5737
6083