Skip to content

Commit 9651ee8

Browse files
authored
check inet: Make offline use possible
1 parent a57998c commit 9651ee8

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

builder/penv_setup.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import semantic_version
2020
import subprocess
2121
import sys
22+
import socket
2223

2324
from platformio.package.version import pepver_to_semver
2425
from platformio.compat import IS_WINDOWS
@@ -45,6 +46,19 @@
4546
}
4647

4748

49+
def has_internet_connection(host="8.8.8.8", port=53, timeout=2):
50+
"""
51+
Checks if an internet connection is available (default: Google DNS server).
52+
Returns True if a connection is possible, otherwise False.
53+
"""
54+
try:
55+
socket.setdefaulttimeout(timeout)
56+
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
57+
return True
58+
except Exception:
59+
return False
60+
61+
4862
def get_executable_path(penv_dir, executable_name):
4963
"""
5064
Get the path to an executable based on the penv_dir.
@@ -350,12 +364,16 @@ def setup_python_environment(env, platform, platformio_dir):
350364
# Set executable paths from tools
351365
esptool_binary_path = get_executable_path(penv_dir, "esptool")
352366
uv_executable = get_executable_path(penv_dir, "uv")
353-
367+
354368
# Install espressif32 Python dependencies
355-
if not install_python_deps(penv_python, uv_executable):
356-
sys.stderr.write("Error: Failed to install Python dependencies into penv\n")
357-
sys.exit(1)
369+
if has_internet_connection():
370+
if not install_python_deps(penv_python, uv_executable):
371+
sys.stderr.write("Error: Failed to install Python dependencies into penv\n")
372+
sys.exit(1)
373+
else:
374+
print("Warning: No internet connection detected, Python dependency check will be skipped.")
375+
358376
# Install esptool after dependencies
359377
install_esptool(env, platform, penv_python, uv_executable)
360-
378+
361379
return penv_python, esptool_binary_path

0 commit comments

Comments
 (0)