1111
1212
1313def get_version_from_dependency (tool : str ) -> Optional [str ]:
14+ """Get the version of a tool from the pyproject.toml dependencies."""
1415 pyproject_path = Path (__file__ ).parent .parent / "pyproject.toml"
1516 if not pyproject_path .exists ():
1617 return None
@@ -108,6 +109,7 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
108109
109110
110111def _resolve_version (versions : List [str ], user_input : Optional [str ]) -> Optional [str ]:
112+ """Resolve the version based on user input and available versions."""
111113 if user_input is None :
112114 return None
113115 try :
@@ -131,6 +133,7 @@ def _resolve_version(versions: List[str], user_input: Optional[str]) -> Optional
131133
132134
133135def _get_runtime_version (tool : str ) -> Optional [str ]:
136+ """Get the runtime version of a tool."""
134137 try :
135138 output = subprocess .check_output ([tool , "--version" ], text = True )
136139 if tool == "clang-tidy" :
@@ -144,6 +147,7 @@ def _get_runtime_version(tool: str) -> Optional[str]:
144147
145148
146149def _install_tool (tool : str , version : str ) -> Optional [Path ]:
150+ """Install a tool using pip."""
147151 try :
148152 subprocess .check_call (
149153 [sys .executable , "-m" , "pip" , "install" , f"{ tool } =={ version } " ]
@@ -155,6 +159,7 @@ def _install_tool(tool: str, version: str) -> Optional[Path]:
155159
156160
157161def _resolve_install (tool : str , version : Optional [str ]) -> Optional [Path ]:
162+ """Resolve the installation of a tool, checking for version and installing if necessary."""
158163 user_version = _resolve_version (
159164 CLANG_FORMAT_VERSIONS if tool == "clang-format" else CLANG_TIDY_VERSIONS ,
160165 version ,
@@ -191,6 +196,7 @@ def is_installed(tool: str) -> Optional[Path]:
191196
192197
193198def ensure_installed (tool : str , version : Optional [str ] = None ) -> str :
199+ """Ensure a tool is installed, resolving its version if necessary."""
194200 LOG .info ("Ensuring %s is installed" , tool )
195201 tool_path = _resolve_install (tool , version )
196202 if tool_path :
0 commit comments