Skip to main content

clang-format-swig

clang-format for SWIG .i interface files.

Why

SWIG .i files are mostly C/C++ with a handful of SWIG-specific directives sprinkled in (lines that start with %):

%module mylib

%{
#include "mylib.h"
%}

%include "typemaps.i"

%typemap(in) MyStruct * {
    if (!convert($input, &$1)) return NULL;
}

Running clang-format directly on these files produces broken output because:

  • %{ and %} contain braces that shift clang-format's tracked brace depth, causing everything after them to be indented as if inside a block.
  • %module is parsed as a C++20 module declaration, altering scope state for all subsequent code.

The C/C++ content (the bulk of every .i file) ends up incorrectly indented or not formatted at all.

How it works

Before passing the file to clang-format, each %-prefixed line is swapped for a #pragma placeholder:

Original Placeholder
%module my_lib #pragma SWIG_3F9A12_0
%{ #pragma SWIG_3F9A12_1
%} #pragma SWIG_3F9A12_2

#pragma lines are preserved verbatim by clang-format and have no effect on brace depth or scope, so all surrounding C/C++ is formatted correctly. Afterwards the placeholders are replaced back with the original % lines.

Your .clang-format config is fully respected: clang-format-swig is a thin wrapper, not a reimplementation. It is written in Go and compiles to a single static binary, so it can ship through any package registry without requiring a runtime or build toolchain on the target system.

Installation

Pick whichever channel fits your stack, every install resolves to the same Go binary.
If there's no distribution available for your platform architecture, you can open a feature request.

clang-format must be installed separately and be on PATH. Install it however you'd normally get LLVM tooling on your platform (e.g. apt install clang-format, brew install clang-format, winget install LLVM.LLVM, uv tool install clang-format, npm install -g clang-format, ...).

Go

go install github.com/Avasam/clang-format-swig@latest

Requires Go (see go.mod for the minimum version).

pre-commit

Add to your .pre-commit-config.yaml:

# Requires having clang-format pre-installed and available on PATH
# Has go installation and build overhead
- repo: https://github.com/Avasam/clang-format-swig
  rev: vX.X.X
  hooks:
    - id: clang-format-swig

or

# Has Python installation overhead
- repo: local
  hooks:
    - id: clang-format-swig
      name: clang-format SWIG files
      language: python
      entry: clang-format-swig
      files: \.i$
      additional_dependencies:
        - clang-format-swig==X.X.X
        - clang-format==X.X.X

Python

uv tool install clang-format-swig

The platform binary is bundled in the wheel.

Node.js

npm install -g clang-format-swig

The platform binary is fetched as an optional dependency, so no install-time scripts run.

.NET

dotnet tool install -g clang-format-swig

See TargetFramework in clang-format-swig.csproj for the minimum .NET runtime. The platform binary is embedded in the package and extracted to your user cache on first run.

Usage

# Format files in-place
clang-format-swig src/mylibrary.i

# Format multiple files
clang-format-swig **/*.i

# Check without writing (useful in CI)
clang-format-swig --check **/*.i

# Print version
clang-format-swig --version

clang-format-swig exits 0 if no files were changed (or --check found nothing to change), and 1 if any file was reformatted (or would be reformatted under --check).

clang-format itself must be on PATH; the wrapper does not vendor it.

pre-commit usage

Once the hook is configured, it runs automatically on staged .i files:

pre-commit run clang-format-swig --all-files

LLM / Coding Agent disclaimer: This project was initially scaffolded with Claude (Sonnet 4.6 and Opus 4.7) from a Python proof of concept script. The initial project layout and Go script were machine-generated. Every change is reviewed by a human before being merged.

Metadata

