Skip to main content

Simple formatter for Kconfig files

Project description

✨ kconfigstyle

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

Example:

 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 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 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:

There's several extensions used in practice by Zephyr + ESP-IDF; both projects maintain their own forks of the original kconfiglib library:

Espressif has an excellent documentation page here about their fork of Kconfiglib:

Which 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>

Command Line Options

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

  • --preset {zephyr,espidf} Use a style preset (individual options override preset values)

  • --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)

  • --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 for ESP-IDF)

  • --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

License

See LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kconfigstyle-0.6.2.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kconfigstyle-0.6.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file kconfigstyle-0.6.2.tar.gz.

File metadata

  • Download URL: kconfigstyle-0.6.2.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kconfigstyle-0.6.2.tar.gz
Algorithm Hash digest
SHA256 f20f3ae9991b7d481e3c0ae4659a493d2d5ecf5a5dc682b9f1f9583d9f089b6e
MD5 00fc517b1faa9efb32f634462fa3fafe
BLAKE2b-256 9925f37d19359f2b45840f5298a1af7239d920b9de171814ec76854096ea3a07

See more details on using hashes here.

File details

Details for the file kconfigstyle-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: kconfigstyle-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kconfigstyle-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a84d14f7e3afc9cf99654c8c8009ecb21deabb283cd82d446ad8b5550d61d4c
MD5 3f229a4633c7d500042ca2fb07914ef3
BLAKE2b-256 3a7a8ee1e1f44cd63d2fda66c207504233bc512f5e0b61daa4cd59cba529e32c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page