@@ -51,7 +51,12 @@ def exec_git(*args: str, ignore_errors: bool = False) -> str:
5151
5252
5353def get_git_directory_path () -> Path :
54- """Returns the path to the git directory."""
54+ """
55+ Returns the path to the git dir.
56+
57+ Returns:
58+ Absolute path to .git dir.
59+ """
5560 pwd = Path .cwd ()
5661
5762 git_dir = exec_git ("-C" , str (pwd ), "rev-parse" , "--git-dir" ).rstrip ()
@@ -65,29 +70,66 @@ def get_git_directory_path() -> Path:
6570
6671
6772def get_autohooks_directory_path () -> Path :
68- """Returns the absolute path to the package."""
73+ """
74+ Returns the path to package dir.
75+
76+ Returns:
77+ Absolute path to package dir.
78+ """
79+
6980 return Path (__file__ ).resolve ().parent
7081
7182
7283def get_git_hook_directory_path (git_dir_path : Optional [Path ] = None ) -> Path :
73- """Returns the absolute path of the git hooks dir."""
84+ """
85+ Returns the absolute path to git hooks dir.
86+
87+ Args:
88+ git_dir_path: Path to .git dir.
89+
90+ Returns:
91+ Absolute path to git hooks dir.
92+ """
93+
7494 if git_dir_path is None :
7595 git_dir_path = get_git_directory_path ()
7696 return git_dir_path / "hooks"
7797
7898
7999def is_project_root (path : Path ) -> bool :
80- """Checks if the current dir is the project root dir."""
100+ """
101+ Checks if the given dir is the project root dir.
102+ The dir is considered a project root if it contains any of:
103+ - pyproject.toml
104+ - .git dir
105+ - setup.py
106+ - setup.cfg
107+
108+ Args:
109+ path: Path object to check for project root
110+
111+ Returns:
112+ True if path is project root, False else
113+ """
114+
81115 return (
82116 (path / "pyproject.toml" ).is_file ()
83117 or (path / ".git" ).is_dir ()
84118 or (path / "setup.py" ).is_file ()
85119 or (path / "setup.cfg" ).is_file ()
86120 )
87121
88-
89122def get_project_root_path (path : Optional [Path ] = None ) -> Path :
90- """Returns the path to the project root dir."""
123+ """
124+ Returns the path to the project root dir.
125+
126+ Args:
127+ path: Path to the current working dir.
128+
129+ Returns:
130+ Absolute path to the project root dir.
131+ """
132+
91133 if path is None :
92134 path = Path .cwd ()
93135
@@ -104,24 +146,44 @@ def get_project_root_path(path: Optional[Path] = None) -> Path:
104146
105147
106148def get_project_autohooks_plugins_path (path : Optional [Path ] = None ) -> Path :
107- """Returns the path to the plugins folder"""
149+ """
150+ Returns the path to plugins folder.
151+
152+ Args:
153+ path: Path to the current working dir.
154+
155+ Returns:
156+ Absolute path to plugins dir.
157+ """
158+
108159 root = get_project_root_path (path )
109160 return root / ".autohooks"
110161
111162
112163def get_pyproject_toml_path (path : Optional [Path ] = None ) -> Path :
113- """Returns the path to the pyproject.toml"""
164+ """
165+ Returns the path to pyproject.toml.
166+
167+ Args:
168+ path: Path to the current working dir.
169+
170+ Returns:
171+ Absolute path to pyproject.toml.
172+ """
173+
114174 root = get_project_root_path (path )
115175 return root / "pyproject.toml"
116176
117177
118178def is_split_env ():
119- """Checks that environment supports -S option (separate arguments).
179+ """
180+ Checks that environment supports -S option (separate arguments).
120181
121182 Returns:
122183 True: if OS is modern Linux/BSD
123184 False: if OS is older/macOS/Windows
124185 """
186+
125187 try :
126188 subprocess .run (
127189 shlex .split ("/usr/bin/env -S echo True" ),
0 commit comments