ominfra 0.0.0.dev144__py3-none-any.whl → 0.0.0.dev145__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.
@@ -8,7 +8,7 @@ from .base import CommandExecutor
8
8
  CommandExecutorMap = ta.NewType('CommandExecutorMap', ta.Mapping[ta.Type[Command], CommandExecutor])
9
9
 
10
10
 
11
- class CommandExecutionService(CommandExecutor):
11
+ class LocalCommandExecutor(CommandExecutor):
12
12
  def __init__(
13
13
  self,
14
14
  *,
@@ -18,8 +18,8 @@ from .base import CommandNameMap
18
18
  from .base import CommandRegistration
19
19
  from .base import CommandRegistrations
20
20
  from .base import build_command_name_map
21
- from .execution import CommandExecutionService
22
21
  from .execution import CommandExecutorMap
22
+ from .execution import LocalCommandExecutor
23
23
  from .marshal import install_command_marshaling
24
24
  from .subprocess import SubprocessCommand
25
25
  from .subprocess import SubprocessCommandExecutor
@@ -106,8 +106,7 @@ def bind_commands(
106
106
  lst.extend([
107
107
  inj.bind(provide_command_executor_map, singleton=True),
108
108
 
109
- inj.bind(CommandExecutionService, singleton=True, eager=main_config.debug),
110
- inj.bind(CommandExecutor, to_key=CommandExecutionService),
109
+ inj.bind(LocalCommandExecutor, singleton=True, eager=main_config.debug),
111
110
  ])
112
111
 
113
112
  #
@@ -0,0 +1,33 @@
1
+ # ruff: noqa: UP006 UP007
2
+ """
3
+ ~deploy
4
+ deploy.pid (flock)
5
+ /app
6
+ /<appspec> - shallow clone
7
+ /conf
8
+ /env
9
+ <appspec>.env
10
+ /nginx
11
+ <appspec>.conf
12
+ /supervisor
13
+ <appspec>.conf
14
+ /venv
15
+ /<appspec>
16
+
17
+ ?
18
+ /logs
19
+ /wrmsr--omlish--<spec>
20
+
21
+ spec = <name>--<rev>--<when>
22
+
23
+ ==
24
+
25
+ for dn in [
26
+ 'app',
27
+ 'conf',
28
+ 'conf/env',
29
+ 'conf/nginx',
30
+ 'conf/supervisor',
31
+ 'venv',
32
+ ]:
33
+ """
ominfra/manage/main.py CHANGED
@@ -17,6 +17,7 @@ from .bootstrap import MainBootstrap
17
17
  from .bootstrap_ import main_bootstrap
18
18
  from .commands.base import Command
19
19
  from .commands.base import CommandExecutor
20
+ from .commands.execution import LocalCommandExecutor
20
21
  from .commands.subprocess import SubprocessCommand
21
22
  from .config import MainConfig
22
23
  from .deploy.command import DeployCommand
@@ -90,7 +91,7 @@ def _main() -> None:
90
91
  ce: CommandExecutor
91
92
 
92
93
  if args.local:
93
- ce = injector[CommandExecutor]
94
+ ce = injector[LocalCommandExecutor]
94
95
 
95
96
  else:
96
97
  tgt = RemoteSpawning.Target(
@@ -20,6 +20,7 @@ from ..commands.base import CommandException
20
20
  from ..commands.base import CommandExecutor
21
21
  from ..commands.base import CommandOutputOrException
22
22
  from ..commands.base import CommandOutputOrExceptionData
23
+ from ..commands.execution import LocalCommandExecutor
23
24
  from .channel import RemoteChannel
24
25
  from .payload import RemoteExecutionPayloadFile
25
26
  from .payload import get_remote_payload_src
@@ -52,7 +53,7 @@ def _remote_execution_main() -> None:
52
53
 
53
54
  chan.set_marshaler(injector[ObjMarshalerManager])
54
55
 
55
- ce = injector[CommandExecutor]
56
+ ce = injector[LocalCommandExecutor]
56
57
 
57
58
  while True:
58
59
  i = chan.recv_obj(Command)
@@ -2169,23 +2169,24 @@ TODO:
2169
2169
  @dc.dataclass(frozen=True)
2170
2170
  class ObjMarshalOptions:
2171
2171
  raw_bytes: bool = False
2172
+ nonstrict_dataclasses: bool = False
2172
2173
 
2173
2174
 
2174
2175
  class ObjMarshaler(abc.ABC):
2175
2176
  @abc.abstractmethod
2176
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2177
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2177
2178
  raise NotImplementedError
2178
2179
 
2179
2180
  @abc.abstractmethod
2180
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2181
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2181
2182
  raise NotImplementedError
2182
2183
 
2183
2184
 
2184
2185
  class NopObjMarshaler(ObjMarshaler):
2185
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2186
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2186
2187
  return o
2187
2188
 
2188
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2189
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2189
2190
  return o
2190
2191
 
2191
2192
 
@@ -2193,29 +2194,29 @@ class NopObjMarshaler(ObjMarshaler):
2193
2194
  class ProxyObjMarshaler(ObjMarshaler):
2194
2195
  m: ta.Optional[ObjMarshaler] = None
2195
2196
 
2196
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2197
- return check_not_none(self.m).marshal(o, opts)
2197
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2198
+ return check_not_none(self.m).marshal(o, ctx)
2198
2199
 
2199
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2200
- return check_not_none(self.m).unmarshal(o, opts)
2200
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2201
+ return check_not_none(self.m).unmarshal(o, ctx)
2201
2202
 
2202
2203
 
2203
2204
  @dc.dataclass(frozen=True)
2204
2205
  class CastObjMarshaler(ObjMarshaler):
2205
2206
  ty: type
2206
2207
 
2207
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2208
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2208
2209
  return o
2209
2210
 
2210
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2211
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2211
2212
  return self.ty(o)
2212
2213
 
2213
2214
 
2214
2215
  class DynamicObjMarshaler(ObjMarshaler):
2215
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2216
- return marshal_obj(o)
2216
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2217
+ return ctx.manager.marshal_obj(o, opts=ctx.options)
2217
2218
 
2218
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2219
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2219
2220
  return o
2220
2221
 
2221
2222
 
@@ -2223,10 +2224,10 @@ class DynamicObjMarshaler(ObjMarshaler):
2223
2224
  class Base64ObjMarshaler(ObjMarshaler):
2224
2225
  ty: type
2225
2226
 
2226
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2227
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2227
2228
  return base64.b64encode(o).decode('ascii')
2228
2229
 
2229
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2230
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2230
2231
  return self.ty(base64.b64decode(o))
2231
2232
 
2232
2233
 
@@ -2234,25 +2235,25 @@ class Base64ObjMarshaler(ObjMarshaler):
2234
2235
  class BytesSwitchedObjMarshaler(ObjMarshaler):
2235
2236
  m: ObjMarshaler
2236
2237
 
2237
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2238
- if opts.raw_bytes:
2238
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2239
+ if ctx.options.raw_bytes:
2239
2240
  return o
2240
- return self.m.marshal(o, opts)
2241
+ return self.m.marshal(o, ctx)
2241
2242
 
2242
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2243
- if opts.raw_bytes:
2243
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2244
+ if ctx.options.raw_bytes:
2244
2245
  return o
2245
- return self.m.unmarshal(o, opts)
2246
+ return self.m.unmarshal(o, ctx)
2246
2247
 
2247
2248
 
2248
2249
  @dc.dataclass(frozen=True)
2249
2250
  class EnumObjMarshaler(ObjMarshaler):
2250
2251
  ty: type
2251
2252
 
2252
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2253
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2253
2254
  return o.name
2254
2255
 
2255
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2256
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2256
2257
  return self.ty.__members__[o] # type: ignore
2257
2258
 
2258
2259
 
@@ -2260,15 +2261,15 @@ class EnumObjMarshaler(ObjMarshaler):
2260
2261
  class OptionalObjMarshaler(ObjMarshaler):
2261
2262
  item: ObjMarshaler
2262
2263
 
2263
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2264
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2264
2265
  if o is None:
2265
2266
  return None
2266
- return self.item.marshal(o, opts)
2267
+ return self.item.marshal(o, ctx)
2267
2268
 
2268
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2269
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2269
2270
  if o is None:
2270
2271
  return None
2271
- return self.item.unmarshal(o, opts)
2272
+ return self.item.unmarshal(o, ctx)
2272
2273
 
2273
2274
 
2274
2275
  @dc.dataclass(frozen=True)
@@ -2277,11 +2278,11 @@ class MappingObjMarshaler(ObjMarshaler):
2277
2278
  km: ObjMarshaler
2278
2279
  vm: ObjMarshaler
2279
2280
 
2280
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2281
- return {self.km.marshal(k, opts): self.vm.marshal(v, opts) for k, v in o.items()}
2281
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2282
+ return {self.km.marshal(k, ctx): self.vm.marshal(v, ctx) for k, v in o.items()}
2282
2283
 
2283
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2284
- return self.ty((self.km.unmarshal(k, opts), self.vm.unmarshal(v, opts)) for k, v in o.items())
2284
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2285
+ return self.ty((self.km.unmarshal(k, ctx), self.vm.unmarshal(v, ctx)) for k, v in o.items())
2285
2286
 
2286
2287
 
2287
2288
  @dc.dataclass(frozen=True)
@@ -2289,11 +2290,11 @@ class IterableObjMarshaler(ObjMarshaler):
2289
2290
  ty: type
2290
2291
  item: ObjMarshaler
2291
2292
 
2292
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2293
- return [self.item.marshal(e, opts) for e in o]
2293
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2294
+ return [self.item.marshal(e, ctx) for e in o]
2294
2295
 
2295
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2296
- return self.ty(self.item.unmarshal(e, opts) for e in o)
2296
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2297
+ return self.ty(self.item.unmarshal(e, ctx) for e in o)
2297
2298
 
2298
2299
 
2299
2300
  @dc.dataclass(frozen=True)
@@ -2302,11 +2303,18 @@ class DataclassObjMarshaler(ObjMarshaler):
2302
2303
  fs: ta.Mapping[str, ObjMarshaler]
2303
2304
  nonstrict: bool = False
2304
2305
 
2305
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2306
- return {k: m.marshal(getattr(o, k), opts) for k, m in self.fs.items()}
2306
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2307
+ return {
2308
+ k: m.marshal(getattr(o, k), ctx)
2309
+ for k, m in self.fs.items()
2310
+ }
2307
2311
 
2308
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2309
- return self.ty(**{k: self.fs[k].unmarshal(v, opts) for k, v in o.items() if not self.nonstrict or k in self.fs})
2312
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2313
+ return self.ty(**{
2314
+ k: self.fs[k].unmarshal(v, ctx)
2315
+ for k, v in o.items()
2316
+ if not (self.nonstrict or ctx.options.nonstrict_dataclasses) or k in self.fs
2317
+ })
2310
2318
 
2311
2319
 
2312
2320
  @dc.dataclass(frozen=True)
@@ -2326,50 +2334,50 @@ class PolymorphicObjMarshaler(ObjMarshaler):
2326
2334
  {i.tag: i for i in impls},
2327
2335
  )
2328
2336
 
2329
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2337
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2330
2338
  impl = self.impls_by_ty[type(o)]
2331
- return {impl.tag: impl.m.marshal(o, opts)}
2339
+ return {impl.tag: impl.m.marshal(o, ctx)}
2332
2340
 
2333
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2341
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2334
2342
  [(t, v)] = o.items()
2335
2343
  impl = self.impls_by_tag[t]
2336
- return impl.m.unmarshal(v, opts)
2344
+ return impl.m.unmarshal(v, ctx)
2337
2345
 
2338
2346
 
2339
2347
  @dc.dataclass(frozen=True)
2340
2348
  class DatetimeObjMarshaler(ObjMarshaler):
2341
2349
  ty: type
2342
2350
 
2343
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2351
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2344
2352
  return o.isoformat()
2345
2353
 
2346
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2354
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2347
2355
  return self.ty.fromisoformat(o) # type: ignore
2348
2356
 
2349
2357
 
2350
2358
  class DecimalObjMarshaler(ObjMarshaler):
2351
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2359
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2352
2360
  return str(check_isinstance(o, decimal.Decimal))
2353
2361
 
2354
- def unmarshal(self, v: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2362
+ def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2355
2363
  return decimal.Decimal(check_isinstance(v, str))
2356
2364
 
2357
2365
 
2358
2366
  class FractionObjMarshaler(ObjMarshaler):
2359
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2367
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2360
2368
  fr = check_isinstance(o, fractions.Fraction)
2361
2369
  return [fr.numerator, fr.denominator]
2362
2370
 
2363
- def unmarshal(self, v: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2371
+ def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2364
2372
  num, denom = check_isinstance(v, list)
2365
2373
  return fractions.Fraction(num, denom)
2366
2374
 
2367
2375
 
2368
2376
  class UuidObjMarshaler(ObjMarshaler):
2369
- def marshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2377
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2370
2378
  return str(o)
2371
2379
 
2372
- def unmarshal(self, o: ta.Any, opts: ObjMarshalOptions) -> ta.Any:
2380
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2373
2381
  return uuid.UUID(o)
2374
2382
 
2375
2383
 
@@ -2530,6 +2538,12 @@ class ObjMarshalerManager:
2530
2538
 
2531
2539
  #
2532
2540
 
2541
+ def _make_context(self, opts: ta.Optional[ObjMarshalOptions]) -> 'ObjMarshalContext':
2542
+ return ObjMarshalContext(
2543
+ options=opts or self._default_options,
2544
+ manager=self,
2545
+ )
2546
+
2533
2547
  def marshal_obj(
2534
2548
  self,
2535
2549
  o: ta.Any,
@@ -2537,7 +2551,7 @@ class ObjMarshalerManager:
2537
2551
  opts: ta.Optional[ObjMarshalOptions] = None,
2538
2552
  ) -> ta.Any:
2539
2553
  m = self.get_obj_marshaler(ty if ty is not None else type(o))
2540
- return m.marshal(o, opts or self._default_options)
2554
+ return m.marshal(o, self._make_context(opts))
2541
2555
 
2542
2556
  def unmarshal_obj(
2543
2557
  self,
@@ -2546,7 +2560,7 @@ class ObjMarshalerManager:
2546
2560
  opts: ta.Optional[ObjMarshalOptions] = None,
2547
2561
  ) -> T:
2548
2562
  m = self.get_obj_marshaler(ty)
2549
- return m.unmarshal(o, opts or self._default_options)
2563
+ return m.unmarshal(o, self._make_context(opts))
2550
2564
 
2551
2565
  def roundtrip_obj(
2552
2566
  self,
@@ -2561,6 +2575,12 @@ class ObjMarshalerManager:
2561
2575
  return u
2562
2576
 
2563
2577
 
2578
+ @dc.dataclass(frozen=True)
2579
+ class ObjMarshalContext:
2580
+ options: ObjMarshalOptions
2581
+ manager: ObjMarshalerManager
2582
+
2583
+
2564
2584
  ##
2565
2585
 
2566
2586