dbx-tools-node-runtime 0.9.166__tar.gz → 0.9.173__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dbx-tools-node-runtime
3
- Version: 0.9.166
3
+ Version: 0.9.173
4
4
  Summary: Shared PythonMonkey runtime and lazy Node.js bootstrap
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dbx-tools-node-runtime"
3
- version = "0.9.166"
3
+ version = "0.9.173"
4
4
  description = "Shared PythonMonkey runtime and lazy Node.js bootstrap"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10,<4"
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "dbx-tools-node-runtime"
5
- version = "0.9.166"
5
+ version = "0.9.173"
6
6
  description = "Shared PythonMonkey runtime and lazy Node.js bootstrap"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.10,<4"
@@ -24,7 +24,14 @@ _LOCK_DIRECTORY_ENVIRONMENT = "DBX_TOOLS_NODE_RUNTIME_LOCK_DIRECTORY"
24
24
  _NODEJS_WHEEL_REQUIREMENT = "nodejs-wheel>=22.20,<23"
25
25
  _PYTHONMONKEY_VERSION = "1.3.2"
26
26
  _PROCESS_LOCK = RLock()
27
- _PROCESS_RUNTIME: ModuleType | None = None
27
+
28
+
29
+ @dataclass
30
+ class _ProcessRuntime:
31
+ module: ModuleType | None = None
32
+
33
+
34
+ _PROCESS_RUNTIME = _ProcessRuntime()
28
35
 
29
36
 
30
37
  @dataclass(frozen=True)
@@ -330,33 +337,36 @@ def _verify_runtime() -> None:
330
337
  raise RuntimeError(f"Installed PythonMonkey runtime failed verification:\n{result.stdout}")
331
338
 
332
339
 
340
+ def _install_pythonmonkey(lock_directory: str | Path | None) -> ModuleType:
341
+ with _pythonmonkey_install_environment(lock_directory) as environment:
342
+ _pip_install(
343
+ f"pythonmonkey=={_PYTHONMONKEY_VERSION}",
344
+ environment=environment,
345
+ only_binary=("pythonmonkey",),
346
+ )
347
+ _verify_runtime()
348
+ runtime = _environment_pythonmonkey()
349
+ if runtime is None:
350
+ raise RuntimeError(
351
+ "The locked PythonMonkey installation is unavailable in the active "
352
+ f"Python environment {sys.prefix}"
353
+ )
354
+ return runtime
355
+
356
+
357
+ def _load_pythonmonkey(lock_directory: str | Path | None) -> ModuleType:
358
+ runtime = _environment_pythonmonkey()
359
+ if runtime is not None:
360
+ return runtime
361
+ with _file_lock(_lock_path("pythonmonkey", lock_directory)):
362
+ runtime = _environment_pythonmonkey()
363
+ return runtime if runtime is not None else _install_pythonmonkey(lock_directory)
364
+
365
+
333
366
  def ensure_pythonmonkey(lock_directory: str | Path | None = None) -> ModuleType:
334
367
  """Return PythonMonkey, installing its locked version into the active environment."""
335
368
 
336
- global _PROCESS_RUNTIME
337
369
  with _PROCESS_LOCK:
338
- if _PROCESS_RUNTIME is not None:
339
- return _PROCESS_RUNTIME
340
- environment_runtime = _environment_pythonmonkey()
341
- if environment_runtime is not None:
342
- _PROCESS_RUNTIME = environment_runtime
343
- return environment_runtime
344
-
345
- with _file_lock(_lock_path("pythonmonkey", lock_directory)):
346
- environment_runtime = _environment_pythonmonkey()
347
- if environment_runtime is None:
348
- with _pythonmonkey_install_environment(lock_directory) as environment:
349
- _pip_install(
350
- f"pythonmonkey=={_PYTHONMONKEY_VERSION}",
351
- environment=environment,
352
- only_binary=("pythonmonkey",),
353
- )
354
- _verify_runtime()
355
- environment_runtime = _environment_pythonmonkey()
356
- if environment_runtime is None:
357
- raise RuntimeError(
358
- "The locked PythonMonkey installation is unavailable in the active "
359
- f"Python environment {sys.prefix}"
360
- )
361
- _PROCESS_RUNTIME = environment_runtime
362
- return environment_runtime
370
+ if _PROCESS_RUNTIME.module is None:
371
+ _PROCESS_RUNTIME.module = _load_pythonmonkey(lock_directory)
372
+ return _PROCESS_RUNTIME.module