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

Config file warning #280

Merged
merged 8 commits into from Sep 3, 2017
9 changes: 8 additions & 1 deletion src/pydocstyle/config.py
Expand Up @@ -256,10 +256,17 @@ def _get_config(self, node):
raise IllegalConfiguration('Configuration file {!r} specified '
'via --config was not found.'
.format(self._run_conf.config))

if None in self._cache:
return self._cache[None]
options, _ = self._read_configuration_file(self._run_conf.config)
config = self._create_check_config(options)

if options is None:
log.warning('Configuration file does not contain a '
'pydocstyle section. Using default configuration.')
config = self._create_check_config(self._options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called for every directory in a project, so a lack of a pydocstyle section should generally be treated by just skipping it and checking the parent directory. If you use the default config, you might screw up the configuration (this might happen if, for example, there's a setup.cfg file for a different tool).

This logic should only be applied if self._run_config.config is not None, i.e., if a specific config file is specified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought this block was in the top level of the method, but in fact it's inside the self._run_config.config check. But add a test for this anyway (a config file in the hierarchy that doesn't have a correct section name).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😸

else:
config = self._create_check_config(options)

# Make the CLI always win
final_config = {}
Expand Down
11 changes: 11 additions & 0 deletions src/tests/test_integration.py
Expand Up @@ -251,6 +251,17 @@ def foo():
assert 'D103' not in err


def test_sectionless_config_file(env):
"""Test that config files without a valid section name issue a warning."""
with env.open('config.ini', 'wt') as conf:
conf.write('[pdcstl]')
config_path = conf.name

_, err, code = env.invoke('--config={}'.format(config_path))
assert code == 0
assert 'Configuration file does not contain a pydocstyle section' in err


def test_config_path(env):
"""Test that options are correctly loaded from a specific config file.

Expand Down