Skip to content

clang-apply-replacements

PyPI part of cpp-linter

A Python wheel of clang-apply-replacements, the LLVM-based tool that applies serialized clang-tidy fix-it replacements (YAML files) to source files.

Website · Get started · Discussions

Quick start

pip install clang-apply-replacements

The wheel bundles the clang-apply-replacements binary; no LLVM installation is required on the host machine.

Tip

In CI, use pipx run clang-apply-replacements — no install needed. GitHub-hosted runners ship with pipx pre-installed.

Verify:

clang-apply-replacements --version

Usage

clang-tidy --export-fixes writes the fixes it suggests to a YAML file, and clang-apply-replacements applies every .yaml file under the directory you give it. With a compile_commands.json in build/:

mkdir -p fixes
clang-tidy -p build --export-fixes=fixes/main.yaml src/main.cpp
clang-apply-replacements --remove-change-desc-files fixes
  • clang-tidy does not create the fixes directory, so create it first.
  • --remove-change-desc-files deletes the YAML files after applying them. Applying the same file twice edits the source twice and breaks it.

Run clang-apply-replacements --help to see all available options. The clang-tidy documentation describes --export-fixes.

Supported versions

  • PyPI has wheels for LLVM 16 and 17. pip install clang-apply-replacements installs the newest; pip install "clang-apply-replacements==16.*" installs LLVM 16.
  • Wheels exist for Linux (x86-64, x86, ARM64 and ARMv7 with glibc; x86-64 and x86 with musl), macOS (x86-64 and ARM64) and Windows (x86-64 and x86). On other platforms pip builds the source distribution, which downloads and compiles LLVM.
  • Since 22.1.8, the clang-tidy wheel on PyPI also installs a clang-apply-replacements command. In an environment with both packages, the one installed last provides the command, and uninstalling either one removes it.
  • For other LLVM versions, the static binaries include clang-apply-replacements for LLVM 12 to 23.

Contributing

See CONTRIBUTING.md for development setup, build instructions, and the release process, and use GitHub issues for bug reports and feature requests.

License

This project is licensed under the Apache License 2.0 - see LICENSE.md for details. The clang-apply-replacements binary bundled in the wheels is part of the LLVM Project and is licensed under the Apache License 2.0 with LLVM Exceptions.

About

clang-apply-replacements Python wheels

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages