rsnarsna
feat(lambdas): integrate ALLI-script engines and create 4 separate modular Lambda functions
ea3ef49 Download language_core/runtime_environment.py from Rsnarsna/auto: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/Rsnarsna/auto/resolve/main/language_core/runtime_environment.py
- Command line
-
hf download hf://spaces/Rsnarsna/auto/language_core/runtime_environment.py
-
curl -L -o runtime_environment.py https://huggingface.co/spaces/Rsnarsna/auto/resolve/main/language_core/runtime_environment.py
2.19 kB
| """ | |
| Language Core: Runtime Environment and Platform Capability Inspector. | |
| Detects active language runtime versions (Python and Node.js) on the host machine | |
| and resolves enabled language capabilities via the VersionMatrix. | |
| """ | |
| import sys | |
| import subprocess | |
| import platform | |
| from typing import Dict, Any, Optional, List | |
| from language_core.version_matrix import ( | |
| Language, VersionMatrix, LanguageFeature, parse_version_tuple | |
| ) | |
| class RuntimeEnvironment: | |
| """ | |
| Inspects host machine runtime environments (Python and Node.js) | |
| and resolves enabled syntax capabilities. | |
| """ | |
| def get_python_version() -> str: | |
| return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" | |
| def get_nodejs_version() -> Optional[str]: | |
| try: | |
| result = subprocess.run(["node", "--version"], capture_output=True, text=True, timeout=3) | |
| if result.returncode == 0: | |
| return result.stdout.strip().lstrip("vV") | |
| except Exception: | |
| pass | |
| return None | |
| def get_environment_report(cls) -> Dict[str, Any]: | |
| py_ver = cls.get_python_version() | |
| node_ver = cls.get_nodejs_version() | |
| py_caps = VersionMatrix.get_supported_features(Language.PYTHON, py_ver) | |
| py_cap_names = [f.value for f in py_caps] | |
| node_caps = [] | |
| if node_ver: | |
| # Map node version to ES version roughly (Node 14+ supports ES2020, Node 18+ ES2022) | |
| n_major = parse_version_tuple(node_ver)[0] | |
| es_ver = "11.0.0" if n_major >= 14 else "6.0.0" | |
| node_caps = [f.value for f in VersionMatrix.get_supported_features(Language.JAVASCRIPT, es_ver)] | |
| return { | |
| "os": platform.system(), | |
| "os_release": platform.release(), | |
| "python": { | |
| "installed": True, | |
| "version": py_ver, | |
| "supported_features": py_cap_names | |
| }, | |
| "nodejs": { | |
| "installed": node_ver is not None, | |
| "version": node_ver or "Not Found", | |
| "supported_features": node_caps | |
| } | |
| } | |