ominfra 0.0.0.dev177__py3-none-any.whl → 0.0.0.dev179__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.
@@ -5,7 +5,7 @@ from omlish.lite.logs import log
5
5
 
6
6
  from ..commands.base import Command
7
7
  from ..commands.base import CommandExecutor
8
- from .deploy import DeployManager
8
+ from .driver import DeployDriverFactory
9
9
  from .specs import DeploySpec
10
10
 
11
11
 
@@ -23,11 +23,12 @@ class DeployCommand(Command['DeployCommand.Output']):
23
23
 
24
24
  @dc.dataclass(frozen=True)
25
25
  class DeployCommandExecutor(CommandExecutor[DeployCommand, DeployCommand.Output]):
26
- _deploy: DeployManager
26
+ _driver_factory: DeployDriverFactory
27
27
 
28
28
  async def execute(self, cmd: DeployCommand) -> DeployCommand.Output:
29
29
  log.info('Deploying! %r', cmd.spec)
30
30
 
31
- await self._deploy.run_deploy(cmd.spec)
31
+ with self._driver_factory(cmd.spec) as driver:
32
+ await driver.drive_deploy()
32
33
 
33
34
  return DeployCommand.Output()
@@ -1,18 +1,10 @@
1
1
  # ruff: noqa: UP006 UP007
2
2
  import datetime
3
- import os.path
4
3
  import typing as ta
5
4
 
6
- from omlish.lite.check import check
7
5
  from omlish.lite.typing import Func0
8
6
 
9
- from .apps import DeployAppManager
10
- from .paths.manager import DeployPathsManager
11
- from .specs import DeploySpec
12
- from .tags import DeployAppRev
13
- from .tags import DeployTagMap
14
7
  from .tags import DeployTime
15
- from .types import DeployHome
16
8
 
17
9
 
18
10
  DEPLOY_TAG_DATETIME_FMT = '%Y%m%dT%H%M%SZ'
@@ -25,16 +17,11 @@ class DeployManager:
25
17
  def __init__(
26
18
  self,
27
19
  *,
28
- apps: DeployAppManager,
29
- paths: DeployPathsManager,
30
20
 
31
21
  utc_clock: ta.Optional[DeployManagerUtcClock] = None,
32
22
  ):
33
23
  super().__init__()
34
24
 
35
- self._apps = apps
36
- self._paths = paths
37
-
38
25
  self._utc_clock = utc_clock
39
26
 
40
27
  def _utc_now(self) -> datetime.datetime:
@@ -43,42 +30,5 @@ class DeployManager:
43
30
  else:
44
31
  return datetime.datetime.now(tz=datetime.timezone.utc) # noqa
45
32
 
46
- def _make_deploy_time(self) -> DeployTime:
33
+ def make_deploy_time(self) -> DeployTime:
47
34
  return DeployTime(self._utc_now().strftime(DEPLOY_TAG_DATETIME_FMT))
48
-
49
- async def run_deploy(
50
- self,
51
- spec: DeploySpec,
52
- ) -> None:
53
- self._paths.validate_deploy_paths()
54
-
55
- #
56
-
57
- hs = check.non_empty_str(spec.home)
58
- hs = os.path.expanduser(hs)
59
- hs = os.path.realpath(hs)
60
- hs = os.path.abspath(hs)
61
-
62
- home = DeployHome(hs)
63
-
64
- #
65
-
66
- deploy_tags = DeployTagMap(
67
- self._make_deploy_time(),
68
- spec.key(),
69
- )
70
-
71
- #
72
-
73
- for app in spec.apps:
74
- app_tags = deploy_tags.add(
75
- app.app,
76
- app.key(),
77
- DeployAppRev(app.git.rev),
78
- )
79
-
80
- await self._apps.prepare_app(
81
- app,
82
- home,
83
- app_tags,
84
- )
@@ -0,0 +1,62 @@
1
+ # ruff: noqa: UP006 UP007
2
+ import typing as ta
3
+
4
+ from omlish.lite.typing import Func1
5
+
6
+ from .apps import DeployAppManager
7
+ from .paths.manager import DeployPathsManager
8
+ from .specs import DeploySpec
9
+ from .tags import DeployAppRev
10
+ from .tags import DeployTagMap
11
+ from .tags import DeployTime
12
+ from .types import DeployHome
13
+
14
+
15
+ class DeployDriverFactory(Func1[DeploySpec, ta.ContextManager['DeployDriver']]):
16
+ pass
17
+
18
+
19
+ class DeployDriver:
20
+ def __init__(
21
+ self,
22
+ *,
23
+ spec: DeploySpec,
24
+ home: DeployHome,
25
+ time: DeployTime,
26
+
27
+ paths: DeployPathsManager,
28
+ apps: DeployAppManager,
29
+ ) -> None:
30
+ super().__init__()
31
+
32
+ self._spec = spec
33
+ self._home = home
34
+ self._time = time
35
+
36
+ self._paths = paths
37
+ self._apps = apps
38
+
39
+ async def drive_deploy(self) -> None:
40
+ self._paths.validate_deploy_paths()
41
+
42
+ #
43
+
44
+ deploy_tags = DeployTagMap(
45
+ self._time,
46
+ self._spec.key(),
47
+ )
48
+
49
+ #
50
+
51
+ for app in self._spec.apps:
52
+ app_tags = deploy_tags.add(
53
+ app.app,
54
+ app.key(),
55
+ DeployAppRev(app.git.rev),
56
+ )
57
+
58
+ await self._apps.prepare_app(
59
+ app,
60
+ self._home,
61
+ app_tags,
62
+ )
@@ -1,6 +1,11 @@
1
1
  # ruff: noqa: UP006 UP007
