Skip to main content

flake8-ruler

CLI tool to generate a flake8 (setup.cfg) from a nicer, modern, more powerful, flakehell-inspired (and 100% compatible) config (pyproject.toml).

Features:

  • TOML: type-safe, syntax-highlighted, well standartized config format.
  • Powerful per-plugin codes configuration.
  • Glob patterns.
  • Extending and merging multiple configs, shared configurations.
  • Remote configs.
  • Predefined configs for bugs, security, styleguides.

Getting started

Install:

python3 -m pip install flake8-ruler

Create pyproject.toml:

# you can add in this section any options supported by flake8
[tool.flake8_ruler]
max_line_length = 90

[tool.flake8_ruler.plugins]
# include everything in pyflakes except F401
pyflakes = ["+*", "-F401"]
# enable only codes from S100 to S199
flake8-bandit = ["-*", "+S1??"]
# enable everything that starts from `flake8-`
"flake8-*" = ["+*"]
# explicitly disable a plugin
flake8-docstrings = ["-*"]

Convert pyproject.toml into setup.cfg:

python3 -m flake8_ruler

Done! Now, you can just run flake8 and it will automatically use the newly generated config.

Plugins

In pyproject.toml you can specify [tool.flake8_ruler.plugins] table. It's a key-value of flake8 plugins and associated to them rules.

Key can be exact plugin name or wildcard template. For example "flake8-commas" or "flake8-*". The tool will choose the longest match for every plugin if possible. In the previous example, flake8-commas will match to the first pattern, flake8-bandit and flake8-bugbear to the second, and pycodestyle will not match to any pattern.

Value is a list of templates for error codes for this plugin. First symbol in every template must be + (include) or - (exclude). The latest matched pattern wins. For example, ["+*", "-F*", "-E30?", "-E401"] means "Include everything except all checks that starts with F, check from E301 to E310, and E401".

Codes

An error code is added into the generated setup.cfg only if the following conditions match:

  1. The plugin is installed in the same environment as flake8-ruler.
  2. The code is detected by flake8-codes. If not, please, contribute.
  3. The code is enabled in [tool.flake8_ruler.plugins].

Use flake8-codes to find out the supported error codes for a plugin:

python3 -m pip install flake8-codes
python3 -m flake8_codes

Inheritance

Option base allows to specify base config from which you want to inherit this one. It can be path to local config or remote URL. You can specify one path or list of paths as well. For example:

base = [
    "https://raw.githubusercontent.com/orsinium-labs/flake8-ruler/master/pyproject.toml",
    ".flake8-ruler.toml",
]
max_line_length = 90

In this example, flake8-ruler will read remote config, local config (.flake8-ruler.toml), and then current config. So, even if max_line_length is specified in some of base configs, it will be overwritten by max_line_length = 90 from the current config.

You can find some predefined configs in ./configs/ directory.

Resources

Release files for flake8_ruler 0.1.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 flake8_ruler 0.1.0
File Size Uploaded
flake8_ruler-0.1.0.tar.gz 11.4 kB Details

Built distribution (wheel)

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

Total release size: 19.6 kB

Release files / flake8_ruler-0.1.0.tar.gz

Download URL flake8_ruler-0.1.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e3cd0698ffc16eb61a4bef5c3c96277032170ce71d67368297c23ff1b0b80728
BLAKE2b-256 checksum
How to use checksums
2cb4052ef23e560df60f45a917de01e69c4c3ee2aed7728e9f8885c2022c6679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / flake8_ruler-0.1.0-py3-none-any.whl

Download URL flake8_ruler-0.1.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcff2ed873dcb5a35c661c2fb1068ceca0ef75b7d5b5d3cf4073db2ad6c43263
BLAKE2b-256 checksum
How to use checksums
6d950ce49a81f9363025c2f03827304f03c5605d506af49eca9c56a0e9bee866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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