|
19 | 19 | import semantic_version
|
20 | 20 | import subprocess
|
21 | 21 | import sys
|
| 22 | +import socket |
22 | 23 |
|
23 | 24 | from platformio.package.version import pepver_to_semver
|
24 | 25 | from platformio.compat import IS_WINDOWS
|
|
45 | 46 | }
|
46 | 47 |
|
47 | 48 |
|
| 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 | + |
48 | 62 | def get_executable_path(penv_dir, executable_name):
|
49 | 63 | """
|
50 | 64 | Get the path to an executable based on the penv_dir.
|
@@ -350,12 +364,16 @@ def setup_python_environment(env, platform, platformio_dir):
|
350 | 364 | # Set executable paths from tools
|
351 | 365 | esptool_binary_path = get_executable_path(penv_dir, "esptool")
|
352 | 366 | uv_executable = get_executable_path(penv_dir, "uv")
|
353 |
| - |
| 367 | + |
354 | 368 | # 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 | + |
358 | 376 | # Install esptool after dependencies
|
359 | 377 | install_esptool(env, platform, penv_python, uv_executable)
|
360 |
| - |
| 378 | + |
361 | 379 | return penv_python, esptool_binary_path
|
0 commit comments