Skip to content
项目

关于

从 pyproject.toml 加载配置的 Flake8 插件

其他项目

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

# Flake8-pyproject Flake8 plug-in loading the configuration from pyproject.toml

Flake8 cannot be configured via pyproject.toml, even though virtually all other Python dev tools have adopted it as the central location for project configuration. The discussion of the original proposal (#234) was closed as "too heated", subsequent feature and pull requests were marked as "spam" (#1332, #1421, #1431, #1447, #1501).

Flake8-pyproject also has bad manners and force-feeds Flake8 the spam it so despises. It registers itself as a Flake8 plug-in to seamlessly load the configuration from pyproject.toml when you run the flake8 command in the same folder.

Usage

Say your Flake8 configuration in .flake8 (or in tox.ini, or setup.cfg) is this:

[flake8]
ignore = E231, E241
per-file-ignores =
    __init__.py:F401
max-line-length = 88
count = true

Copy that [flake8] section to pyproject.toml, rename it as [tool.flake8], and convert the key–value pairs to the TOML format:

[tool.flake8]
ignore = ['E231', 'E241']
per-file-ignores = [
    '__init__.py:F401',
]
max-line-length = 88
count = true

Then run flake8 in the project root folder, where pyproject.toml is located.

In case your TOML-based configuration is contained in a different folder, or the file has a different name, specify the location with the --toml-config command-line option.

For compatibility with earlier versions of this package, and perhaps extra reliability in terms of possible future breakage of the plug-in hook, the package also provides a flake8p command that could be called alternatively.

Implementation

Flake8 uses RawConfigParser from the standard library to parse its configuration files, and therefore expects them to have the INI format.

This library hooks into Flake8's plug-in mechanism to load the configuration from pyproject.toml instead, if it finds such a file in the current folder (working directory). It then creates a RawConfigParser instance, converting from the TOML input format, and passes it on to Flake8 while discarding configuration options that would otherwise be sourced from elsewhere.

As of Python 3.11, a TOML parser is part of the standard library (PEP 680). On older Python installations, we rely on Tomli.

A few very simple integration tests round out the package, making sure that any one of the possible configuration files are in fact accepted when pyproject.toml isn't found.

release coverage

探索相关项目

加载中…