51
51
platform = env .PioPlatform ()
52
52
projectconfig = env .GetProjectConfig ()
53
53
terminal_cp = locale .getpreferredencoding ().lower ()
54
+ PYTHON_EXE = env .subst ("$PYTHONEXE" ) # Global Python executable path
54
55
55
56
# Framework directory path
56
57
FRAMEWORK_DIR = platform .get_package_dir ("framework-arduinoespressif32" )
@@ -80,24 +81,20 @@ def add_to_pythonpath(path):
80
81
sys .path .insert (0 , normalized_path )
81
82
82
83
83
- def setup_python_paths (env ):
84
+ def setup_python_paths ():
84
85
"""
85
86
Setup Python paths based on the actual Python executable being used.
86
-
87
- Args:
88
- env: SCons environment object
89
87
"""
90
- python_exe = env .subst ('$PYTHONEXE' )
91
- if not python_exe or not os .path .isfile (python_exe ):
88
+ if not PYTHON_EXE or not os .path .isfile (PYTHON_EXE ):
92
89
return
93
90
94
91
# Get the directory containing the Python executable
95
- python_dir = os .path .dirname (python_exe )
92
+ python_dir = os .path .dirname (PYTHON_EXE )
96
93
add_to_pythonpath (python_dir )
97
94
98
95
# Try to find site-packages directory using the actual Python executable
99
96
result = subprocess .run (
100
- [python_exe , "-c" , "import site; print(site.getsitepackages()[0])" ],
97
+ [PYTHON_EXE , "-c" , "import site; print(site.getsitepackages()[0])" ],
101
98
capture_output = True ,
102
99
text = True ,
103
100
timeout = 5
@@ -108,7 +105,7 @@ def setup_python_paths(env):
108
105
add_to_pythonpath (site_packages )
109
106
110
107
# Setup Python paths based on the actual Python executable
111
- setup_python_paths (env )
108
+ setup_python_paths ()
112
109
113
110
114
111
def _get_executable_path (python_exe , executable_name ):
@@ -200,7 +197,7 @@ def install_python_deps():
200
197
bool: True if successful, False otherwise
201
198
"""
202
199
# Get uv executable path
203
- uv_executable = _get_uv_executable_path (env . subst ( "$PYTHONEXE" ) )
200
+ uv_executable = _get_uv_executable_path (PYTHON_EXE )
204
201
205
202
try :
206
203
result = subprocess .run (
@@ -216,7 +213,7 @@ def install_python_deps():
216
213
if not uv_available :
217
214
try :
218
215
result = subprocess .run (
219
- [env . subst ( "$PYTHONEXE" ) , "-m" , "pip" , "install" , "uv>=0.1.0" , "-q" , "-q" , "-q" ],
216
+ [PYTHON_EXE , "-m" , "pip" , "install" , "uv>=0.1.0" , "-q" , "-q" , "-q" ],
220
217
capture_output = True ,
221
218
text = True ,
222
219
timeout = 30 , # 30 second timeout
@@ -228,11 +225,11 @@ def install_python_deps():
228
225
return False
229
226
230
227
# Update uv executable path after installation
231
- uv_executable = _get_uv_executable_path (env . subst ( "$PYTHONEXE" ) )
228
+ uv_executable = _get_uv_executable_path (PYTHON_EXE )
232
229
233
230
# Add Scripts directory to PATH for Windows
234
231
if sys .platform == "win32" :
235
- python_dir = os .path .dirname (env . subst ( "$PYTHONEXE" ) )
232
+ python_dir = os .path .dirname (PYTHON_EXE )
236
233
scripts_dir = os .path .join (python_dir , "Scripts" )
237
234
if os .path .isdir (scripts_dir ):
238
235
os .environ ["PATH" ] = scripts_dir + os .pathsep + os .environ .get ("PATH" , "" )
@@ -297,7 +294,7 @@ def _get_installed_uv_packages():
297
294
298
295
cmd = [
299
296
uv_executable , "pip" , "install" ,
300
- f"--python={ env . subst ( '$PYTHONEXE' ) } " ,
297
+ f"--python={ PYTHON_EXE } " ,
301
298
"--quiet" , "--upgrade"
302
299
] + packages_list
303
300
@@ -329,42 +326,37 @@ def _get_installed_uv_packages():
329
326
return True
330
327
331
328
332
- def install_esptool (env ):
329
+ def install_esptool ():
333
330
"""
334
331
Install esptool from package folder "tool-esptoolpy" using uv package manager.
335
332
Also determines the path to the esptool executable binary.
336
333
337
- Args:
338
- env: SCons environment object
339
-
340
334
Returns:
341
335
str: Path to esptool executable, or 'esptool' as fallback
342
336
"""
343
- python_exe = env .subst ("$PYTHONEXE" )
344
-
345
337
try :
346
338
subprocess .check_call (
347
- [python_exe , "-c" , "import esptool" ],
339
+ [PYTHON_EXE , "-c" , "import esptool" ],
348
340
stdout = subprocess .DEVNULL ,
349
341
stderr = subprocess .DEVNULL ,
350
342
env = os .environ
351
343
)
352
- esptool_binary_path = _get_esptool_executable_path (python_exe )
344
+ esptool_binary_path = _get_esptool_executable_path (PYTHON_EXE )
353
345
return esptool_binary_path
354
346
except (subprocess .CalledProcessError , FileNotFoundError ):
355
347
pass
356
348
357
349
esptool_repo_path = env .subst (platform .get_package_dir ("tool-esptoolpy" ) or "" )
358
350
if esptool_repo_path and os .path .isdir (esptool_repo_path ):
359
- uv_executable = _get_uv_executable_path (python_exe )
351
+ uv_executable = _get_uv_executable_path (PYTHON_EXE )
360
352
try :
361
353
subprocess .check_call ([
362
354
uv_executable , "pip" , "install" , "--quiet" ,
363
- f"--python={ python_exe } " ,
355
+ f"--python={ PYTHON_EXE } " ,
364
356
"-e" , esptool_repo_path
365
357
], env = os .environ )
366
358
367
- esptool_binary_path = _get_esptool_executable_path (python_exe )
359
+ esptool_binary_path = _get_esptool_executable_path (PYTHON_EXE )
368
360
return esptool_binary_path
369
361
370
362
except subprocess .CalledProcessError as e :
@@ -376,7 +368,7 @@ def install_esptool(env):
376
368
377
369
# Install Python dependencies and esptool
378
370
install_python_deps ()
379
- esptool_binary_path = install_esptool (env )
371
+ esptool_binary_path = install_esptool ()
380
372
381
373
382
374
def BeforeUpload (target , source , env ):
@@ -923,7 +915,7 @@ def firmware_metrics(target, source, env):
923
915
return
924
916
925
917
try :
926
- cmd = [env . subst ( "$PYTHONEXE" ) , "-m" , "esp_idf_size" , "--ng" ]
918
+ cmd = [PYTHON_EXE , "-m" , "esp_idf_size" , "--ng" ]
927
919
928
920
# Parameters from platformio.ini
929
921
extra_args = env .GetProjectOption ("custom_esp_idf_size_args" , "" )
@@ -1051,7 +1043,7 @@ def firmware_metrics(target, source, env):
1051
1043
env .Replace (
1052
1044
UPLOADER = join (FRAMEWORK_DIR , "tools" , "espota.py" ),
1053
1045
UPLOADERFLAGS = ["--debug" , "--progress" , "-i" , "$UPLOAD_PORT" ],
1054
- UPLOADCMD = '"$PYTHONEXE " "$UPLOADER" $UPLOADERFLAGS -f $SOURCE' ,
1046
+ UPLOADCMD = f'" { PYTHON_EXE } " "$UPLOADER" $UPLOADERFLAGS -f $SOURCE' ,
1055
1047
)
1056
1048
if set (["uploadfs" , "uploadfsota" ]) & set (COMMAND_LINE_TARGETS ):
1057
1049
env .Append (UPLOADERFLAGS = ["--spiffs" ])
0 commit comments