Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 44f1dd1

Browse files
committed
Merge pull request #138 from farmersez/nested-config-files
#133 - Better handling of configuration from files and CLI.
2 parents 44f462d + ba06aaa commit 44f1dd1

File tree

6 files changed

+1098
-201
lines changed

6 files changed

+1098
-201
lines changed

docs/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ New Features
2222
will now be checked by default instead of D203, which required a single
2323
blank line before a class docstring (#137).
2424

25+
* Configuration files are now handled correctly. The closer a configuration file
26+
is to a checked file the more it matters.
27+
Configuration files no longer support ``explain``, ``source``, ``debug``,
28+
``verbose`` or ``count`` (#133).
29+
2530
Bug Fixes
2631

2732
* On Python 2.x, D302 ("Use u""" for Unicode docstrings") is not reported

docs/snippets/cli.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _cli_usage:
2+
13
Usage
24
^^^^^
35

docs/snippets/config.rst

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
1-
``pep257`` looks for a config file in the root of the project (the common
2-
prefix of all checked files) and goes up in the directory tree until it finds
3-
one of the following files (in this order):
1+
``pep257`` supports `ini`-like configuration files. In order for ``pep257`` to
2+
use it, it must be named ``setup.cfg``, ``tox.ini`` or ``.pep257`` and have
3+
a ``[pep257]`` section.
44

5-
* ``setup.cfg``
6-
* ``tox.ini``
7-
* ``.pep257``
5+
When searching for a configuration file, ``pep257`` looks for one of the file
6+
specified above `in that exact order`. If a configuration file was not found,
7+
it keeps looking for one up the directory tree until one is found or uses
8+
the default configuration.
89

9-
The first found file is read, and configurations in the ``[pep257]`` section
10-
are used, if such a section exists.
10+
Available Options
11+
#################
12+
13+
Not all configuration options are available in the configuration files.
14+
Available options are:
15+
16+
* ``convention``
17+
* ``select``
18+
* ``ignore``
19+
* ``add_select``
20+
* ``add_ignore``
21+
* ``match``
22+
* ``match_dir``
23+
24+
See the :ref:`cli_usage` section for more information.
25+
26+
Inheritance
27+
###########
28+
29+
By default, when finding a configuration file, ``pep257`` tries to inherit
30+
the parent directory's configuration and merge them to the local ones.
31+
32+
The merge process is as follows:
33+
34+
* If one of ``select``, ``ignore`` or ``convention`` was specified in the child
35+
configuration - Ignores the parent configuration and set the new error codes
36+
to check. Othewise, Simply copies the parent checked error codes.
37+
* If ``add-ignore`` or ``add-select`` were specified, adds or removes the
38+
specified error codes from the checked error codes list.
39+
* If ``match`` or ``match-dir`` were specified - use them. Otherwise, use the
40+
parent's.
41+
42+
In order to disable this (useful for configuration files located in your repo's
43+
root), simply add ``inherit=false`` to your configuration file.
44+
45+
46+
.. note::
47+
48+
If any of ``select``, ``ignore`` or ``convention`` were specified in
49+
the CLI, the configuration files will take no part in choosing which error
50+
codes will be checked. ``match`` and ``match-dir`` will still take effect.
1151

1252
Example
1353
#######
1454

1555
.. code::
1656
1757
[pep257]
18-
verbose = true
58+
inherit = false
1959
ignore = D100,D203,D405
20-
explain = true
60+
match = *.py
2161

0 commit comments

Comments
 (0)