omdev 0.0.0.dev210__py3-none-any.whl → 0.0.0.dev211__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omdev/ci/cache.py +137 -10
- omdev/ci/ci.py +110 -75
- omdev/ci/cli.py +41 -7
- omdev/ci/compose.py +31 -15
- omdev/ci/{dockertars.py → docker.py} +43 -30
- omdev/ci/github/__init__.py +0 -0
- omdev/ci/github/bootstrap.py +11 -0
- omdev/ci/github/cache.py +355 -0
- omdev/ci/github/cacheapi.py +207 -0
- omdev/ci/github/cli.py +39 -0
- omdev/ci/requirements.py +1 -0
- omdev/ci/shell.py +42 -0
- omdev/ci/utils.py +49 -0
- omdev/scripts/ci.py +1737 -485
- omdev/scripts/interp.py +22 -22
- omdev/scripts/pyproject.py +22 -22
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/RECORD +22 -16
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev210.dist-info → omdev-0.0.0.dev211.dist-info}/top_level.txt +0 -0
omdev/ci/github/cli.py
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# ruff: noqa: UP006 UP007
|
2
|
+
# @omlish-lite
|
3
|
+
"""
|
4
|
+
See:
|
5
|
+
- https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28
|
6
|
+
"""
|
7
|
+
import dataclasses as dc
|
8
|
+
|
9
|
+
from omlish.argparse.cli import ArgparseCli
|
10
|
+
from omlish.argparse.cli import argparse_arg
|
11
|
+
from omlish.argparse.cli import argparse_cmd
|
12
|
+
from omlish.lite.json import json_dumps_pretty
|
13
|
+
|
14
|
+
from .cache import GithubV1CacheShellClient
|
15
|
+
|
16
|
+
|
17
|
+
class GithubCli(ArgparseCli):
|
18
|
+
@argparse_cmd(
|
19
|
+
argparse_arg('key'),
|
20
|
+
)
|
21
|
+
def get_cache_entry(self) -> None:
|
22
|
+
shell_client = GithubV1CacheShellClient()
|
23
|
+
entry = shell_client.run_get_entry(self.args.key)
|
24
|
+
if entry is None:
|
25
|
+
return
|
26
|
+
print(json_dumps_pretty(dc.asdict(entry))) # noqa
|
27
|
+
|
28
|
+
@argparse_cmd(
|
29
|
+
argparse_arg('repository-id'),
|
30
|
+
)
|
31
|
+
def list_cache_entries(self) -> None:
|
32
|
+
raise NotImplementedError
|
33
|
+
|
34
|
+
|
35
|
+
if __name__ == '__main__':
|
36
|
+
def _main() -> None:
|
37
|
+
GithubCli().cli_run_and_exit()
|
38
|
+
|
39
|
+
_main()
|
omdev/ci/requirements.py
CHANGED
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
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# ruff: noqa: UP006 UP007
|
2
2
|
# @omlish-lite
|
3
3
|
import hashlib
|
4
|
+
import logging
|
4
5
|
import os.path
|
5
6
|
import tempfile
|
7
|
+
import time
|
6
8
|
import typing as ta
|
7
9
|
|
10
|
+
from omlish.lite.logs import log
|
11
|
+
|
8
12
|
|
9
13
|
##
|
10
14
|
|
@@ -30,3 +34,48 @@ def read_yaml_file(yaml_file: str) -> ta.Any:
|
|
30
34
|
|
31
35
|
def sha256_str(s: str) -> str:
|
32
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
|