2
+ import contextlib
3
+ import os.path
2
4
  import typing as ta
3
5
 
6
+ from omlish.lite.check import check
7
+ from omlish.lite.inject import ContextvarInjectorScope
8
+ from omlish.lite.inject import Injector
4
9
  from omlish.lite.inject import InjectorBindingOrBindings
5
10
  from omlish.lite.inject import InjectorBindings
6
11
  from omlish.lite.inject import inj
@@ -12,16 +17,72 @@ from .commands import DeployCommandExecutor
12
17
  from .conf import DeployConfManager
13
18
  from .config import DeployConfig
14
19
  from .deploy import DeployManager
20
+ from .driver import DeployDriver
21
+ from .driver import DeployDriverFactory
15
22
  from .git import DeployGitManager
16
23
  from .interp import InterpCommand
17
24
  from .interp import InterpCommandExecutor
18
25
  from .paths.inject import bind_deploy_paths
19
26
  from .paths.owners import DeployPathOwner
27
+ from .specs import DeploySpec
28
+ from .tags import DeployTime
20
29
  from .tmp import DeployHomeAtomics
21
30
  from .tmp import DeployTmpManager
31
+ from .types import DeployHome
22
32
  from .venvs import DeployVenvManager
23
33
 
24
34
 
35
+ ##
36
+
37
+
38
+ class DeployInjectorScope(ContextvarInjectorScope):
39
+ pass
40
+
41
+
42
+ def bind_deploy_scope() -> InjectorBindings:
43
+ lst: ta.List[InjectorBindingOrBindings] = [
44
+ inj.bind_scope(DeployInjectorScope),
45
+ inj.bind_scope_seed(DeploySpec, DeployInjectorScope),
46
+
47
+ inj.bind(DeployDriver, in_=DeployInjectorScope),
48
+ ]
49
+
50
+ #
51
+
52
+ def provide_deploy_driver_factory(injector: Injector, sc: DeployInjectorScope) -> DeployDriverFactory:
53
+ @contextlib.contextmanager
54
+ def factory(spec: DeploySpec) -> ta.Iterator[DeployDriver]:
55
+ with sc.enter({
56
+ inj.as_key(DeploySpec): spec,
57
+ }):
58
+ yield injector[DeployDriver]
59
+ return DeployDriverFactory(factory)
60
+ lst.append(inj.bind(provide_deploy_driver_factory, singleton=True))
61
+
62
+ #
63
+
64
+ def provide_deploy_home(deploy: DeploySpec) -> DeployHome:
65
+ hs = check.non_empty_str(deploy.home)
66
+ hs = os.path.expanduser(hs)
67
+ hs = os.path.realpath(hs)
68
+ hs = os.path.abspath(hs)
69
+ return DeployHome(hs)
70
+ lst.append(inj.bind(provide_deploy_home, in_=DeployInjectorScope))
71
+
72
+ #
73
+
74
+ def provide_deploy_time(deploys: DeployManager) -> DeployTime:
75
+ return deploys.make_deploy_time()
76
+ lst.append(inj.bind(provide_deploy_time, in_=DeployInjectorScope))
77
+
78
+ #
79
+
80
+ return inj.as_bindings(*lst)
81
+
82
+
83
+ ##
84
+
85
+
25
86
  def bind_deploy(
26
87
  *,
27
88
  deploy_config: DeployConfig,
@@ -30,6 +91,8 @@ def bind_deploy(
30
91
  inj.bind(deploy_config),
31
92
 
32
93
  bind_deploy_paths(),
94
+
95
+ bind_deploy_scope(),
33
96
  ]
34
97
 
35
98
  #
@@ -1,7 +1,7 @@
1
1
  # ruff: noqa: UP006 UP007
2
2
  import dataclasses as dc
3
3
 
4
- from omdev.interp.resolvers import DEFAULT_INTERP_RESOLVER
4
+ from omdev.interp.default import get_default_interp_resolver
5
5
  from omdev.interp.types import InterpOpts
6
6
  from omdev.interp.types import InterpSpecifier
7
7
  from omlish.lite.check import check
@@ -28,7 +28,7 @@ class InterpCommand(Command['InterpCommand.Output']):
28
28
  class InterpCommandExecutor(CommandExecutor[InterpCommand, InterpCommand.Output]):
29
29
  async def execute(self, cmd: InterpCommand) -> InterpCommand.Output:
30
30
  i = InterpSpecifier.parse(check.not_none(cmd.spec))
31
- o = check.not_none(await DEFAULT_INTERP_RESOLVER.resolve(i, install=cmd.install))
31
+ o = check.not_none(await get_default_interp_resolver().resolve(i, install=cmd.install))
32
32
  return InterpCommand.Output(
33
33
  exe=o.exe,
34
34
  version=str(o.version.version),
@@ -6,7 +6,7 @@ TODO:
6
6
  """
7
7
  import os.path
8
8
 
9
- from omdev.interp.resolvers import DEFAULT_INTERP_RESOLVER
9
+ from omdev.interp.default import get_default_interp_resolver
10
10
  from omdev.interp.types import InterpSpecifier
11
11
  from omlish.asyncs.asyncio.subprocesses import asyncio_subprocesses
12
12
  from omlish.lite.check import check
@@ -25,7 +25,7 @@ class DeployVenvManager:
25
25
  ) -> None:
26
26
  if spec.interp is not None:
27
27
  i = InterpSpecifier.parse(check.not_none(spec.interp))
28
- o = check.not_none(await DEFAULT_INTERP_RESOLVER.resolve(i))
28
+ o = check.not_none(await get_default_interp_resolver().resolve(i))
29
29
  sys_exe = o.exe
30
30
  else:
31
31
  sys_exe = 'python3'