@@ -20,16 +20,10 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
2020 return None
2121 with open (pyproject_path , "rb" ) as f :
2222 data = tomllib .load (f )
23- # First try project.optional-dependencies.tools
24- optional_deps = data .get ("project" , {}).get ("optional-dependencies" , {})
25- tools_deps = optional_deps .get ("tools" , [])
26- for dep in tools_deps :
27- if dep .startswith (f"{ tool } ==" ):
28- return dep .split ("==" )[1 ]
29-
30- # Fallback to project.dependencies for backward compatibility
31- dependencies = data .get ("project" , {}).get ("dependencies" , [])
32- for dep in dependencies :
23+ # Check build-system.requires
24+ build_system = data .get ("build-system" , {})
25+ requires = build_system .get ("requires" , [])
26+ for dep in requires :
3327 if dep .startswith (f"{ tool } ==" ):
3428 return dep .split ("==" )[1 ]
3529 return None
@@ -148,20 +142,6 @@ def parse_version(v: str):
148142 return None
149143
150144
151- def _get_runtime_version (tool : str ) -> Optional [str ]:
152- """Get the runtime version of a tool."""
153- try :
154- output = subprocess .check_output ([tool , "--version" ], text = True )
155- if tool == "clang-tidy" :
156- lines = output .strip ().splitlines ()
157- if len (lines ) > 1 :
158- return lines [1 ].split ()[- 1 ]
159- elif tool == "clang-format" :
160- return output .strip ().split ()[- 1 ]
161- except Exception :
162- return None
163-
164-
165145def _install_tool (tool : str , version : str ) -> Optional [Path ]:
166146 """Install a tool using pip."""
167147 try :
@@ -187,31 +167,4 @@ def _resolve_install(tool: str, version: Optional[str]) -> Optional[Path]:
187167 else DEFAULT_CLANG_TIDY_VERSION
188168 )
189169
190- path = shutil .which (tool )
191- if path :
192- runtime_version = _get_runtime_version (tool )
193- if runtime_version and user_version not in runtime_version :
194- LOG .info (
195- "%s version mismatch (%s != %s), reinstalling..." ,
196- tool ,
197- runtime_version ,
198- user_version ,
199- )
200- return _install_tool (tool , user_version )
201- return Path (path )
202-
203170 return _install_tool (tool , user_version )
204-
205-
206- def is_installed (tool : str ) -> Optional [Path ]:
207- """Check if a tool is installed and return its path."""
208- path = shutil .which (tool )
209- if path :
210- return Path (path )
211- return None
212-
213-
214- def ensure_installed (tool : str , version : Optional [str ] = None ) -> None :
215- """Ensure a tool is installed, resolving its version if necessary."""
216- if version is not None :
217- _install_tool (tool , version )
0 commit comments