omdev 0.0.0.dev209__py3-none-any.whl → 0.0.0.dev211__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.
omdev/ci/shell.py ADDED
@@ -0,0 +1,42 @@
1
+ # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
3
+ import dataclasses as dc
4
+ import os
5
+ import typing as ta
6
+
7
+
8
+ T = ta.TypeVar('T')
9
+
10
+
11
+ ##
12
+
13
+
14
+ @dc.dataclass(frozen=True)
15
+ class ShellCmd:
16
+ s: str
17
+
18
+ env: ta.Optional[ta.Mapping[str, str]] = None
19
+
20
+ def build_run_kwargs(
21
+ self,
22
+ *,
23
+ env: ta.Optional[ta.Mapping[str, str]] = None,
24
+ **kwargs: ta.Any,
25
+ ) -> ta.Dict[str, ta.Any]:
26
+ if env is None:
27
+ env = os.environ
28
+ if self.env:
29
+ if (ek := set(env) & set(self.env)):
30
+ raise KeyError(*ek)
31
+ env = {**env, **self.env}
32
+
33
+ return dict(
34
+ env=env,
35
+ **kwargs,
36
+ )
37
+
38
+ def run(self, fn: ta.Callable[..., T], **kwargs) -> T:
39
+ return fn(
40
+ 'sh', '-c', self.s,
41
+ **self.build_run_kwargs(**kwargs),
42
+ )
omdev/ci/utils.py ADDED
@@ -0,0 +1,81 @@
1
+ # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
3
+ import hashlib
4
+ import logging
5
+ import os.path
6
+ import tempfile
7
+ import time
8
+ import typing as ta
9
+
10
+ from omlish.lite.logs import log
11
+
12
+
13
+ ##
14
+
15
+
16
+ def make_temp_file() -> str:
17
+ file_fd, file = tempfile.mkstemp()
18
+ os.close(file_fd)
19
+ return file
20
+
21
+
22
+ ##
23
+
24
+
25
+ def read_yaml_file(yaml_file: str) -> ta.Any:
26
+ yaml = __import__('yaml')
27
+
28
+ with open(yaml_file) as f:
29
+ return yaml.safe_load(f)
30
+
31
+
32
+ ##
33
+
34
+
35
+ def sha256_str(s: str) -> str:
36
+ return hashlib.sha256(s.encode('utf-8')).hexdigest()
37
+
38
+
39
+ ##
40
+
41
+
42
+ class LogTimingContext:
43
+ DEFAULT_LOG: ta.ClassVar[logging.Logger] = log
44
+
45
+ def __init__(
46
+ self,
47
+ description: str,
48
+ *,
49
+ log: ta.Optional[logging.Logger] = None, # noqa
50
+ level: int = logging.DEBUG,
51
+ ) -> None:
52
+ super().__init__()
53
+
54
+ self._description = description
55
+ self._log = log if log is not None else self.DEFAULT_LOG
56
+ self._level = level
57
+
58
+ def set_description(self, description: str) -> 'LogTimingContext':
59
+ self._description = description
60
+ return self
61
+
62
+ _begin_time: float
63
+ _end_time: float
64
+
65
+ def __enter__(self) -> 'LogTimingContext':
66
+ self._begin_time = time.time()
67
+
68
+ self._log.log(self._level, f'Begin {self._description}') # noqa
69
+
70
+ return self
71
+
72
+ def __exit__(self, exc_type, exc_val, exc_tb):
73
+ self._end_time = time.time()
74
+
75
+ self._log.log(
76
+ self._level,
77
+ f'End {self._description} - {self._end_time - self._begin_time:0.2f} s elapsed',
78
+ )
79
+
80
+
81
+ log_timing_context = LogTimingContext
omdev/interp/cli.py CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python3
2
1
  # @omlish-amalg ../scripts/interp.py
3
2
  # ruff: noqa: UP007
4
3
  """
@@ -104,7 +104,8 @@ class SystemInterpProvider(InterpProvider):
104
104
  async def get_exe_version(self, exe: str) -> ta.Optional[InterpVersion]:
105
105
  if not self._options.inspect:
106
106
  s = os.path.basename(exe)
107
- s = s.removeprefix('python')
107
+ if s.startswith('python'): # noqa
108
+ s = s[len('python'):]
108
109
  if '.' in s:
109
110
  try:
110
111
  return InterpVersion.parse(s)
omdev/pycharm/cli.py CHANGED
@@ -88,7 +88,7 @@ class Cli(ap.Cli):
88
88
 
89
89
  @ap.cmd(
90
90
  ap.arg('dir', nargs='?'),
91
- ap.arg('--clion', action='store_true'),
91
+ ap.arg('-c', '--clion', action='store_true'),
92
92
  )
93
93
  def open(self) -> None:
94
94
  dir = os.path.abspath(self.args.dir or '.') # noqa
omdev/pyproject/cli.py CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python3
2
1
  # @omlish-amalg ../scripts/pyproject.py
3
2
  # ruff: noqa: UP006 UP007
4
3
  """
omdev/revisions.py CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python3
2
1
  """
3
2
  TODO:
4
3
  - omlish-lite, move to pyproject/