1313import re
1414import yaml
1515from yaml import SafeLoader
16- from os . path import join
16+ from pathlib import Path
1717from typing import Set , Optional , Dict , Any , List , Tuple
1818
1919
@@ -49,8 +49,12 @@ def __init__(self, env):
4949 self .project_src_dir = env .subst ("$PROJECT_SRC_DIR" )
5050 # Get Arduino framework installation directory
5151 self .arduino_framework_dir = self .platform .get_package_dir ("framework-arduinoespressif32" )
52+ # Get Arduino libraries installation directory
53+ ald = self .platform .get_package_dir ("framework-arduinoespressif32-libs" )
5254 # Get MCU-specific Arduino libraries directory
53- self .arduino_libs_mcu = join (self .platform .get_package_dir ("framework-arduinoespressif32-libs" ), self .mcu )
55+ self .arduino_libs_mcu = (
56+ str (Path (ald ) / self .mcu ) if ald else ""
57+ )
5458
5559
5660class ComponentLogger :
@@ -228,13 +232,14 @@ def _get_or_create_component_yml(self) -> str:
228232 Absolute path to the component YAML file
229233 """
230234 # Try Arduino framework first
231- framework_yml = join (self .config .arduino_framework_dir , "idf_component.yml" )
232- if os .path .exists (framework_yml ):
235+ afd = self .config .arduino_framework_dir
236+ framework_yml = str (Path (afd ) / "idf_component.yml" ) if afd else ""
237+ if framework_yml and os .path .exists (framework_yml ):
233238 self ._create_backup (framework_yml )
234239 return framework_yml
235240
236241 # Try project source directory
237- project_yml = join ( self .config .project_src_dir , "idf_component.yml" )
242+ project_yml = str ( Path ( self .config .project_src_dir ) / "idf_component.yml" )
238243 if os .path .exists (project_yml ):
239244 self ._create_backup (project_yml )
240245 return project_yml
@@ -416,9 +421,12 @@ def _backup_pioarduino_build_py(self) -> None:
416421 """
417422 if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
418423 return
419-
420- build_py_path = join (self .config .arduino_libs_mcu , "pioarduino-build.py" )
421- backup_path = join (self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
424+
425+ if not self .config .arduino_libs_mcu :
426+ return
427+
428+ build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
429+ backup_path = str (Path (self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
422430
423431 if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
424432 shutil .copy2 (build_py_path , backup_path )
@@ -446,7 +454,7 @@ def _remove_include_directory(self, component: str) -> None:
446454 Args:
447455 component: Component name in filesystem format
448456 """
449- include_path = join ( self .config .arduino_libs_mcu , "include" , component )
457+ include_path = str ( Path ( self .config .arduino_libs_mcu ) / "include" / component )
450458
451459 if os .path .exists (include_path ):
452460 shutil .rmtree (include_path )
@@ -459,7 +467,7 @@ def _remove_cpppath_entries(self) -> None:
459467 for all components that were removed from the project. Uses
460468 multiple regex patterns to catch different include path formats.
461469 """
462- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
470+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
463471
464472 if not os .path .exists (build_py_path ):
465473 return
@@ -667,14 +675,17 @@ def _get_arduino_core_libraries(self) -> Dict[str, str]:
667675 libraries_mapping = {}
668676
669677 # Path to Arduino Core Libraries
670- arduino_libs_dir = join (self .config .arduino_framework_dir , "libraries" )
678+ afd = self .config .arduino_framework_dir
679+ if not afd :
680+ return libraries_mapping
681+ arduino_libs_dir = str (Path (afd ).resolve () / "libraries" )
671682
672683 if not os .path .exists (arduino_libs_dir ):
673684 return libraries_mapping
674685
675686 try :
676687 for entry in os .listdir (arduino_libs_dir ):
677- lib_path = join ( arduino_libs_dir , entry )
688+ lib_path = str ( Path ( arduino_libs_dir ) / entry )
678689 if os .path .isdir (lib_path ):
679690 lib_name = self ._get_library_name_from_properties (lib_path )
680691 if lib_name :
@@ -699,7 +710,7 @@ def _get_library_name_from_properties(self, lib_dir: str) -> Optional[str]:
699710 Returns:
700711 Official library name or None if not found or readable
701712 """
702- prop_path = join ( lib_dir , "library.properties" )
713+ prop_path = str ( Path ( lib_dir ) / "library.properties" )
703714 if not os .path .isfile (prop_path ):
704715 return None
705716
@@ -891,7 +902,7 @@ def _remove_ignored_lib_includes(self) -> None:
891902 components when dependencies are detected. Uses multiple regex
892903 patterns to catch different include path formats.
893904 """
894- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
905+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
895906
896907 if not os .path .exists (build_py_path ):
897908 self .logger .log_change ("Build file not found" )
@@ -930,7 +941,10 @@ def _remove_ignored_lib_includes(self) -> None:
930941 rf'.*"[^"]*{ re .escape (lib_name )} [^"]*include[^"]*"[^,\n]*,?\n' ,
931942 rf'.*join\([^)]*"include"[^)]*"{ re .escape (lib_name )} "[^)]*\),?\n' ,
932943 rf'.*"{ re .escape (lib_name )} /include"[^,\n]*,?\n' ,
933- rf'\s*"[^"]*/{ re .escape (lib_name )} /[^"]*",?\n'
944+ rf'\s*"[^"]*[\\/]{ re .escape (lib_name )} [\\/][^"]*",?\n' ,
945+ # pathlib-style: Path(...)/"include"/"<name>"
946+ rf'.*Path\([^)]*\)\s*/\s*"include"\s*/\s*"{ re .escape (lib_name )} "[^,\n]*,?\n' ,
947+ rf'.*Path\([^)]*{ re .escape (lib_name )} [^)]*\)\s*/\s*"include"[^,\n]*,?\n'
934948 ]
935949
936950 removed_count = 0
@@ -992,8 +1006,10 @@ def _backup_pioarduino_build_py(self) -> None:
9921006 if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
9931007 return
9941008
995- build_py_path = join (self .config .arduino_libs_mcu , "pioarduino-build.py" )
996- backup_path = join (self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1009+ if not self .config .arduino_libs_mcu :
1010+ return
1011+ build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1012+ backup_path = str (Path (self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
9971013
9981014 if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
9991015 shutil .copy2 (build_py_path , backup_path )
@@ -1007,7 +1023,7 @@ class BackupManager:
10071023 framework build scripts, ensuring that original files can be restored
10081024 when needed or when builds are cleaned.
10091025 """
1010-
1026+
10111027 def __init__ (self , config : ComponentManagerConfig ):
10121028 """
10131029 Initialize the backup manager with configuration access.
@@ -1019,7 +1035,7 @@ def __init__(self, config: ComponentManagerConfig):
10191035 config: Configuration manager instance providing access to paths
10201036 """
10211037 self .config = config
1022-
1038+
10231039 def backup_pioarduino_build_py (self ) -> None :
10241040 """
10251041 Create backup of the original pioarduino-build.py file.
@@ -1030,13 +1046,13 @@ def backup_pioarduino_build_py(self) -> None:
10301046 """
10311047 if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
10321048 return
1033-
1034- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
1035- backup_path = join ( self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1036-
1049+
1050+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1051+ backup_path = str ( Path ( self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
1052+
10371053 if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
10381054 shutil .copy2 (build_py_path , backup_path )
1039-
1055+
10401056 def restore_pioarduino_build_py (self , target = None , source = None , env = None ) -> None :
10411057 """
10421058 Restore the original pioarduino-build.py from backup.
@@ -1050,9 +1066,9 @@ def restore_pioarduino_build_py(self, target=None, source=None, env=None) -> Non
10501066 source: Build source (unused, for PlatformIO compatibility)
10511067 env: Environment (unused, for PlatformIO compatibility)
10521068 """
1053- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
1054- backup_path = join ( self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1055-
1069+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1070+ backup_path = str ( Path ( self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
1071+
10561072 if os .path .exists (backup_path ):
10571073 shutil .copy2 (backup_path , build_py_path )
10581074 os .remove (backup_path )
0 commit comments