4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
"""OpenSRE platform runtime services.
|
|
|
|
This package intentionally shares its name with Python's stdlib ``platform`` module.
|
|
Expose the stdlib module's public API here as well so existing ``import platform``
|
|
callers continue to behave as expected while project code can import subpackages
|
|
such as ``platform.analytics``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
import sysconfig
|
|
from pathlib import Path
|
|
|
|
# Directory (relative to ``sys._MEIPASS``) where the release build stages a copy
|
|
# of the genuine stdlib ``platform.py``. PyInstaller does not lay out the stdlib
|
|
# as loose ``.py`` files on disk, and this package shadows the ``platform`` name,
|
|
# so the frozen binary cannot otherwise reach the real module. The release
|
|
# workflow bundles it here; keep this constant in sync with that ``--add-data``
|
|
# destination.
|
|
_FROZEN_STDLIB_DIR = "_opensre_stdlib_platform"
|
|
|
|
|
|
def _candidate_stdlib_platform_paths() -> list[Path]:
|
|
"""Return the locations to probe for the genuine stdlib ``platform.py``."""
|
|
candidates: list[Path] = []
|
|
|
|
# Frozen builds (PyInstaller): a copy bundled into the extracted data tree.
|
|
meipass = getattr(sys, "_MEIPASS", None)
|
|
if meipass:
|
|
candidates.append(Path(meipass) / _FROZEN_STDLIB_DIR / "platform.py")
|
|
|
|
# Regular source checkout / installed interpreter.
|
|
stdlib_dir = sysconfig.get_path("stdlib")
|
|
if stdlib_dir:
|
|
candidates.append(Path(stdlib_dir) / "platform.py")
|
|
|
|
# Last resort: sit next to another known stdlib module on disk.
|
|
os_file = getattr(os, "__file__", None)
|
|
if os_file:
|
|
candidates.append(Path(os_file).resolve().parent / "platform.py")
|
|
|
|
return candidates
|
|
|
|
|
|
def _is_frozen() -> bool:
|
|
"""Check if running in a PyInstaller frozen build."""
|
|
return getattr(sys, "frozen", False)
|
|
|
|
|
|
_REENTRANCY_GUARD = "_opensre_platform_loading"
|
|
|
|
|
|
def _load_stdlib_platform():
|
|
"""Load the genuine stdlib ``platform`` module.
|
|
|
|
This package intentionally shadows the stdlib ``platform`` name, so the real
|
|
module is loaded directly from its source file. In frozen builds the stdlib
|
|
is not available as loose ``.py`` files, so the release build bundles a copy
|
|
that we load from ``sys._MEIPASS`` (see ``_FROZEN_STDLIB_DIR``).
|
|
"""
|
|
candidates = _candidate_stdlib_platform_paths()
|
|
for stdlib_path in candidates:
|
|
if not stdlib_path.is_file():
|
|
continue
|
|
spec = importlib.util.spec_from_file_location("_opensre_stdlib_platform", stdlib_path)
|
|
if spec is not None and spec.loader is not None:
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
checked = ", ".join(repr(str(path)) for path in candidates) or "<no candidate paths>"
|
|
raise ImportError(f"Unable to load stdlib platform module — checked: {checked}")
|
|
|
|
|
|
_stdlib_platform = _load_stdlib_platform()
|
|
|
|
for _name in dir(_stdlib_platform):
|
|
if _name.startswith("__") and _name not in {"__all__", "__version__"}:
|
|
continue
|
|
globals()[_name] = getattr(_stdlib_platform, _name)
|
|
|
|
__all__ = tuple(name for name in dir(_stdlib_platform) if not name.startswith("_"))
|