File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed
Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -23,25 +23,19 @@ class LanguageConfig:
2323 exclude_files : list [str ] = Factory (list )
2424 """Files that indicate a directory should not be considered a project root for this language."""
2525
26- def find_project_root (self , file_path : Path ) -> Path | None :
27- """Find the project root directory for the given file path.
28-
29- Args:
30- file_path (Path): The file path to check.
31- Returns:
32- Path | None: The project root directory if found, otherwise None.
33- """
34-
35- if not file_path .is_file ():
36- raise ValueError (f"Expected a file path, got: { file_path } " )
26+ def _find_project_root (self , dir_path : Path ) -> Path | None :
27+ for project_path in (dir_path , * dir_path .parents ):
28+ if any ((project_path / excl ).exists () for excl in self .exclude_files ):
29+ return
30+ if any ((project_path / proj ).exists () for proj in self .project_files ):
31+ return project_path
3732
38- if not any (file_path .name .endswith (suffix ) for suffix in self .suffixes ):
39- return
33+ return dir_path
4034
41- for parent in file_path .parents :
42- if any ((parent / excl ).exists () for excl in self .exclude_files ):
35+ def find_project_root (self , path : Path ) -> Path | None :
36+ if path .is_file ():
37+ if not any (path .name .endswith (suffix ) for suffix in self .suffixes ):
4338 return
44- if any ((parent / proj ).exists () for proj in self .project_files ):
45- return parent
39+ path = path .parent
4640
47- return file_path . parent
41+ return self . _find_project_root ( path )
You can’t perform that action at this time.
0 commit comments