Skip to content

Commit 89c1672

Browse files
committed
add docstring to util
1 parent 90a453d commit 89c1672

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cpp_linter_hooks/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
def 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

110111
def _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

133135
def _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

146149
def _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

157161
def _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

193198
def 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

Comments
 (0)