45
45
from platformio .package .manager .tool import ToolPackageManager
46
46
47
47
48
- # Import penv_setup functionality using explicit module loading
48
+ # Import penv_setup functionality using explicit module loading for centralized Python environment management
49
49
penv_setup_path = Path (__file__ ).parent / "builder" / "penv_setup.py"
50
50
spec = importlib .util .spec_from_file_location ("penv_setup" , str (penv_setup_path ))
51
51
penv_setup_module = importlib .util .module_from_spec (spec )
@@ -226,7 +226,7 @@ def _check_tl_install_version(self) -> bool:
226
226
logger .debug (f"No version check required for { tl_install_name } " )
227
227
return True
228
228
229
- # Check if tool is already installed
229
+ # Check current installation status
230
230
tl_install_path = self .packages_dir / tl_install_name
231
231
package_json_path = tl_install_path / "package.json"
232
232
@@ -244,10 +244,10 @@ def _check_tl_install_version(self) -> bool:
244
244
logger .warning (f"Installed version for { tl_install_name } unknown, installing { required_version } " )
245
245
return self ._install_tl_install (required_version )
246
246
247
- # IMPORTANT: Compare versions correctly
247
+ # Compare versions to avoid unnecessary reinstallation
248
248
if self ._compare_tl_install_versions (installed_version , required_version ):
249
249
logger .debug (f"{ tl_install_name } version { installed_version } is already correctly installed" )
250
- # IMPORTANT: Set package as available, but do NOT reinstall
250
+ # Mark package as available without reinstalling
251
251
self .packages [tl_install_name ]["optional" ] = True
252
252
return True
253
253
else :
@@ -305,8 +305,7 @@ def _extract_version_from_url(self, version_string: str) -> str:
305
305
306
306
def _install_tl_install (self , version : str ) -> bool :
307
307
"""
308
- Install tool-esp_install ONLY when necessary
309
- and handles backwards compatibility for tl-install.
308
+ Install tool-esp_install with version validation and legacy compatibility.
310
309
311
310
Args:
312
311
version: Version string or URL to install
@@ -320,7 +319,7 @@ def _install_tl_install(self, version: str) -> bool:
320
319
try :
321
320
old_tl_install_exists = old_tl_install_path .exists ()
322
321
if old_tl_install_exists :
323
- # remove outdated tl-install
322
+ # Remove legacy tl-install directory
324
323
safe_remove_directory (old_tl_install_path )
325
324
326
325
if tl_install_path .exists ():
@@ -331,17 +330,17 @@ def _install_tl_install(self, version: str) -> bool:
331
330
self .packages [tl_install_name ]["optional" ] = False
332
331
self .packages [tl_install_name ]["version" ] = version
333
332
pm .install (version )
334
- # Ensure backward compatibility by removing pio install status indicator
333
+ # Remove PlatformIO install marker to prevent version conflicts
335
334
tl_piopm_path = tl_install_path / ".piopm"
336
335
safe_remove_file (tl_piopm_path )
337
336
338
337
if (tl_install_path / "package.json" ).exists ():
339
338
logger .info (f"{ tl_install_name } successfully installed and verified" )
340
339
self .packages [tl_install_name ]["optional" ] = True
341
340
342
- # Handle old tl-install to keep backwards compatibility
341
+ # Maintain backwards compatibility with legacy tl-install references
343
342
if old_tl_install_exists :
344
- # Copy tool-esp_install content to tl-install location
343
+ # Copy tool-esp_install content to legacy tl-install location
345
344
if safe_copy_directory (tl_install_path , old_tl_install_path ):
346
345
logger .info (f"Content copied from { tl_install_name } to old tl-install location" )
347
346
else :
@@ -450,7 +449,7 @@ def _run_idf_tools_install(self, tools_json_path: str, idf_tools_path: str, penv
450
449
451
450
def _check_tool_version (self , tool_name : str ) -> bool :
452
451
"""Check if the installed tool version matches the required version."""
453
- # Clean up versioned directories FIRST, before any version checks
452
+ # Clean up versioned directories before version checks to prevent conflicts
454
453
self ._cleanup_versioned_tool_directories (tool_name )
455
454
456
455
paths = self ._get_tool_paths (tool_name )
@@ -489,14 +488,14 @@ def install_tool(self, tool_name: str) -> bool:
489
488
paths = self ._get_tool_paths (tool_name )
490
489
status = self ._check_tool_status (tool_name )
491
490
492
- # Get penv python if available
491
+ # Use centrally configured Python executable if available
493
492
penv_python = getattr (self , '_penv_python' , None )
494
493
495
- # Case 1: New installation with idf_tools
494
+ # Case 1: Fresh installation using idf_tools.py
496
495
if status ['has_idf_tools' ] and status ['has_tools_json' ]:
497
496
return self ._install_with_idf_tools (tool_name , paths , penv_python )
498
497
499
- # Case 2: Tool already installed, version check
498
+ # Case 2: Tool already installed, perform version validation
500
499
if (status ['has_idf_tools' ] and status ['has_piopm' ] and
501
500
not status ['has_tools_json' ]):
502
501
return self ._handle_existing_tool (tool_name , paths )
@@ -511,7 +510,7 @@ def _install_with_idf_tools(self, tool_name: str, paths: Dict[str, str], penv_py
511
510
):
512
511
return False
513
512
514
- # Copy tool files
513
+ # Copy tool metadata to IDF tools directory
515
514
target_package_path = Path (IDF_TOOLS_PATH ) / "tools" / tool_name / "package.json"
516
515
517
516
if not safe_copy_file (paths ['package_path' ], target_package_path ):
@@ -534,7 +533,7 @@ def _handle_existing_tool(self, tool_name: str, paths: Dict[str, str]) -> bool:
534
533
logger .debug (f"Tool { tool_name } found with correct version" )
535
534
return True
536
535
537
- # Wrong version , reinstall - cleanup is already done in _check_tool_version
536
+ # Version mismatch detected , reinstall tool ( cleanup already performed)
538
537
logger .info (f"Reinstalling { tool_name } due to version mismatch" )
539
538
540
539
# Remove the main tool directory (if it still exists after cleanup)
@@ -623,7 +622,7 @@ def _configure_installer(self) -> None:
623
622
logger .error ("Error during tool-esp_install version check / installation" )
624
623
return
625
624
626
- # Remove pio install marker to avoid issues when switching versions
625
+ # Remove legacy PlatformIO install marker to prevent version conflicts
627
626
old_tl_piopm_path = Path (self .packages_dir ) / "tl-install" / ".piopm"
628
627
if old_tl_piopm_path .exists ():
629
628
safe_remove_file (old_tl_piopm_path )
@@ -735,17 +734,17 @@ def _configure_filesystem_tools(self, variables: Dict, targets: List[str]) -> No
735
734
self ._install_filesystem_tool (filesystem , for_download = True )
736
735
737
736
def setup_python_env (self , env ):
738
- """Setup Python virtual environment and return executable paths."""
739
- # Penv should already be set up in configure_default_packages
737
+ """Configure SCons environment with centrally managed Python executable paths."""
738
+ # Python environment is centrally managed in configure_default_packages
740
739
if hasattr (self , '_penv_python' ) and hasattr (self , '_esptool_path' ):
741
- # Update SCons environment with penv python
740
+ # Update SCons environment with centrally configured Python executable
742
741
env .Replace (PYTHONEXE = self ._penv_python )
743
742
return self ._penv_python , self ._esptool_path
744
743
745
744
# This should not happen, but provide fallback
746
745
logger .warning ("Penv not set up in configure_default_packages, setting up now" )
747
746
748
- # Use centralized minimal setup as a fallback and propagate into SCons
747
+ # Fallback to minimal setup if centralized configuration failed
749
748
config = ProjectConfig .get_instance ()
750
749
core_dir = config .get ("platformio" , "core_dir" )
751
750
penv_python , esptool_path = setup_penv_minimal (self , core_dir , install_esptool = True )
@@ -769,7 +768,7 @@ def configure_default_packages(self, variables: Dict, targets: List[str]) -> Any
769
768
self ._configure_installer ()
770
769
self ._install_esptool_package ()
771
770
772
- # THEN: Setup Python virtual environment completely
771
+ # Complete Python virtual environment setup
773
772
config = ProjectConfig .get_instance ()
774
773
core_dir = config .get ("platformio" , "core_dir" )
775
774
0 commit comments