mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 14:29:34 +08:00
Merge #2271 from Plastic-time
This commit is contained in:
@@ -377,7 +377,12 @@ def _venv_python(root: Path) -> Path:
|
||||
|
||||
|
||||
def _clean_env() -> dict[str, str]:
|
||||
keep = ("PATH", "HOME", "LANG", "LC_ALL", "TMPDIR", "SSL_CERT_FILE", "SSL_CERT_DIR")
|
||||
keep = (
|
||||
*("PATH", "HOME", "LANG", "LC_ALL", "TMPDIR", "SSL_CERT_FILE", "SSL_CERT_DIR"),
|
||||
# Windows counterparts: without SYSTEMROOT, Winsock and the TLS
|
||||
# providers fail to load, so pip cannot even build its SSL context.
|
||||
*("SYSTEMROOT", "WINDIR", "TEMP", "TMP", "USERPROFILE", "PATHEXT"),
|
||||
)
|
||||
env = {key: os.environ[key] for key in keep if key in os.environ}
|
||||
for key in ("HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "http_proxy", "https_proxy"):
|
||||
if key in os.environ:
|
||||
|
||||
@@ -513,7 +513,12 @@ def _stream_event(raw: Any, *, source: str) -> StreamEvent:
|
||||
|
||||
|
||||
def _clean_env() -> dict[str, str]:
|
||||
keep = ("PATH", "HOME", "LANG", "LC_ALL", "TMPDIR", "SSL_CERT_FILE", "SSL_CERT_DIR")
|
||||
keep = (
|
||||
*("PATH", "HOME", "LANG", "LC_ALL", "TMPDIR", "SSL_CERT_FILE", "SSL_CERT_DIR"),
|
||||
# Windows counterparts: without SYSTEMROOT a worker cannot open a
|
||||
# socket (WinError 10106), so asyncio and HTTP clients fail at start-up.
|
||||
*("SYSTEMROOT", "WINDIR", "TEMP", "TMP", "USERPROFILE", "PATHEXT"),
|
||||
)
|
||||
return {key: os.environ[key] for key in keep if key in os.environ}
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import zipfile
|
||||
|
||||
import pytest
|
||||
|
||||
from deeptutor.plugins import lifecycle
|
||||
from deeptutor.plugins.lifecycle import (
|
||||
LifecycleResult,
|
||||
PluginLifecycleError,
|
||||
@@ -156,3 +158,17 @@ def test_manifest_from_wheel_is_parsed_without_importing_plugin(tmp_path) -> Non
|
||||
record = manager.registry.get_plugin(result.plugin_id)
|
||||
assert record is not None and record.manifest is not None
|
||||
assert parse_manifest(record.manifest.to_dict()).id == "org.author.example"
|
||||
|
||||
|
||||
def test_install_env_keeps_windows_system_variables_only(monkeypatch, tmp_path) -> None:
|
||||
# pip builds an SSL context before it reads a local wheel; on Windows that
|
||||
# fails without SYSTEMROOT and the install exits 2.
|
||||
windows = ("SYSTEMROOT", "WINDIR", "TEMP", "TMP", "USERPROFILE", "PATHEXT")
|
||||
for key in windows:
|
||||
monkeypatch.setenv(key, os.environ.get(key) or str(tmp_path))
|
||||
monkeypatch.setenv("DEEPTUTOR_TEST_PROVIDER_KEY", "not-for-plugins")
|
||||
|
||||
env = lifecycle._clean_env()
|
||||
|
||||
assert {key: env.get(key) for key in windows} == {key: os.environ[key] for key in windows}
|
||||
assert "DEEPTUTOR_TEST_PROVIDER_KEY" not in env
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -276,3 +277,29 @@ def test_one_failed_worker_does_not_block_other_managed_extensions(tmp_path, mon
|
||||
workers = runtime.load_enabled_workers(registry)
|
||||
|
||||
assert isinstance(workers[0], _Capability)
|
||||
|
||||
|
||||
_WINDOWS_SYSTEM_ENV = ("SYSTEMROOT", "WINDIR", "TEMP", "TMP", "USERPROFILE", "PATHEXT")
|
||||
|
||||
|
||||
def test_worker_env_keeps_windows_system_variables_only(monkeypatch, tmp_path) -> None:
|
||||
for key in _WINDOWS_SYSTEM_ENV:
|
||||
monkeypatch.setenv(key, os.environ.get(key) or str(tmp_path))
|
||||
monkeypatch.setenv("DEEPTUTOR_TEST_PROVIDER_KEY", "not-for-plugins")
|
||||
|
||||
env = runtime._clean_env()
|
||||
|
||||
assert {key: env.get(key) for key in _WINDOWS_SYSTEM_ENV} == {
|
||||
key: os.environ[key] for key in _WINDOWS_SYSTEM_ENV
|
||||
}
|
||||
assert "DEEPTUTOR_TEST_PROVIDER_KEY" not in env
|
||||
|
||||
|
||||
def test_worker_env_can_open_a_socket() -> None:
|
||||
# On Windows a child without SYSTEMROOT fails here with WinError 10106,
|
||||
# before any plugin code (asyncio, httpx, ...) gets to run.
|
||||
probe = "import socket; socket.socket().close()"
|
||||
completed = subprocess.run(
|
||||
[sys.executable, "-c", probe], env=runtime._clean_env(), capture_output=True
|
||||
)
|
||||
assert completed.returncode == 0, completed.stderr.decode(errors="replace")
|
||||
|
||||
Reference in New Issue
Block a user