API Reference

clang_tools.main

The module containing main entrypoint function.

clang_tools.main.get_parser() ArgumentParser

Get and parser to interpret CLI args.

clang_tools.main.main()

The main entrypoint to the CLI program.

clang_tools.install

The module that performs the installation of clang-tools.

clang_tools.install.RE_PARSE_VERSION = re.compile(b'version\\s([\\d\\.]+)', re.MULTILINE)

This pattern is designed to match only the major version number.

clang_tools.install.clang_tools_binary_url(tool: str, version: str, tag: str = 'master-03a926cf') str

Assemble the URL to the binary.

Parameters:
tool: str

The name of the tool to download.

version: str

The version of the tool to download.

tag: str = 'master-03a926cf'

The release tag used in the base URL.

Returns:

The URL used to download the specified tool.

Create a symlink to the installed binary that doesn’t have the version number appended.

tool_name: str

The name of the clang-tool to symlink.

version: str

The version of the clang-tool to symlink.

install_dir: str

The installation directory to create the symlink in.

overwrite: bool = False

A flag to indicate if an existing symlink should be overwritten.

target: Path = None

The target executable’s path and name for which to create a symlink to. If this argument is not specified (or is None), then the target’s path and name is constructed from the tool_name, version, and install_dir parameters.

A bool describing if the symlink was created.

clang_tools.install.install_clang_tools(version: str, tools: str, directory: str, overwrite: bool, no_progress_bar: bool) None

Wraps functions used to individually install tools.

Parameters:
version: str

The version of the tools to install.

tools: str

The specify tool(s) to install.

directory: str

The installation directory.

overwrite: bool

A flag to indicate if the creation of a symlink has permission to overwrite an existing symlink.

no_progress_bar: bool

A flag used to disable the downloads’ progress bar.

clang_tools.install.install_dir_name(directory: str) str

Automate directory choosing if not explicitly specified by user.

Parameters:
directory: str

The directory that was manually specified in the CLI. If this was not specified, then default values are used depending on the operating system.

Returns:

The install directory name (in absolute form).

clang_tools.install.install_tool(tool_name: str, version: str, directory: str, no_progress_bar: bool) bool

An abstract function that can install either clang-tidy or clang-format.

Parameters:
tool_name: str

The name of the clang-tool to install.

version: str

The version of the tools to install.

directory: str

The installation directory.

no_progress_bar: bool

A flag used to disable the downloads’ progress bar.

Returns:

True if the binary had to be downloaded and installed. False if the binary was not downloaded but is installed in directory.

clang_tools.install.is_installed(tool_name: str, version: str) Path | None

Detect if the specified tool is installed.

Parameters:
tool_name: str

The name of the specified tool.

version: str

The specific version to expect.

Returns:

The path to the detected tool (if found), otherwise None.

clang_tools.install.move_and_chmod_bin(old_bin_name: str, new_bin_name: str, install_dir: str) None

Move download clang-tools binary and move to bin dir with right permission.

Parameters:
old_bin_name: str

The downloaded file’s name.

new_bin_name: str

The desired name of the file after being moved to the install_dir.

install_dir: str

The target installation directory.

clang_tools.install.uninstall_clang_tools(version: str, directory: str)

Uninstall a clang tool of a given version.

Parameters:
version: str

The version of the clang-tools to remove.

directory: str

The directory from which to remove the installed clang-tools.

clang_tools.install.uninstall_tool(tool_name: str, version: str, directory: str)

Remove a specified tool of a given version.

Parameters:
tool_name: str

The name of the clang tool to uninstall.

version: str

The version of the clang-tools to remove.

directory: str

The directory from which to remove the installed clang-tools.

clang_tools.util

A module containing utility functions.

clang_tools.util.check_install_os() str

Identify this Operating System.

Note

This will raise an exception if the detected OS is not supported. Please open an issue at https://github.com/cpp-linter/clang-tools-pip/issues if you encounter an unsupported OS.

Returns:

A lower-case str describing the detected OS.

clang_tools.util.download_file(url: str, file_name: str, no_progress_bar: bool) str | None

Download the given file_name from the given url.

Parameters:
url: str

The URL to download from.

file_name: str

The file name to download.

Returns:

The path to downloaded file if successful, otherwise None.

clang_tools.util.get_sha_checksum(binary_url: str) str

Fetch the SHA512 checksum corresponding to the released binary.

Parameters:
binary_url: str

The URL used to download the binary.

Returns:

A str containing the contents of the SHA512sum file given binary_url.

clang_tools.util.verify_sha512(checksum: str, exe: bytes) bool

Verify the executable binary’s SHA512 hash matches the valid checksum.

Parameters:
checksum: str

The SHA512 checksum.

exe: bytes

The bytes content of the binary executable that is to be verified.

Returns:

True if the exe hash matches the checksum given, otherwise False.