Release files for clang-format-swig 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for clang-format-swig 0.0.1
File Actions
clang_format_swig-0.0.1-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for clang_format_swig-0.0.1-py3-none-win_arm64.whl
clang_format_swig-0.0.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for clang_format_swig-0.0.1-py3-none-win_amd64.whl
clang_format_swig-0.0.1-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for clang_format_swig-0.0.1-py3-none-manylinux_2_17_x86_64.whl
clang_format_swig-0.0.1-py3-none-manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for clang_format_swig-0.0.1-py3-none-manylinux_2_17_aarch64.whl
clang_format_swig-0.0.1-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for clang_format_swig-0.0.1-py3-none-manylinux2014_x86_64.whl
clang_format_swig-0.0.1-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for clang_format_swig-0.0.1-py3-none-manylinux2014_aarch64.whl
clang_format_swig-0.0.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for clang_format_swig-0.0.1-py3-none-macosx_11_0_arm64.whl
clang_format_swig-0.0.1-py3-none-macosx_10_9_x86_64.whl Python 3 none macOS 10.9+ x86-64 Details for clang_format_swig-0.0.1-py3-none-macosx_10_9_x86_64.whl

Total release size: 5.9 MB

Release files / clang_format_swig-0.0.1-py3-none-win_arm64.whl

Download URL clang_format_swig-0.0.1-py3-none-win_arm64.whl
Size 729.4 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
1164f1a56d3546240fa6da47dd8be1499888ef2bc663a63b53735b63f259a6fc
BLAKE2b-256 checksum
How to use checksums
a864e52189ccfe4dcc5a289c2cb7e4137349f7e2e5a87605e2ad4be59c19360e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-win_amd64.whl

Download URL clang_format_swig-0.0.1-py3-none-win_amd64.whl
Size 789.7 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
7f610f8a6f1a2e6c671176fff32ef90609c08ef13b26cab61d77e0b95fdaf815
BLAKE2b-256 checksum
How to use checksums
0619e47cc49d2a889568406b1c5ce8aa9ca77da18eaa63c60fbe87da3f60f5c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-manylinux_2_17_x86_64.whl

Download URL clang_format_swig-0.0.1-py3-none-manylinux_2_17_x86_64.whl
Size 738.4 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
417e52ebbfdb7b85b841b09c4b839abc039aab0955e7f0fa5b9bb430751f8a18
BLAKE2b-256 checksum
How to use checksums
5d927e6a08a1cf13cee0b7a887bb77c1041881bed91ce530f26a982dc1b825cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-manylinux_2_17_aarch64.whl

Download URL clang_format_swig-0.0.1-py3-none-manylinux_2_17_aarch64.whl
Size 685.4 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
55473db1605590c8fd36b1e45867634a7a5e718b5ba6a5a06fd60ca21c739ba9
BLAKE2b-256 checksum
How to use checksums
7890f6e9608da6d479d3806547cb61872e025d1b0d74d0edcee21ee1a5360e52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-manylinux2014_x86_64.whl

Download URL clang_format_swig-0.0.1-py3-none-manylinux2014_x86_64.whl
Size 738.4 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
7a41ef1c248a01760d37ad8a1606831e5a82ccc4d603b9a12e7316f71bac64cc
BLAKE2b-256 checksum
How to use checksums
5878e45eb2adf59b8d68b33d1a6ff6fa1ced4e381c73fdef13c911adb0eaa52a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-manylinux2014_aarch64.whl

Download URL clang_format_swig-0.0.1-py3-none-manylinux2014_aarch64.whl
Size 685.4 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
7a288c748ea6063f277d1ceb27b2dfe9e9834ab9f6bccc26fe93bec2f4e89e7e
BLAKE2b-256 checksum
How to use checksums
004c2ced83c9709a3f54a0f280c7bce41172b82ab623f6aa2c9e74f9c53a13e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-macosx_11_0_arm64.whl

Download URL clang_format_swig-0.0.1-py3-none-macosx_11_0_arm64.whl
Size 756.8 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8df11b77c252b581803c61fc75df2faff6eb22707d2e0e37cffe05cdc95bc5bb
BLAKE2b-256 checksum
How to use checksums
6655854c997102e0af009e5986a5f937e33b5193add525080da9c2668275e07b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clang_format_swig-0.0.1-py3-none-macosx_10_9_x86_64.whl

Download URL clang_format_swig-0.0.1-py3-none-macosx_10_9_x86_64.whl
Size 762.2 kB
Tags Python 3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
fc43898e37c395951a6c58154958b99075de3430630528f4fbfd999ea8c8f4d4
BLAKE2b-256 checksum
How to use checksums
06f58a56e175b697026adc6e4511291abcbd635776a1c682fc6cd70b622f9985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for clang-format-swig 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

8 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page