mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-05 12:36:54 +00:00
Re-allow for relative paths for exclude
Previously, all testing was done from the directory in which the configuration file lived, so this bug went unnoticed. However, if you run Flake8 against its own source from a directory above, you would notice that the patterns in the exclude config value in tox.ini were ignored. This is because we (like any reasonable person) are using relative paths. The path is relative, however, to the directory in which the configuration file was located. So we keep track of which directory that is and use that to normalize the paths in the config file. Yes, there is an unrelated change to our tox.ini in this commit as well. ;-) Closes #194
This commit is contained in:
parent
e619fd3b20
commit
63f5f15068
4 changed files with 34 additions and 15 deletions
|
|
@ -43,6 +43,8 @@ class ConfigFileFinder(object):
|
|||
# List of filenames to find in the local/project directory
|
||||
self.project_filenames = ('setup.cfg', 'tox.ini', self.program_config)
|
||||
|
||||
self.local_directory = os.path.abspath(os.curdir)
|
||||
|
||||
if not args:
|
||||
args = ['.']
|
||||
self.parent = self.tail = os.path.abspath(os.path.commonprefix(args))
|
||||
|
|
@ -78,6 +80,7 @@ class ConfigFileFinder(object):
|
|||
if os.path.exists(filename):
|
||||
yield filename
|
||||
found_config_files = True
|
||||
self.local_directory = parent
|
||||
(parent, tail) = os.path.split(parent)
|
||||
|
||||
def local_config_files(self):
|
||||
|
|
@ -160,9 +163,11 @@ class MergedConfigParser(object):
|
|||
self.config_finder = ConfigFileFinder(self.program_name, self.args,
|
||||
self.extra_config_files)
|
||||
|
||||
@staticmethod
|
||||
def _normalize_value(option, value):
|
||||
final_value = option.normalize(value)
|
||||
def _normalize_value(self, option, value):
|
||||
final_value = option.normalize(
|
||||
value,
|
||||
self.config_finder.local_directory,
|
||||
)
|
||||
LOG.debug('%r has been normalized to %r for option "%s"',
|
||||
value, final_value, option.config_name)
|
||||
return final_value
|
||||
|
|
|
|||
|
|
@ -121,14 +121,14 @@ class Option(object):
|
|||
return self.long_option_name[2:].replace('-', '_')
|
||||
return self.short_option_name[1]
|
||||
|
||||
def normalize(self, value):
|
||||
def normalize(self, value, *normalize_args):
|
||||
"""Normalize the value based on the option configuration."""
|
||||
if self.normalize_paths:
|
||||
# Decide whether to parse a list of paths or a single path
|
||||
normalize = utils.normalize_path
|
||||
if self.comma_separated_list:
|
||||
normalize = utils.normalize_paths
|
||||
return normalize(value)
|
||||
return normalize(value, *normalize_args)
|
||||
elif self.comma_separated_list:
|
||||
return utils.parse_comma_separated_list(value)
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue