@@ -55,13 +55,73 @@ def _get_npm_package_path(package_name: str) -> Optional[str]:
5555 debug_log (f"Error getting npm package path for { package_name } : { e } " )
5656 return None
5757
58+ def _get_c_package_path (package_name : str ) -> Optional [str ]:
59+ """
60+ Finds the local installation path of a C package.
61+ """
62+ try :
63+ debug_log (f"Getting local path for C package: { package_name } " )
64+
65+ # Try using pkg-config to find the package
66+ try :
67+ result = subprocess .run (
68+ ["pkg-config" , "--variable=includedir" , package_name ],
69+ capture_output = True ,
70+ text = True ,
71+ timeout = 5
72+ )
73+ if result .returncode == 0 and result .stdout .strip ():
74+ include_dir = Path (result .stdout .strip ())
75+ package_path = include_dir / package_name
76+ if package_path .exists ():
77+ return str (package_path .resolve ())
78+ if include_dir .exists ():
79+ return str (include_dir .resolve ())
80+ except (subprocess .TimeoutExpired , FileNotFoundError ):
81+ debug_log (f"pkg-config not available or timed out for { package_name } " )
82+
83+ # Search in standard system include directories
84+ common_include_paths = [
85+ "/usr/include" ,
86+ "/usr/local/include" ,
87+ "/opt/homebrew/include" ,
88+ "/opt/local/include" ,
89+ Path .home () / ".local" / "include" ,
90+ ]
91+
92+ for base_path in common_include_paths :
93+ base_path = Path (base_path )
94+ if not base_path .exists ():
95+ continue
96+
97+ # Check if package exists as a directory
98+ package_dir = base_path / package_name
99+ if package_dir .exists () and package_dir .is_dir ():
100+ return str (package_dir .resolve ())
101+
102+ # Check for header files with package name
103+ header_file = base_path / f"{ package_name } .h"
104+ if header_file .exists ():
105+ return str (header_file .resolve ())
106+
107+ # Check current directory for local installations
108+ local_package = Path (f"./{ package_name } " )
109+ if local_package .exists ():
110+ return str (local_package .resolve ())
111+
112+ return None
113+ except Exception as e :
114+ debug_log (f"Error getting C package path for { package_name } : { e } " )
115+ return None
116+
58117def get_local_package_path (package_name : str , language : str ) -> Optional [str ]:
59118 """
60119 Dispatches to the correct package path finder based on the language.
61120 """
62121 finders = {
63122 "python" : _get_python_package_path ,
64123 "javascript" : _get_npm_package_path ,
124+ "c" : _get_c_package_path ,
65125 }
66126 finder = finders .get (language )
67127 if finder :
0 commit comments