ominfra 0.0.0.dev135__py3-none-any.whl → 0.0.0.dev137__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,10 +87,10 @@ Basically this: https://mitogen.networkgenomics.com/howitworks.html
87
87
  ##
88
88
 
89
89
 
90
- _PYREMOTE_BOOTSTRAP_COMM_FD = 100
90
+ _PYREMOTE_BOOTSTRAP_INPUT_FD = 100
91
91
  _PYREMOTE_BOOTSTRAP_SRC_FD = 101
92
92
 
93
- _PYREMOTE_BOOTSTRAP_CHILD_PID_VAR = '_OPYR_CPID'
93
+ _PYREMOTE_BOOTSTRAP_CHILD_PID_VAR = '_OPYR_CHILD_PID'
94
94
  _PYREMOTE_BOOTSTRAP_ARGV0_VAR = '_OPYR_ARGV0'
95
95
 
96
96
  _PYREMOTE_BOOTSTRAP_ACK0 = b'OPYR000\n'
@@ -121,7 +121,7 @@ def _pyremote_bootstrap_main(context_name: str) -> None:
121
121
  # Parent process
122
122
 
123
123
  # Dup original stdin to comm_fd for use as comm channel
124
- os.dup2(0, _PYREMOTE_BOOTSTRAP_COMM_FD)
124
+ os.dup2(0, _PYREMOTE_BOOTSTRAP_INPUT_FD)
125
125
 
126
126
  # Overwrite stdin (fed to python repl) with first copy of src
127
127
  os.dup2(r0, 0)
@@ -179,7 +179,7 @@ def pyremote_build_bootstrap_cmd(context_name: str) -> str:
179
179
  bs_src = textwrap.dedent(inspect.getsource(_pyremote_bootstrap_main))
180
180
 
