diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 5bd3613..95277fa 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -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: @@ -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 diff --git a/src/docformatter/configuration.py b/src/docformatter/configuration.py index c8046c8..c4d8217 100644 --- a/src/docformatter/configuration.py +++ b/src/docformatter/configuration.py @@ -60,6 +60,7 @@ class Configurater: """Dictionary of configuration file arguments.""" configuration_file_lst = [ + ".docformatter.toml", "pyproject.toml", "setup.cfg", "tox.ini", @@ -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: diff --git a/tests/test_configuration_functions.py b/tests/test_configuration_functions.py index f93721d..c765fa7 100644 --- a/tests/test_configuration_functions.py +++ b/tests/test_configuration_functions.py @@ -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): @@ -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",