Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Rene Dudfield: setup.cfg - a solution to python config file soup? A howto guide.

$
0
0

Sick of config file soup cluttering up your repo? Me too. However there is a way to at least clean it up for many python tools.

Some of the tools you might use and the config files they support...

flake8 - .flake8 , setup.cfg , tox.ini , and config/flake8 on windows pytest - pytest.ini , tox.ini , setup.cfg coverage.py - .coveragerc , setup.cfg , tox.ini mypy - setup.cfg , mypy.ini tox - tox.ini

Can mypy use setup.cfg as well?

OK, you've convinced me. -- Guido

With that mypy now also supports setup.cfg, and we can all remove many more config files.

The rules for precedence are easy:

read --config-file option - if it's incorrect, exit read [tool].ini - if correct, stop read setup.cfg How to config with setup.cfg?

Here's a list to the configuration documentation for setup.cfg.

coverage config pytest config flake8 config mypy config behave What does a setup.cfg look like now?

Here's an example setup.cfg for you with various tools configured. (note these are nonsensical example configs, not what I suggest you use!)

## http://coverage.readthedocs.io/en/latest/config.html

#[coverage:run]

#timid = True

## http://pytest.org/latest/customize.html#adding-default-options

# [tool:pytest]

# addopts=-v --cov pygameweb pygameweb/ tests/

## http://mypy.readthedocs.io/en/latest/config_file.html

#[mypy]

#python_version = 2.7

#[flake8]

#max-line-length = 120

#max-complexity = 10

#exclude = build,dist,docs/conf.py,somepackage/migrations,*.egg-info

## Run with: pylint --rcfile=setup.cfg somepackage

#[pylint]

#disable = C0103,C0111

#ignore = migrations

#ignore-docstrings = yes

#output-format = colorized


Viewing all articles
Browse latest Browse all 9596

Trending Articles