omdev 0.0.0.dev25__py3-none-any.whl → 0.0.0.dev26__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.

Potentially problematic release.


This version of omdev might be problematic. Click here for more details.

omdev/pyproject/pkg.py CHANGED
@@ -30,13 +30,14 @@ import dataclasses as dc
30
30
  import importlib
31
31
  import os.path
32
32
  import shutil
33
- import subprocess
34
33
  import sys
34
+ import tempfile
35
35
  import types
36
36
  import typing as ta
37
37
 
38
38
  from omlish.lite.cached import cached_nullary
39
39
  from omlish.lite.logs import log
40
+ from omlish.lite.subprocesses import subprocess_check_call
40
41
 
41
42
  from ..cexts.magic import CextMagic
42
43
  from ..findmagic import find_magic
@@ -161,13 +162,12 @@ class BasePyprojectPackageGenerator(abc.ABC):
161
162
  build_output_dir: ta.Optional[str] = None,
162
163
  *,
163
164
  add_revision: bool = False,
165
+ test: bool = False,
164
166
  ) -> None:
165
- subprocess.check_call(
166
- [
167
- sys.executable,
168
- '-m',
169
- 'build',
170
- ],
167
+ subprocess_check_call(
168
+ sys.executable,
169
+ '-m',
170
+ 'build',
171
171
  cwd=self._pkg_dir(),
172
172
  )
173
173
 
@@ -176,6 +176,25 @@ class BasePyprojectPackageGenerator(abc.ABC):
176
176
  if add_revision:
177
177
  GitRevisionAdder().add_to(dist_dir)
178
178
 
179
+ if test:
180
+ for fn in os.listdir(dist_dir):
181
+ tmp_dir = tempfile.mkdtemp()
182
+
183
+ subprocess_check_call(
184
+ sys.executable,
185
+ '-m', 'venv',
186
+ 'test-install',
187
+ cwd=tmp_dir,
188
+ )
189
+
190
+ subprocess_check_call(
191
+ os.path.join(tmp_dir, 'test-install', 'bin', 'python3'),
192
+ '-m', 'pip',
193
+ 'install',
194
+ os.path.abspath(os.path.join(dist_dir, fn)),
195
+ cwd=tmp_dir,
196
+ )
197
+
179
198
  if build_output_dir is not None:
180
199
  for fn in os.listdir(dist_dir):
181
200
  shutil.copyfile(os.path.join(dist_dir, fn), os.path.join(build_output_dir, fn))
omdev/scripts/interp.py CHANGED
@@ -3,7 +3,7 @@
3
3
  # @omlish-lite
4
4
  # @omlish-script
5
5
  # @omdev-amalg-output ../interp/cli.py
6
- # ruff: noqa: UP007
6
+ # ruff: noqa: N802 UP006 UP007 UP036
7
7
  """
8
8
  TODO:
9
9
  - partial best-matches - '3.12'
@@ -31,6 +31,17 @@ import threading
31
31
  import typing as ta
32
32
 
33
33
 
34
+ ########################################
35
+
36
+
37
+ if sys.version_info < (3, 8):
38
+ raise OSError(
39
+ f'Requires python (3, 8), got {sys.version_info} from {sys.executable}') # noqa
40
+
41
+
42
+ ########################################
43
+
44
+
34
45
  # ../../versioning/versions.py
35
46
  VersionLocalType = ta.Tuple[ta.Union[int, str], ...]
36
47
  VersionCmpPrePostDevType = ta.Union['InfinityVersionType', 'NegativeInfinityVersionType', ta.Tuple[str, int]]
@@ -72,7 +83,6 @@ CallableVersionOperator = ta.Callable[['Version', str], bool]
72
83
  # Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
73
84
  # details.
74
85
  # https://github.com/pypa/packaging/blob/2c885fe91a54559e2382902dce28428ad2887be5/src/packaging/version.py
75
- # ruff: noqa: UP006 UP007
76
86
 
77
87
 
78
88
  ##
@@ -479,7 +489,6 @@ class cached_nullary: # noqa
479
489
 
480
490
  ########################################
481
491
  # ../../../omlish/lite/check.py
482
- # ruff: noqa: UP006 UP007
483
492
 
484
493
 
485
494
  def check_isinstance(v: T, spec: ta.Union[ta.Type[T], tuple]) -> T:
@@ -539,7 +548,6 @@ json_dumps_compact: ta.Callable[..., str] = functools.partial(json.dumps, **JSON
539
548
 
540
549
  ########################################
541
550
  # ../../../omlish/lite/reflect.py
542
- # ruff: noqa: UP006
543
551
 
544
552
 
545
553
  _GENERIC_ALIAS_TYPES = (
@@ -640,7 +648,6 @@ def is_sunder(name: str) -> bool:
640
648
  # Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
641
649
  # details.
642
650
  # https://github.com/pypa/packaging/blob/2c885fe91a54559e2382902dce28428ad2887be5/src/packaging/specifiers.py
643
- # ruff: noqa: UP006 UP007
644
651
 
645
652
 
646
653
  ##
@@ -1146,7 +1153,6 @@ TODO:
1146
1153
  - translate json keys
1147
1154
  - debug
1148
1155
  """
1149
- # ruff: noqa: UP006 UP007 N802
1150
1156
 
1151
1157
 
1152
1158
  log = logging.getLogger(__name__)
@@ -1345,46 +1351,51 @@ def configure_standard_logging(
1345
1351
  *,
1346
1352
  json: bool = False,
1347
1353
  target: ta.Optional[logging.Logger] = None,
1348
- no_check: bool = False,
1354
+ force: bool = False,
1349
1355
  ) -> ta.Optional[StandardLogHandler]:
1350
- if target is None:
1351
- target = logging.root
1356
+ logging._acquireLock() # type: ignore # noqa
1357
+ try:
1358
+ if target is None:
1359
+ target = logging.root
1352
1360
 
1353
- #
1361
+ #
1354
1362
 
1355
- if not no_check:
1356
- if any(isinstance(h, StandardLogHandler) for h in list(target.handlers)):
1357
- return None
1363
+ if not force:
1364
+ if any(isinstance(h, StandardLogHandler) for h in list(target.handlers)):
1365
+ return None
1358
1366
 
1359
- #
1367
+ #
1360
1368
 
1361
- handler = logging.StreamHandler()
1369
+ handler = logging.StreamHandler()
1362
1370
 
1363
- #
1371
+ #
1364
1372
 
1365
- formatter: logging.Formatter
1366
- if json:
1367
- formatter = JsonLogFormatter()
1368
- else:
1369
- formatter = StandardLogFormatter(StandardLogFormatter.build_log_format(STANDARD_LOG_FORMAT_PARTS))
1370
- handler.setFormatter(formatter)
1373
+ formatter: logging.Formatter
1374
+ if json:
1375
+ formatter = JsonLogFormatter()
1376
+ else:
1377
+ formatter = StandardLogFormatter(StandardLogFormatter.build_log_format(STANDARD_LOG_FORMAT_PARTS))
1378
+ handler.setFormatter(formatter)
1371
1379
 
1372
- #
1380
+ #
1373
1381
 
1374
- handler.addFilter(TidLogFilter())
1382
+ handler.addFilter(TidLogFilter())
1375
1383
 
1376
- #
1384
+ #
1377
1385
 
1378
- target.addHandler(handler)
1386
+ target.addHandler(handler)
1379
1387
 
1380
- #
1388
+ #
1381
1389
 
1382
- if level is not None:
1383
- target.setLevel(level)
1390
+ if level is not None:
1391
+ target.setLevel(level)
1384
1392
 
1385
- #
1393
+ #
1394
+
1395
+ return StandardLogHandler(handler)
1386
1396
 
1387
- return StandardLogHandler(handler)
1397
+ finally:
1398
+ logging._releaseLock() # type: ignore # noqa
1388
1399
 
1389
1400
 
1390
1401
  ########################################
@@ -1407,7 +1418,6 @@ def check_runtime_version() -> None:
1407
1418
 
1408
1419
  ########################################
1409
1420
  # ../types.py
1410
- # ruff: noqa: UP006
1411
1421
 
1412
1422
 
1413
1423
  # See https://peps.python.org/pep-3149/
@@ -1499,7 +1509,6 @@ class Interp:
1499
1509
 
1500
1510
  ########################################
1501
1511
  # ../../../omlish/lite/subprocesses.py
1502
- # ruff: noqa: UP006 UP007
1503
1512
 
1504
1513
 
1505
1514
  ##
@@ -1606,7 +1615,6 @@ def subprocess_try_output_str(*args: str, **kwargs: ta.Any) -> ta.Optional[str]:
1606
1615
 
1607
1616
  ########################################
1608
1617
  # ../inspect.py
1609
- # ruff: noqa: UP006 UP007
1610
1618
 
1611
1619
 
1612
1620
  @dc.dataclass(frozen=True)
@@ -1770,7 +1778,6 @@ TODO:
1770
1778
  - optionally install / upgrade pyenv itself
1771
1779
  - new vers dont need these custom mac opts, only run on old vers
1772
1780
  """
1773
- # ruff: noqa: UP006 UP007
1774
1781
 
1775
1782
 
1776
1783
  ##
@@ -2165,7 +2172,6 @@ TODO:
2165
2172
  - python, python3, python3.12, ...
2166
2173
  - check if path py's are venvs: sys.prefix != sys.base_prefix
2167
2174
  """
2168
- # ruff: noqa: UP006 UP007
2169
2175
 
2170
2176
 
2171
2177
  ##
@@ -2274,7 +2280,6 @@ class SystemInterpProvider(InterpProvider):
2274
2280
 
2275
2281
  ########################################
2276
2282
  # ../resolvers.py
2277
- # ruff: noqa: UP006 UP007
2278
2283
 
2279
2284
 
2280
2285
  INTERP_PROVIDER_TYPES_BY_NAME: ta.Mapping[str, ta.Type[InterpProvider]] = {
@@ -3,7 +3,7 @@
3
3
  # @omlish-lite
4
4
  # @omlish-script
5
5
  # @omdev-amalg-output ../pyproject/cli.py
6
- # ruff: noqa: UP006 UP007
6
+ # ruff: noqa: N802 TCH003 UP006 UP007 UP036
7
7
  """
8
8
  TODO:
9
9
  - check / tests, src dir sets
@@ -66,6 +66,17 @@ import weakref # noqa
66
66
  import zipfile
67
67
 
68
68
 
69
+ ########################################
70
+
71
+
72
+ if sys.version_info < (3, 8):
73
+ raise OSError(
74
+ f'Requires python (3, 8), got {sys.version_info} from {sys.executable}') # noqa
75
+
76
+
77
+ ########################################
78
+
79
+
69
80
  # ../../toml/parser.py
70
81
  TomlParseFloat = ta.Callable[[str], ta.Any]
71
82
  TomlKey = ta.Tuple[str, ...]
@@ -101,7 +112,6 @@ class CextMagic:
101
112
 
102
113
  ########################################
103
114
  # ../../findmagic.py
104
- # @omlish-script
105
115
 
106
116
 
107
117
  def compile_magic_pat(m: str) -> re.Pattern:
@@ -203,7 +213,6 @@ def find_magic(
203
213
  # License Agreement.
204
214
  #
205
215
  # https://github.com/python/cpython/blob/f5009b69e0cd94b990270e04e65b9d4d2b365844/Lib/tomllib/_parser.py
206
- # ruff: noqa: UP006 UP007
207
216
 
208
217
 
209
218
  ##
@@ -1109,7 +1118,6 @@ class TomlWriter:
1109
1118
  # Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
1110
1119
  # details.
1111
1120
  # https://github.com/pypa/packaging/blob/2c885fe91a54559e2382902dce28428ad2887be5/src/packaging/version.py
1112
- # ruff: noqa: UP006 UP007
1113
1121
 
1114
1122
 
1115
1123
  ##
@@ -1495,7 +1503,6 @@ def canonicalize_version(
1495
1503
 
1496
1504
  ########################################
1497
1505
  # ../../wheelfile.py
1498
- # ruff: noqa: UP006 UP007
1499
1506
  # https://github.com/pypa/wheel/blob/7bb46d7727e6e89fe56b3c78297b3af2672bbbe2/src/wheel/wheelfile.py
1500
1507
  # MIT License
1501
1508
  #
@@ -1755,7 +1762,6 @@ class cached_nullary: # noqa
1755
1762
 
1756
1763
  ########################################
1757
1764
  # ../../../omlish/lite/check.py
1758
- # ruff: noqa: UP006 UP007
1759
1765
 
1760
1766
 
1761
1767
  def check_isinstance(v: T, spec: ta.Union[ta.Type[T], tuple]) -> T:
@@ -1815,7 +1821,6 @@ json_dumps_compact: ta.Callable[..., str] = functools.partial(json.dumps, **JSON
1815
1821
 
1816
1822
  ########################################
1817
1823
  # ../../../omlish/lite/reflect.py
1818
- # ruff: noqa: UP006
1819
1824
 
1820
1825
 
1821
1826
  _GENERIC_ALIAS_TYPES = (
@@ -1898,7 +1903,6 @@ def is_sunder(name: str) -> bool:
1898
1903
  TODO:
1899
1904
  - embed pip._internal.req.parse_requirements, add additional env stuff? breaks compat with raw pip
1900
1905
  """
1901
- # ruff: noqa: UP007
1902
1906
 
1903
1907
 
1904
1908
  class RequirementsRewriter:
@@ -1993,7 +1997,6 @@ class RequirementsRewriter:
1993
1997
  # Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
1994
1998
  # details.
1995
1999
  # https://github.com/pypa/packaging/blob/2c885fe91a54559e2382902dce28428ad2887be5/src/packaging/specifiers.py
1996
- # ruff: noqa: UP006 UP007
1997
2000
 
1998
2001
 
1999
2002
  ##
@@ -2499,7 +2502,6 @@ TODO:
2499
2502
  - translate json keys
2500
2503
  - debug
2501
2504
  """
2502
- # ruff: noqa: UP006 UP007 N802
2503
2505
 
2504
2506
 
2505
2507
  log = logging.getLogger(__name__)
@@ -2698,46 +2700,51 @@ def configure_standard_logging(
2698
2700
  *,
2699
2701
  json: bool = False,
2700
2702
  target: ta.Optional[logging.Logger] = None,
2701
- no_check: bool = False,
2703
+ force: bool = False,
2702
2704
  ) -> ta.Optional[StandardLogHandler]:
2703
- if target is None:
2704
- target = logging.root
2705
+ logging._acquireLock() # type: ignore # noqa
2706
+ try:
2707
+ if target is None:
2708
+ target = logging.root
2705
2709
 
2706
- #
2710
+ #
2707
2711
 
2708
- if not no_check:
2709
- if any(isinstance(h, StandardLogHandler) for h in list(target.handlers)):
2710
- return None
2712
+ if not force:
2713
+ if any(isinstance(h, StandardLogHandler) for h in list(target.handlers)):
2714
+ return None
2711
2715
 
2712
- #
2716
+ #
2713
2717
 
2714
- handler = logging.StreamHandler()
2718
+ handler = logging.StreamHandler()
2715
2719
 
2716
- #
2720
+ #
2717
2721
 
2718
- formatter: logging.Formatter
2719
- if json:
2720
- formatter = JsonLogFormatter()
2721
- else:
2722
- formatter = StandardLogFormatter(StandardLogFormatter.build_log_format(STANDARD_LOG_FORMAT_PARTS))
2723
- handler.setFormatter(formatter)
2722
+ formatter: logging.Formatter
2723
+ if json:
2724
+ formatter = JsonLogFormatter()
2725
+ else:
2726
+ formatter = StandardLogFormatter(StandardLogFormatter.build_log_format(STANDARD_LOG_FORMAT_PARTS))
2727
+ handler.setFormatter(formatter)
2724
2728
 
2725
- #
2729
+ #
2726
2730
 
2727
- handler.addFilter(TidLogFilter())
2731
+ handler.addFilter(TidLogFilter())
2728
2732
 
2729
- #
2733
+ #
2730
2734
 
2731
- target.addHandler(handler)
2735
+ target.addHandler(handler)
2732
2736
 
2733
- #
2737
+ #
2734
2738
 
2735
- if level is not None:
2736
- target.setLevel(level)
2739
+ if level is not None:
2740
+ target.setLevel(level)
2737
2741
 
2738
- #
2742
+ #
2739
2743
 
2740
- return StandardLogHandler(handler)
2744
+ return StandardLogHandler(handler)
2745
+
2746
+ finally:
2747
+ logging._releaseLock() # type: ignore # noqa
2741
2748
 
2742
2749
 
2743
2750
  ########################################
@@ -2747,7 +2754,6 @@ TODO:
2747
2754
  - pickle stdlib objs? have to pin to 3.8 pickle protocol, will be cross-version
2748
2755
  - nonstrict toggle
2749
2756
  """
2750
- # ruff: noqa: UP006 UP007
2751
2757
 
2752
2758
 
2753
2759
  ##
@@ -3063,7 +3069,6 @@ def check_runtime_version() -> None:
3063
3069
 
3064
3070
  ########################################
3065
3071
  # ../../interp/types.py
3066
- # ruff: noqa: UP006
3067
3072
 
3068
3073
 
3069
3074
  # See https://peps.python.org/pep-3149/
@@ -3155,7 +3160,6 @@ class Interp:
3155
3160
 
3156
3161
  ########################################
3157
3162
  # ../configs.py
3158
- # ruff: noqa: UP006 UP007
3159
3163
 
3160
3164
 
3161
3165
  @dc.dataclass(frozen=True)
@@ -3259,7 +3263,6 @@ TODO:
3259
3263
  - omlish-lite, move to pyproject/
3260
3264
  - vendor-lite wheel.wheelfile
3261
3265
  """
3262
- # ruff: noqa: TCH003 UP006 UP007
3263
3266
 
3264
3267
 
3265
3268
  ##
@@ -3399,7 +3402,6 @@ class GitRevisionAdder:
3399
3402
 
3400
3403
  ########################################
3401
3404
  # ../../../omlish/lite/subprocesses.py
3402
- # ruff: noqa: UP006 UP007
3403
3405
 
3404
3406
 
3405
3407
  ##
@@ -3506,7 +3508,6 @@ def subprocess_try_output_str(*args: str, **kwargs: ta.Any) -> ta.Optional[str]:
3506
3508
 
3507
3509
  ########################################
3508
3510
  # ../../interp/inspect.py
3509
- # ruff: noqa: UP006 UP007
3510
3511
 
3511
3512
 
3512
3513
  @dc.dataclass(frozen=True)
@@ -3629,7 +3630,6 @@ https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support
3629
3630
  vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir
3630
3631
  'git+https://github.com/wrmsr/omlish@master#subdirectory=.pip/omlish'
3631
3632
  """ # noqa
3632
- # ruff: noqa: UP006 UP007
3633
3633
 
3634
3634
 
3635
3635
  #
@@ -3749,13 +3749,12 @@ class BasePyprojectPackageGenerator(abc.ABC):
3749
3749
  build_output_dir: ta.Optional[str] = None,
3750
3750
  *,
3751
3751
  add_revision: bool = False,
3752
+ test: bool = False,
3752
3753
  ) -> None:
3753
- subprocess.check_call(
3754
- [
3755
- sys.executable,
3756
- '-m',
3757
- 'build',
3758
- ],
3754
+ subprocess_check_call(
3755
+ sys.executable,
3756
+ '-m',
3757
+ 'build',
3759
3758
  cwd=self._pkg_dir(),
3760
3759
  )
3761
3760
 
@@ -3764,6 +3763,25 @@ class BasePyprojectPackageGenerator(abc.ABC):
3764
3763
  if add_revision:
3765
3764
  GitRevisionAdder().add_to(dist_dir)
3766
3765
 
3766
+ if test:
3767
+ for fn in os.listdir(dist_dir):
3768
+ tmp_dir = tempfile.mkdtemp()
3769
+
3770
+ subprocess_check_call(
3771
+ sys.executable,
3772
+ '-m', 'venv',
3773
+ 'test-install',
3774
+ cwd=tmp_dir,
3775
+ )
3776
+
3777
+ subprocess_check_call(
3778
+ os.path.join(tmp_dir, 'test-install', 'bin', 'python3'),
3779
+ '-m', 'pip',
3780
+ 'install',
3781
+ os.path.abspath(os.path.join(dist_dir, fn)),
3782
+ cwd=tmp_dir,
3783
+ )
3784
+
3767
3785
  if build_output_dir is not None:
3768
3786
  for fn in os.listdir(dist_dir):
3769
3787
  shutil.copyfile(os.path.join(dist_dir, fn), os.path.join(build_output_dir, fn))
@@ -4051,7 +4069,6 @@ TODO:
4051
4069
  - optionally install / upgrade pyenv itself
4052
4070
  - new vers dont need these custom mac opts, only run on old vers
4053
4071
  """
4054
- # ruff: noqa: UP006 UP007
4055
4072
 
4056
4073
 
4057
4074
  ##
@@ -4446,7 +4463,6 @@ TODO:
4446
4463
  - python, python3, python3.12, ...
4447
4464
  - check if path py's are venvs: sys.prefix != sys.base_prefix
4448
4465
  """
4449
- # ruff: noqa: UP006 UP007
4450
4466
 
4451
4467
 
4452
4468
  ##
@@ -4555,7 +4571,6 @@ class SystemInterpProvider(InterpProvider):
4555
4571
 
4556
4572
  ########################################
4557
4573
  # ../../interp/resolvers.py
4558
- # ruff: noqa: UP006 UP007
4559
4574
 
4560
4575
 
4561
4576
  INTERP_PROVIDER_TYPES_BY_NAME: ta.Mapping[str, ta.Type[InterpProvider]] = {
@@ -1,11 +1,18 @@
1
+ """
2
+ TODO:
3
+ - check for updates
4
+ """
1
5
  import os
6
+ import re
2
7
  import shutil
3
8
  import subprocess
9
+ import typing as ta
4
10
 
5
11
  from omlish import argparse as ap
6
12
  from omlish import check
7
13
  from omlish import lang
8
14
  from omlish import logs
15
+ from omlish.formats import yaml
9
16
 
10
17
 
11
18
  @lang.cached_function
@@ -75,6 +82,101 @@ class Cli(ap.Cli):
75
82
  'sh', '-c', 'echo 0 > /proc/sys/kernel/yama/ptrace_scope',
76
83
  )
77
84
 
85
+ @ap.command(
86
+ ap.arg('-f', '--file'),
87
+ ap.arg('-w', '--write', action='store_true'),
88
+ ap.arg('-q', '--quiet', action='store_true'),
89
+ ap.arg('base', type=int),
90
+ )
91
+ def reset_compose_ports(self) -> None:
92
+ base_port = int(self.args.base)
93
+ if not base_port:
94
+ raise Exception('Invalid base port')
95
+
96
+ if self.args.file:
97
+ yml_file = self.args.file
98
+ else:
99
+ yml_file = os.path.join('docker', 'compose.yml')
100
+
101
+ with open(yml_file) as f:
102
+ yml_src = f.read()
103
+
104
+ #
105
+
106
+ port_pat = re.compile(r'(?P<l>\d+):(?P<r>\d+)')
107
+ port_line_pat = re.compile(r"( )+- '(?P<l>\d+):(?P<r>\d+)'\s*")
108
+
109
+ class PortEntry(ta.NamedTuple):
110
+ l: int
111
+ s: str
112
+
113
+ dct: dict[str, list[PortEntry]] = {}
114
+
115
+ with lang.disposing(yaml.WrappedLoaders.base(yml_src)) as loader:
116
+ val = check.not_none(loader.get_single_data()) # type: ignore
117
+ root = check.isinstance(val.value, ta.Mapping)
118
+
119
+ services = check.isinstance(
120
+ check.single(
121
+ v.value # type: ignore
122
+ for k, v in root.items()
123
+ if k.value == 'services' # type: ignore
124
+ ),
125
+ ta.Mapping,
126
+ )
127
+ for name_w, cfg_w in services.items():
128
+ name = check.isinstance(name_w.value, str) # type: ignore
129
+ cfg = check.isinstance(cfg_w.value, ta.Mapping) # type: ignore
130
+
131
+ ports = check.opt_single(v.value for k, v in cfg.items() if k.value == 'ports') # type: ignore
132
+ if not ports:
133
+ continue
134
+
135
+ lst: list[PortEntry] = []
136
+ for port_w in ports:
137
+ port = check.isinstance(port_w.value, str)
138
+ if not re.fullmatch(port_pat, port):
139
+ raise Exception(f'Bad port: {port}')
140
+
141
+ lst.append(PortEntry(
142
+ l=port_w.node.start_mark.line,
143
+ s=port,
144
+ ))
145
+
146
+ dct[name] = lst
147
+
148
+ #
149
+
150
+ src_lines = yml_src.splitlines(keepends=True)
151
+ cur_port = base_port
152
+
153
+ for ps in dct.values():
154
+ for p in ps:
155
+ l = src_lines[p.l]
156
+ if not (m := port_line_pat.fullmatch(l)):
157
+ raise Exception(f'Bad port line: {p} {l!r}')
158
+
159
+ p_l, p_r = map(int, p.s.split(':'))
160
+ l_l, l_r = map(int, [(gd := m.groupdict())['l'], gd['r']])
161
+ if p_l != l_l or p_r != l_r:
162
+ raise Exception(f'Port mismatch: {p}')
163
+
164
+ new_l = l.partition("'")[0] + f"'{cur_port}:{l_r}'\n"
165
+ src_lines[p.l] = new_l
166
+
167
+ cur_port += 1
168
+
169
+ new_src = ''.join(src_lines)
170
+
171
+ #
172
+
173
+ if not self.args.quiet:
174
+ print(new_src)
175
+
176
+ if self.args.write:
177
+ with open(yml_file, 'w') as f:
178
+ f.write(new_src)
179
+
78
180
 
79
181
  if __name__ == '__main__':
80
182
  logs.configure_standard_logging('INFO')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev25
3
+ Version: 0.0.0.dev26
4
4
  Summary: omdev
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Operating System :: POSIX
13
13
  Requires-Python: ~=3.12
14
14
  License-File: LICENSE
15
- Requires-Dist: omlish ==0.0.0.dev25
15
+ Requires-Dist: omlish ==0.0.0.dev26
16
16
  Provides-Extra: all
17
17
  Requires-Dist: pycparser ~=2.22 ; extra == 'all'
18
18
  Requires-Dist: cffi ~=1.17 ; extra == 'all'