Vendor semver fallback for radiosonde

This commit is contained in:
James Smith
2026-03-19 11:09:54 +00:00
parent 953a6be3f1
commit f1345b91c4
2 changed files with 190 additions and 12 deletions
+28 -12
View File
@@ -43,9 +43,10 @@ from utils.validation import (
validate_longitude,
)
logger = get_logger('intercept.radiosonde')
radiosonde_bp = Blueprint('radiosonde', __name__, url_prefix='/radiosonde')
logger = get_logger('intercept.radiosonde')
radiosonde_bp = Blueprint('radiosonde', __name__, url_prefix='/radiosonde')
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Track radiosonde state
radiosonde_running = False
@@ -112,6 +113,17 @@ def _resolve_pip_python(pip_bin: str | None) -> str | None:
return _resolve_shebang_interpreter(pip_bin)
def _build_auto_rx_env(auto_rx_dir: str) -> dict[str, str]:
"""Build environment for radiosonde_auto_rx with compatibility shims."""
env = os.environ.copy()
python_path_entries = [PROJECT_ROOT, auto_rx_dir]
existing_pythonpath = env.get('PYTHONPATH', '')
if existing_pythonpath:
python_path_entries.append(existing_pythonpath)
env['PYTHONPATH'] = os.pathsep.join(entry for entry in python_path_entries if entry)
return env
def _iter_auto_rx_python_candidates(auto_rx_path: str):
"""Yield plausible Python interpreters for radiosonde_auto_rx."""
auto_rx_abs = os.path.abspath(auto_rx_path)
@@ -158,6 +170,7 @@ def _iter_auto_rx_python_candidates(auto_rx_path: str):
def _resolve_auto_rx_python(auto_rx_path: str) -> tuple[str | None, str, list[str]]:
"""Pick a Python interpreter that can import autorx.scan successfully."""
auto_rx_dir = os.path.dirname(os.path.abspath(auto_rx_path))
auto_rx_env = _build_auto_rx_env(auto_rx_dir)
checked: list[str] = []
last_error = 'No usable Python interpreter found'
@@ -167,6 +180,7 @@ def _resolve_auto_rx_python(auto_rx_path: str) -> tuple[str | None, str, list[st
dep_check = subprocess.run(
[python_bin, '-c', 'import autorx.scan'],
cwd=auto_rx_dir,
env=auto_rx_env,
capture_output=True,
timeout=10,
)
@@ -670,16 +684,18 @@ def start_radiosonde():
# Set cwd to the auto_rx directory so 'from autorx.scan import ...' works
auto_rx_dir = os.path.dirname(os.path.abspath(auto_rx_path))
try:
logger.info(f"Starting radiosonde_auto_rx: {' '.join(cmd)}")
app_module.radiosonde_process = subprocess.Popen(
cmd,
auto_rx_env = _build_auto_rx_env(auto_rx_dir)
try:
logger.info(f"Starting radiosonde_auto_rx: {' '.join(cmd)}")
app_module.radiosonde_process = subprocess.Popen(
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
start_new_session=True,
cwd=auto_rx_dir,
)
stderr=subprocess.PIPE,
start_new_session=True,
cwd=auto_rx_dir,
env=auto_rx_env,
)
# Wait briefly for process to start
time.sleep(2.0)