Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve configuration file precedence issue #252

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 12 additions & 3 deletions src/docformatter/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,18 @@ def __init__(self, args: List[Union[bool, int, str]]) -> None:
self.config_file = self.args_lst[self.args_lst.index("--config") + 1]
except ValueError:
for _configuration_file in self.configuration_file_lst:
if os.path.isfile(_configuration_file):
self.config_file = f"./{_configuration_file}"
break
_config_section: str = (
"[tool.docformatter]"
if _configuration_file == "pyproject.toml"
else "[docformatter]"
)
_config_file_path: str = f"./{_configuration_file}"
if os.path.isfile(_config_file_path):
with open(_config_file_path, "r") as _config_file:
_config = _config_file.read()
if _config_section in _config:
self.config_file = _config_file_path
break

if os.path.isfile(self.config_file):
self._do_read_configuration_file()
Expand Down