Skip to main content

✨ kconfigstyle

A simple style linter + formatter for Kconfig files, with support for Zephyr and ESP-IDF style conventions.

Lint (reports issues, exits non-zero if any are found):

uvx kconfigstyle Kconfig

Format in place:

uvx kconfigstyle --write --reflow-help --consolidate-empty-lines --max-line-length 80 Kconfig

Before:

# incorrect and inconsistent indentation, spare newline, and unwrapped help text
config FOO_MY_OPTION
  bool "Enable my option" if ANOTHER_OPTION


    help
      Extra long bit of help text that should be reflowed to fit within the maximum line length specified by the style guide.

      This is the second line of the help text.

After:

# properly indented, consolidated newlines, and wrapped help text
config FOO_MY_OPTION
	bool "Enable my option" if ANOTHER_OPTION

	help
	  Extra long bit of help text that should be reflowed to fit within the
	  maximum line length specified by the style guide.

	  This is the second line of the help text.

Background

The "Kconfig language" is defined here:

Zephyr and ESP-IDF both use several extensions in practice, and each maintains its own fork of the original Kconfiglib:

Espressif's fork includes a parser here, however, that is intended to be used on a complete Kconfig setup, not on a per-file basis (i.e. it wants to be able to load in sourced files etc). For the purposes of basic formatting, it's only necessary to parse individual files, so I've implemented a standalone parser for this use case.

Espressif also provides a tool called kconfcheck to check Kconfig syntax/formatting, but it is not very configurable and does not support auto-formatting. kconfigstyle aims to provide a more flexible and user-friendly alternative.

Finally, see here for references on Zephyr and ESP-IDF Kconfig styles:

Installation

Run without installing with uv:

uvx kconfigstyle [options] <kconfig_files>

Or install and run:

pip install kconfigstyle
kconfigstyle [options] <kconfig_files>

Presets

Preset Indent Help indent Max line Other
zephyr (default) tabs tab + 2 spaces 100
espidf 4 spaces +4 spaces 120 hierarchical indent, uppercase configs

Individual options override preset values.

Command Line Options

See kconfigstyle --help for a full list of options. Some notable options include:

  • --preset {zephyr,espidf} Use a style preset (default: zephyr)

  • --write, -w Write formatted output back to files (format mode)

  • --use-spaces Use spaces instead of tabs for indentation

  • --primary-indent PRIMARY_INDENT Number of spaces for primary indentation (default: 4), only applies when --use-spaces is set

  • --help-indent HELP_INDENT Number of extra spaces for help text indentation (default: 2 for Zephyr, 4 for ESP-IDF)

  • --max-line-length MAX_LINE_LENGTH Maximum line length (default: 100 for Zephyr, 120 for ESP-IDF)

  • --max-option-length MAX_OPTION_LENGTH Maximum config option name length (default: 50)

  • --uppercase-configs Require config names to be uppercase

  • --min-prefix-length MIN_PREFIX_LENGTH Minimum prefix length for config names (default: 3; 0 disables the check)

  • --indent-sub-items Use hierarchical indentation for sub-items (ESP-IDF style)

  • --consolidate-empty-lines Consolidate multiple consecutive empty lines into one

  • --reflow-help Reflow help text to fit within max line length

  • --print-formatted Print formatted output to stdout without modifying files

Exit Status

In lint mode (no --write), kconfigstyle exits 1 if any issues are found, otherwise 0. With --write, it exits 0 and reports any remaining issues the formatter can't fix (e.g. naming).

Usage in CI

Lint mode is suitable for CI checks, e.g. in a GitHub Actions workflow:

- uses: astral-sh/setup-uv@v4
- run: uvx kconfigstyle $(git ls-files '*Kconfig*')

License

MIT

Metadata

Release files for kconfigstyle 0.7.0

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

Source distribution (sdist)

Source distribution for kconfigstyle 0.7.0
File Size Uploaded Provenance Actions
kconfigstyle-0.7.0.tar.gz 13.5 kB Without provenance Details for kconfigstyle-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kconfigstyle 0.7.0
File Interpreter ABI Platform Actions
kconfigstyle-0.7.0-py3-none-any.whl Python 3 none any Details for kconfigstyle-0.7.0-py3-none-any.whl

Total release size: 27.5 kB

Release files / kconfigstyle-0.7.0.tar.gz

Download URL kconfigstyle-0.7.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
eebeec6f029efe7127f5821171ac749d15f6722ca48f29de92ce7bdeadd5b1ef
BLAKE2b-256 checksum
How to use checksums
c0fbc4f092f40098825991de55538416e8fc9dc4e81ece361598138f509cc9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / kconfigstyle-0.7.0-py3-none-any.whl

Download URL kconfigstyle-0.7.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c2dac8664330cd10e1c35eccba914a20a03aa467b691faf8dbe0d9df563994e
BLAKE2b-256 checksum
How to use checksums
16a640c5695c13148884208edb7c2eb3c84e1420cc0b150dbfdc8cded5fc5d86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for kconfigstyle 0.7.0

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.

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