Skip to content

Commit 9152569

Browse files
authored
Modify _setup_certifi_env to use python_exe argument
Updated _setup_certifi_env to accept an optional python executable argument for better certifi path resolution.
1 parent c08eb7d commit 9152569

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

builder/penv_setup.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _setup_python_environment_core(env, platform, platformio_dir, should_install
482482
_install_esptool_from_tl_install(platform, penv_python, uv_executable)
483483

484484
# Setup certifi environment variables
485-
_setup_certifi_env(env)
485+
_setup_certifi_env(env, penv_python)
486486

487487
return penv_python, esptool_binary_path
488488

@@ -609,20 +609,37 @@ def _install_esptool_from_tl_install(platform, python_exe, uv_executable):
609609

610610

611611

612-
def _setup_certifi_env(env):
613-
"""Setup certifi environment variables with optional SCons integration."""
614-
try:
615-
import certifi
616-
except ImportError:
617-
print("Info: certifi not available; skipping CA environment setup.")
618-
return
619-
620-
cert_path = certifi.where()
612+
def _setup_certifi_env(env, python_exe=None):
613+
"""
614+
Setup certifi environment variables with priority from the given python_exe virtual environment.
615+
If python_exe is provided, runs a subprocess to extract certifi path from that env to guarantee penv usage.
616+
Falls back to importing certifi from current environment on failure.
617+
"""
618+
cert_path = None
619+
if python_exe:
620+
try:
621+
# Run python executable from penv to get certifi path
622+
out = subprocess.check_output(
623+
[python_exe, "-c", "import certifi; print(certifi.where())"],
624+
text=True,
625+
timeout=5
626+
)
627+
cert_path = out.strip()
628+
except Exception:
629+
cert_path = None
630+
if not cert_path:
631+
try:
632+
import certifi
633+
cert_path = certifi.where()
634+
except Exception:
635+
print("Info: certifi not available; skipping CA environment setup.")
636+
return
637+
# Set environment variables for certificate bundles
621638
os.environ["CERTIFI_PATH"] = cert_path
622639
os.environ["SSL_CERT_FILE"] = cert_path
623640
os.environ["REQUESTS_CA_BUNDLE"] = cert_path
624641
os.environ["CURL_CA_BUNDLE"] = cert_path
625-
642+
626643
# Also propagate to SCons environment if available
627644
if env is not None:
628645
env_vars = dict(env.get("ENV", {}))

0 commit comments

Comments
 (0)