181
181
  for gl in [
182
- '_PYREMOTE_BOOTSTRAP_COMM_FD',
182
+ '_PYREMOTE_BOOTSTRAP_INPUT_FD',
183
183
  '_PYREMOTE_BOOTSTRAP_SRC_FD',
184
184
 
185
185
  '_PYREMOTE_BOOTSTRAP_CHILD_PID_VAR',
@@ -424,6 +424,7 @@ class PyremoteBootstrapDriver:
424
424
  @dc.dataclass(frozen=True)
425
425
  class PyremotePayloadRuntime:
426
426
  input: ta.BinaryIO
427
+ output: ta.BinaryIO
427
428
  main_src: str
428
429
  env_info: PyremoteEnvInfo
429
430
 
@@ -450,12 +451,19 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
450
451
  os.write(1, struct.pack('<I', len(env_info_json)))
451
452
  os.write(1, env_info_json.encode('utf-8'))
452
453
 
454
+ # Setup IO
455
+ input = os.fdopen(_PYREMOTE_BOOTSTRAP_INPUT_FD, 'rb', 0) # noqa
456
+ output = os.fdopen(os.dup(1), 'wb', 0) # noqa
457
+ os.dup2(nfd := os.open('/dev/null', os.O_WRONLY), 1)
458
+ os.close(nfd)
459
+
453
460
  # Write fourth ack
454
- os.write(1, _PYREMOTE_BOOTSTRAP_ACK3)
461
+ output.write(_PYREMOTE_BOOTSTRAP_ACK3)
455
462
 
456
463
  # Return
457
464
  return PyremotePayloadRuntime(
458
- input=os.fdopen(_PYREMOTE_BOOTSTRAP_COMM_FD, 'rb', 0),
465
+ input=input,
466
+ output=output,
459
467
  main_src=main_src,
460
468
  env_info=env_info,
461
469
  )
@@ -1526,6 +1534,9 @@ def _recv_obj(f: ta.IO, ty: type) -> ta.Any:
1526
1534
  return unmarshal_obj(j, ty)
1527
1535
 
1528
1536
 
1537
+ ##
1538
+
1539
+
1529
1540
  def _remote_main() -> None:
1530
1541
  rt = pyremote_bootstrap_finalize() # noqa
1531
1542
 
@@ -1536,7 +1547,42 @@ def _remote_main() -> None:
1536
1547
 
1537
1548
  o = SubprocessCommand()._execute(i) # noqa
1538
1549
 
1539
- _send_obj(sys.stdout.buffer, o)
1550
+ _send_obj(rt.output, o)
1551
+
1552
+
1553
+ ##
1554
+
1555
+
1556
+ @cached_nullary
1557
+ def _get_self_src() -> str:
1558
+ return inspect.getsource(sys.modules[__name__])
1559
+
1560
+
1561
+ def _is_src_amalg(src: str) -> bool:
1562
+ for l in src.splitlines(): # noqa
1563
+ if l.startswith('# @omlish-amalg-output '):
1564
+ return True
1565
+ return False
1566
+
1567
+
1568
+ @cached_nullary
1569
+ def _is_self_amalg() -> bool:
1570
+ return _is_src_amalg(_get_self_src())
1571
+
1572
+
1573
+ def _get_amalg_src(*, amalg_file: ta.Optional[str]) -> str:
1574
+ if amalg_file is not None:
1575
+ with open(amalg_file) as f:
1576
+ return f.read()
1577
+
1578
+ if _is_self_amalg():
1579
+ return _get_self_src()
1580
+
1581
+ import importlib.resources
1582
+ return importlib.resources.read_text(__package__, '_manage.py')
1583
+
1584
+
1585
+ ##
1540
1586
 
1541
1587
 
1542
1588
  def _main() -> None:
@@ -1544,7 +1590,8 @@ def _main() -> None:
1544
1590
 
1545
1591
  parser = argparse.ArgumentParser()
1546
1592
 
1547
- parser.add_argument('--ssh')
1593
+ parser.add_argument('-s', '--shell')
1594
+ parser.add_argument('-q', '--shell-quote', action='store_true')
1548
1595
  parser.add_argument('--python', default='python3')
1549
1596
  parser.add_argument('--_amalg-file')
1550
1597
 
@@ -1552,23 +1599,7 @@ def _main() -> None:
1552
1599
 
1553
1600
  #
1554
1601
 
1555
- self_src = inspect.getsource(sys.modules[__name__])
1556
- self_src_lines = self_src.splitlines()
1557
- for l in self_src_lines:
1558
- if l.startswith('# @omlish-amalg-output '):
1559
- is_self_amalg = True
1560
- break
1561
- else:
1562
- is_self_amalg = False
1563
-
1564
- if is_self_amalg:
1565
- amalg_src = self_src
1566
- else:
1567
- amalg_file = args._amalg_file # noqa
1568
- if amalg_file is None:
1569
- amalg_file = os.path.join(os.path.dirname(__file__), '_manage.py')
1570
- with open(amalg_file) as f:
1571
- amalg_src = f.read()
1602
+ amalg_src = _get_amalg_src(amalg_file=args._amalg_file) # noqa
1572
1603
 
1573
1604
  #
1574
1605
 
@@ -1582,9 +1613,11 @@ def _main() -> None:
1582
1613
 
1583
1614
  bs_src = pyremote_build_bootstrap_cmd(__package__ or 'manage')
1584
1615
 
1585
- if args.ssh is not None:
1586
- sh_src = ' '.join([args.python, '-c', shlex.quote(bs_src)])
1587
- sh_cmd = f'{args.ssh} {shlex.quote(sh_src)}'
1616
+ if args.shell is not None:
1617
+ sh_src = f'{args.python} -c {shlex.quote(bs_src)}'
1618
+ if args.shell_quote:
1619
+ sh_src = shlex.quote(sh_src)
1620
+ sh_cmd = f'{args.shell} {sh_src}'
1588
1621
  cmd = [sh_cmd]
1589
1622
  shell = True
1590
1623
  else:
@@ -3,13 +3,13 @@
3
3
  # ruff: noqa: UP006 UP007
4
4
  import inspect
5
5
  import json
6
- import os
7
6
  import shlex
8
7
  import struct
9
8
  import subprocess
10
9
  import sys
11
10
  import typing as ta
12
11
 
12
+ from omlish.lite.cached import cached_nullary
13
13
  from omlish.lite.check import check_not_none
14
14
  from omlish.lite.json import json_dumps_compact
15
15
  from omlish.lite.marshal import marshal_obj
@@ -50,6 +50,9 @@ def _recv_obj(f: ta.IO, ty: type) -> ta.Any:
50
50
  return unmarshal_obj(j, ty)
51
51
 
52
52
 
53
+ ##
54
+
55
+
53
56
  def _remote_main() -> None:
54
57
  rt = pyremote_bootstrap_finalize() # noqa
55
58
 
@@ -60,7 +63,42 @@ def _remote_main() -> None:
60
63
 
61
64
  o = SubprocessCommand()._execute(i) # noqa
62
65
 
63
- _send_obj(sys.stdout.buffer, o)
66
+ _send_obj(rt.output, o)
67
+
68
+
69
+ ##
70
+
71
+
72
+ @cached_nullary
73
+ def _get_self_src() -> str:
74
+ return inspect.getsource(sys.modules[__name__])
75
+
76
+
77
+ def _is_src_amalg(src: str) -> bool:
78
+ for l in src.splitlines(): # noqa
79
+ if l.startswith('# @omlish-amalg-output '):
80
+ return True
81
+ return False
82
+
83
+
84
+ @cached_nullary
85
+ def _is_self_amalg() -> bool:
86
+ return _is_src_amalg(_get_self_src())
87
+
88
+
89
+ def _get_amalg_src(*, amalg_file: ta.Optional[str]) -> str:
90
+ if amalg_file is not None:
91
+ with open(amalg_file) as f:
92
+ return f.read()
93
+
94
+ if _is_self_amalg():
95
+ return _get_self_src()
96
+
97
+ import importlib.resources
98
+ return importlib.resources.read_text(__package__, '_manage.py')
99
+
100
+
101
+ ##
64
102
 
65
103
 
66
104
  def _main() -> None:
@@ -68,7 +106,8 @@ def _main() -> None:
68
106
 
69
107
  parser = argparse.ArgumentParser()
70
108
 
71
- parser.add_argument('--ssh')
109
+ parser.add_argument('-s', '--shell')
110
+ parser.add_argument('-q', '--shell-quote', action='store_true')
72
111
  parser.add_argument('--python', default='python3')
73
112
  parser.add_argument('--_amalg-file')
74
113
 
@@ -76,23 +115,7 @@ def _main() -> None:
76
115
 
77
116
  #
78
117
 
79
- self_src = inspect.getsource(sys.modules[__name__])
80
- self_src_lines = self_src.splitlines()
81
- for l in self_src_lines:
82
- if l.startswith('# @omlish-amalg-output '):
83
- is_self_amalg = True
84
- break
85
- else:
86
- is_self_amalg = False
87
-
88
- if is_self_amalg:
89
- amalg_src = self_src
90
- else:
91
- amalg_file = args._amalg_file # noqa
92
- if amalg_file is None:
93
- amalg_file = os.path.join(os.path.dirname(__file__), '_manage.py')
94
- with open(amalg_file) as f:
95
- amalg_src = f.read()
118
+ amalg_src = _get_amalg_src(amalg_file=args._amalg_file) # noqa
96
119
 
97
120
  #
98
121
 
@@ -106,9 +129,11 @@ def _main() -> None:
106
129
 
107
130
  bs_src = pyremote_build_bootstrap_cmd(__package__ or 'manage')
108
131
 
109
- if args.ssh is not None:
110
- sh_src = ' '.join([args.python, '-c', shlex.quote(bs_src)])
111
- sh_cmd = f'{args.ssh} {shlex.quote(sh_src)}'
132
+ if args.shell is not None:
133
+ sh_src = f'{args.python} -c {shlex.quote(bs_src)}'
134
+ if args.shell_quote:
135
+ sh_src = shlex.quote(sh_src)
136
+ sh_cmd = f'{args.shell} {sh_src}'
112
137
  cmd = [sh_cmd]
113
138
  shell = True
114
139
  else:
ominfra/pyremote.py CHANGED
@@ -21,10 +21,10 @@ import zlib
21
21
  ##
22
22
 
23
23
 
24
- _PYREMOTE_BOOTSTRAP_COMM_FD = 100
24
+ _PYREMOTE_BOOTSTRAP_INPUT_FD = 100
25
25
  _PYREMOTE_BOOTSTRAP_SRC_FD = 101
26
26
 
27
- _PYREMOTE_BOOTSTRAP_CHILD_PID_VAR = '_OPYR_CPID'
27
+ _PYREMOTE_BOOTSTRAP_CHILD_PID_VAR = '_OPYR_CHILD_PID'
28
28
  _PYREMOTE_BOOTSTRAP_ARGV0_VAR = '_OPYR_ARGV0'
29
29
 
30
30
  _PYREMOTE_BOOTSTRAP_ACK0 = b'OPYR000\n'
@@ -55,7 +55,7 @@ def _pyremote_bootstrap_main(context_name: str) -> None:
55
55
  # Parent process
56
56
 
57
57
  # Dup original stdin to comm_fd for use as comm channel
58
- os.dup2(0, _PYREMOTE_BOOTSTRAP_COMM_FD)
58
+ os.dup2(0, _PYREMOTE_BOOTSTRAP_INPUT_FD)
59
59
 
60
60
  # Overwrite stdin (fed to python repl) with first copy of src
61
61
  os.dup2(r0, 0)
@@ -113,7 +113,7 @@ def pyremote_build_bootstrap_cmd(context_name: str) -> str:
113
113
  bs_src = textwrap.dedent(inspect.getsource(_pyremote_bootstrap_main))
114
114
 
115
115
  for gl in [
116
- '_PYREMOTE_BOOTSTRAP_COMM_FD',
116
+ '_PYREMOTE_BOOTSTRAP_INPUT_FD',
117
117
  '_PYREMOTE_BOOTSTRAP_SRC_FD',
118
118
 
119
119
  '_PYREMOTE_BOOTSTRAP_CHILD_PID_VAR',
@@ -358,6 +358,7 @@ class PyremoteBootstrapDriver:
358
358
  @dc.dataclass(frozen=True)
359
359
  class PyremotePayloadRuntime:
360
360
  input: ta.BinaryIO
361
+ output: ta.BinaryIO
361
362
  main_src: str
362
363
  env_info: PyremoteEnvInfo
363
364
 
@@ -384,12 +385,19 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
384
385
  os.write(1, struct.pack('<I', len(env_info_json)))
385
386
  os.write(1, env_info_json.encode('utf-8'))
386
387
 
388
+ # Setup IO
389
+ input = os.fdopen(_PYREMOTE_BOOTSTRAP_INPUT_FD, 'rb', 0) # noqa
390
+ output = os.fdopen(os.dup(1), 'wb', 0) # noqa
391
+ os.dup2(nfd := os.open('/dev/null', os.O_WRONLY), 1)
392
+ os.close(nfd)
393
+
387
394
  # Write fourth ack
388
- os.write(1, _PYREMOTE_BOOTSTRAP_ACK3)
395
+ output.write(_PYREMOTE_BOOTSTRAP_ACK3)
389
396
 
390
397
  # Return
391
398
  return PyremotePayloadRuntime(
392
- input=os.fdopen(_PYREMOTE_BOOTSTRAP_COMM_FD, 'rb', 0),
399
+ input=input,
400
+ output=output,
393
401
  main_src=main_src,
394
402
  env_info=env_info,
395
403
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ominfra
3
- Version: 0.0.0.dev135
3
+ Version: 0.0.0.dev137
4
4
  Summary: ominfra
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,8 +12,8 @@ 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: omdev==0.0.0.dev135
16
- Requires-Dist: omlish==0.0.0.dev135
15
+ Requires-Dist: omdev==0.0.0.dev137
16
+ Requires-Dist: omlish==0.0.0.dev137
17
17
  Provides-Extra: all
18
18
  Requires-Dist: paramiko~=3.5; extra == "all"
19
19
  Requires-Dist: asyncssh~=2.18; extra == "all"
@@ -3,7 +3,7 @@ ominfra/__about__.py,sha256=6i1AoruFYQCd-PyhhbDQDWY2d1tiQu9nkwWr-fXAqfY,705
3
3
  ominfra/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  ominfra/cmds.py,sha256=E0AfnvEmnKntXWvmLW5L05_NeDpBET1VBXn7vV6EwBQ,2083
5
5
  ominfra/configs.py,sha256=8aU1Qmbr-qjaE2iP3gAbA2SWJYMPZ-uGK007L01PoOI,1727
6
- ominfra/pyremote.py,sha256=z3D9nj26omHgl3_q_h7uSHRtgYu-Sb06fMQCqS69_QI,10289
6
+ ominfra/pyremote.py,sha256=djh4WzAUqqBoVfXij5ylYHtEh0bo5jxPWicnkg16q1s,10514
7
7
  ominfra/ssh.py,sha256=jQpc4WvkMckIfk4vILda8zFaeharRqc_6wxW50b0OjQ,5431
8
8
  ominfra/threadworkers.py,sha256=oX4ubZn7h932saXpRIJu2MNhBExgGGMuGhdXarZxLJw,4948
9
9
  ominfra/clouds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -57,8 +57,8 @@ ominfra/manage/deploy/poly/site.py,sha256=QJwDDJoVm2-kxi4bxIrp-mn4y2qDLuW3CAUax3
57
57
  ominfra/manage/deploy/poly/supervisor.py,sha256=zkl6VQBcAZaMAhyR9DbbbqULcgFCDZoe9S_vP-mMFQ8,2289
58
58
  ominfra/manage/deploy/poly/venv.py,sha256=BoipDEa4NTeodjf3L57KJfq9eGKLagFNKwD8pS4yrzA,1552
59
59
  ominfra/manage/new/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
60
- ominfra/manage/new/_manage.py,sha256=ycfNgyFofYs6f5jYV2SrAprGChQd-uVhWc79Tvd9iB0,40217
61
- ominfra/manage/new/main.py,sha256=WeiBAM7HQosnDbKahRmDWNvNYUZaKH2d3ooaqk9kQ04,3558
60
+ ominfra/manage/new/_manage.py,sha256=ERsODiUvQUoZQKCPbQUMQDtBLvq3OnFV-jejfLHgmTI,40760
61
+ ominfra/manage/new/main.py,sha256=xIRUXiofpz8Fh3KBw80TdgqGigArC1xooZ1vaIqvxGM,3912
62
62
  ominfra/manage/new/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
63
63
  ominfra/manage/new/commands/base.py,sha256=TTrHL213jf-ClVqToiNHuxQey1Yf6052E8u3E9hAf7Q,574
64
64
  ominfra/manage/new/commands/subprocess.py,sha256=GpbD-cTorgCRg203lCl81HAh-NBYA6ObKa5ZP2ss9rg,1884
@@ -106,9 +106,9 @@ ominfra/tailscale/api.py,sha256=C5-t_b6jZXUWcy5k8bXm7CFnk73pSdrlMOgGDeGVrpw,1370
106
106
  ominfra/tailscale/cli.py,sha256=DSGp4hn5xwOW-l_u_InKlSF6kIobxtUtVssf_73STs0,3567
107
107
  ominfra/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
108
108
  ominfra/tools/listresources.py,sha256=4qVg5txsb10EHhvqXXeM6gJ2jx9LbroEnPydDv1uXs0,6176
109
- ominfra-0.0.0.dev135.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
110
- ominfra-0.0.0.dev135.dist-info/METADATA,sha256=l8zW4aJP_w8h0b-wfdGnlXqPlofGjiw0HLQAfdFfJK4,731
111
- ominfra-0.0.0.dev135.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
112
- ominfra-0.0.0.dev135.dist-info/entry_points.txt,sha256=kgecQ2MgGrM9qK744BoKS3tMesaC3yjLnl9pa5CRczg,37
113
- ominfra-0.0.0.dev135.dist-info/top_level.txt,sha256=E-b2OHkk_AOBLXHYZQ2EOFKl-_6uOGd8EjeG-Zy6h_w,8
114
- ominfra-0.0.0.dev135.dist-info/RECORD,,
109
+ ominfra-0.0.0.dev137.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
110
+ ominfra-0.0.0.dev137.dist-info/METADATA,sha256=8OfILeUYDutFSCpF5j3-yPVNgBa0WHp_CM49WDloxZA,731
111
+ ominfra-0.0.0.dev137.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
112
+ ominfra-0.0.0.dev137.dist-info/entry_points.txt,sha256=kgecQ2MgGrM9qK744BoKS3tMesaC3yjLnl9pa5CRczg,37
113
+ ominfra-0.0.0.dev137.dist-info/top_level.txt,sha256=E-b2OHkk_AOBLXHYZQ2EOFKl-_6uOGd8EjeG-Zy6h_w,8
114
+ ominfra-0.0.0.dev137.dist-info/RECORD,,