Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ How to Configure docformatter
=============================

The command line options for ``docformatter`` can also be stored in a
configuration file. Currently only ``pyproject.toml``, ``setup.cfg``, and
configuration file. The files ``.docformatter.toml``, ``pyproject.toml``, ``setup.cfg``, and
``tox.ini`` are supported. The configuration file can be passed with a full
path. For example:

Expand All @@ -12,9 +12,9 @@ path. For example:

If no configuration file is explicitly passed, ``docformatter`` will search
the current directory for the supported files and use the first one found.
The order of precedence is ``pyproject.toml``, ``setup.cfg``, then ``tox.ini``.
The order of precedence is ``.docformatter.toml``, ``pyproject.toml``, ``setup.cfg``, then ``tox.ini``.

In ``pyproject.toml``, add a section ``[tool.docformatter]`` with
In ``.docformatter.toml`` or ``pyproject.toml``, add a section ``[tool.docformatter]`` with
options listed using the same name as command line argument. For example:

.. code-block:: yaml
Expand Down
15 changes: 3 additions & 12 deletions src/docformatter/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Configurater:
"""Dictionary of configuration file arguments."""

configuration_file_lst = [
".docformatter.toml",
"pyproject.toml",
"setup.cfg",
"tox.ini",
Expand Down Expand Up @@ -372,19 +373,9 @@ def do_parse_arguments(self) -> None:
def _do_read_configuration_file(self) -> None:
"""Read docformatter options from a configuration file."""
argfile = os.path.basename(self.config_file)
for f in self.configuration_file_lst:
if argfile == f:
break

fullpath, ext = os.path.splitext(self.config_file)
filename = os.path.basename(fullpath)

if ext == ".toml" and filename == "pyproject":
if argfile in (".docformatter.toml", "pyproject.toml"):
self._do_read_toml_configuration()

if (ext == ".cfg" and filename == "setup") or (
ext == ".ini" and filename == "tox"
):
elif argfile in ("setup.cfg", "tox.ini"):
self._do_read_parser_configuration()

def _do_read_toml_configuration(self) -> None:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_configuration_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ def test_do_read_configuration_file(config_file):
class TestConfigurater:
"""Class for testing configuration functions."""

@pytest.mark.parametrize("explicit", [False, True])
def test_dedicated_toml(self, tmp_path, monkeypatch, explicit):
monkeypatch.chdir(tmp_path)
(tmp_path / ".docformatter.toml").write_text(
"[tool.docformatter]\nwrap-summaries = 43\n"
)
(tmp_path / "pyproject.toml").write_text(
"[tool.docformatter]\nwrap-summaries = 71\n"
)
options = ["--config", "pyproject.toml"] if explicit else []
config = Configurater(["docformatter", *options, "-"])
config.do_parse_arguments()
assert config.args.wrap_summaries == (71 if explicit else 43)

@pytest.mark.integration
@pytest.mark.order(0)
def test_initialize_configurator_with_default(self):
Expand Down Expand Up @@ -157,6 +171,7 @@ def test_initialize_configurator_with_pyproject_toml(self):
assert uut.args_lst == argb
assert uut.config_file == "./tests/_data/pyproject.toml"
assert uut.configuration_file_lst == [
".docformatter.toml",
"pyproject.toml",
"setup.cfg",
"tox.ini",
Expand Down
Loading