ominfra 0.0.0.dev156__py3-none-any.whl → 0.0.0.dev158__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
ominfra/pyremote.py CHANGED
@@ -162,7 +162,7 @@ def _pyremote_bootstrap_main(context_name: str) -> None:
162
162
  # Get pid
163
163
  pid = os.getpid()
164
164
 
165
- # Two copies of main src to be sent to parent
165
+ # Two copies of payload src to be sent to parent
166
166
  r0, w0 = os.pipe()
167
167
  r1, w1 = os.pipe()
168
168
 
@@ -201,17 +201,17 @@ def _pyremote_bootstrap_main(context_name: str) -> None:
201
201
  # Write pid
202
202
  os.write(1, struct.pack('<Q', pid))
203
203
 
204
- # Read main src from stdin
205
- main_z_len = struct.unpack('<I', os.read(0, 4))[0]
206
- if len(main_z := os.fdopen(0, 'rb').read(main_z_len)) != main_z_len:
204
+ # Read payload src from stdin
205
+ payload_z_len = struct.unpack('<I', os.read(0, 4))[0]
206
+ if len(payload_z := os.fdopen(0, 'rb').read(payload_z_len)) != payload_z_len:
207
207
  raise EOFError
208
- main_src = zlib.decompress(main_z)
208
+ payload_src = zlib.decompress(payload_z)
209
209
 
210
- # Write both copies of main src. Must write to w0 (parent stdin) before w1 (copy pipe) as pipe will likely fill
211
- # and block and need to be drained by pyremote_bootstrap_finalize running in parent.
210
+ # Write both copies of payload src. Must write to w0 (parent stdin) before w1 (copy pipe) as pipe will likely
211
+ # fill and block and need to be drained by pyremote_bootstrap_finalize running in parent.
212
212
  for w in [w0, w1]:
213
213
  fp = os.fdopen(w, 'wb', 0)
214
- fp.write(main_src)
214
+ fp.write(payload_src)
215
215
  fp.close()
216
216
 
217
217
  # Write second ack
@@ -275,7 +275,7 @@ class PyremotePayloadRuntime:
275
275
  input: ta.BinaryIO
276
276
  output: ta.BinaryIO
277
277
  context_name: str
278
- main_src: str
278
+ payload_src: str
279
279
  options: PyremoteBootstrapOptions
280
280
  env_info: PyremoteEnvInfo
281
281
 
@@ -283,9 +283,9 @@ class PyremotePayloadRuntime:
283
283
  def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
284
284
  # If src file var is not present we need to do initial finalization
285
285
  if _PYREMOTE_BOOTSTRAP_SRC_FILE_VAR not in os.environ:
286
- # Read second copy of main src
286
+ # Read second copy of payload src
287
287
  r1 = os.fdopen(_PYREMOTE_BOOTSTRAP_SRC_FD, 'rb', 0)
288
- main_src = r1.read().decode('utf-8')
288
+ payload_src = r1.read().decode('utf-8')
289
289
  r1.close()
290
290
 
291
291
  # Reap boostrap child. Must be done after reading second copy of source because source may be too big to fit in
@@ -303,7 +303,7 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
303
303
  # Write temp source file
304
304
  import tempfile
305
305
  tfd, tfn = tempfile.mkstemp('-pyremote.py')
306
- os.write(tfd, main_src.encode('utf-8'))
306
+ os.write(tfd, payload_src.encode('utf-8'))
307
307
  os.close(tfd)
308
308
 
309
309
  # Set vars
@@ -322,7 +322,7 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
322
322
 
323
323
  # Read temp source file
324
324
  with open(os.environ.pop(_PYREMOTE_BOOTSTRAP_SRC_FILE_VAR)) as sf:
325
- main_src = sf.read()
325
+ payload_src = sf.read()
326
326
 
327
327
  # Restore vars
328
328
  sys.executable = os.environ.pop(_PYREMOTE_BOOTSTRAP_ARGV0_VAR)
@@ -355,7 +355,7 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
355
355
  input=input,
356
356
  output=output,
357
357
  context_name=context_name,
358
- main_src=main_src,
358
+ payload_src=payload_src,
359
359
  options=options,
360
360
  env_info=env_info,
361
361
  )
@@ -367,31 +367,31 @@ def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
367
367
  class PyremoteBootstrapDriver:
368
368
  def __init__(
369
369
  self,
370
- main_src: ta.Union[str, ta.Sequence[str]],
370
+ payload_src: ta.Union[str, ta.Sequence[str]],
371
371
  options: PyremoteBootstrapOptions = PyremoteBootstrapOptions(),
372
372
  ) -> None:
373
373
  super().__init__()
374
374
 
375
- self._main_src = main_src
375
+ self._payload_src = payload_src
376
376
  self._options = options
377
377
 
378
- self._prepared_main_src = self._prepare_main_src(main_src, options)
379
- self._main_z = zlib.compress(self._prepared_main_src.encode('utf-8'))
378
+ self._prepared_payload_src = self._prepare_payload_src(payload_src, options)
379
+ self._payload_z = zlib.compress(self._prepared_payload_src.encode('utf-8'))
380
380
 
381
381
  self._options_json = json.dumps(dc.asdict(options), indent=None, separators=(',', ':')).encode('utf-8') # noqa
382
382
  #
383
383
 
384
384
  @classmethod
385
- def _prepare_main_src(
385
+ def _prepare_payload_src(
386
386
  cls,
387
- main_src: ta.Union[str, ta.Sequence[str]],
387
+ payload_src: ta.Union[str, ta.Sequence[str]],
388
388
  options: PyremoteBootstrapOptions,
389
389
  ) -> str:
390
390
  parts: ta.List[str]
391
- if isinstance(main_src, str):
392
- parts = [main_src]
391
+ if isinstance(payload_src, str):
392
+ parts = [payload_src]
393
393
  else:
394
- parts = list(main_src)
394
+ parts = list(payload_src)
395
395
 
396
396
  if (mn := options.main_name_override) is not None:
397
397
  parts.insert(0, f'__name__ = {mn!r}')
@@ -427,9 +427,9 @@ class PyremoteBootstrapDriver:
427
427
  d = yield from self._read(8)
428
428
  pid = struct.unpack('<Q', d)[0]
429
429
 
430
- # Write main src
431
- yield from self._write(struct.pack('<I', len(self._main_z)))
432
- yield from self._write(self._main_z)
430
+ # Write payload src
431
+ yield from self._write(struct.pack('<I', len(self._payload_z)))
432
+ yield from self._write(self._payload_z)
433
433
 
434
434
  # Read second ack (after writing src copies)
435
435
  yield from self._expect(_PYREMOTE_BOOTSTRAP_ACK1)