Merge branch 'bug/181' into 'master'

Fix project config file discovery

*Description of changes*

Keep searching past the current directory to find project config files.

*Related to:*  #181

See merge request !91
This commit is contained in:
Ian Cordasco 2016-07-26 14:40:44 +00:00
commit 99602828c7
5 changed files with 22 additions and 27 deletions

View file

@ -1,5 +1,5 @@
3.0.1 -- 2016-07-25 3.0.1 -- 2016-07-25 (unreleased)
------------------- --------------------------------
- Fix regression in handling of ``# noqa`` for multiline strings. - Fix regression in handling of ``# noqa`` for multiline strings.
(See also `GitLab#177`_) (See also `GitLab#177`_)

View file

@ -0,0 +1,9 @@
3.0.2 -- 2016-07-26
-------------------
- Fix local config file discovery. (See also `GitLab#181`_)
.. links
.. _GitLab#181:
https://gitlab.com/pycqa/flake8/issues/181

View file

@ -6,6 +6,7 @@ All of the release notes that have been recorded for Flake8 are organized here
with the newest releases first. with the newest releases first.
.. toctree:: .. toctree::
3.0.2
3.0.1 3.0.1
3.0.0 3.0.0
2.6.2 2.6.2

View file

@ -43,8 +43,6 @@ class ConfigFileFinder(object):
# List of filenames to find in the local/project directory # List of filenames to find in the local/project directory
self.project_filenames = ('setup.cfg', 'tox.ini', self.program_config) self.project_filenames = ('setup.cfg', 'tox.ini', self.program_config)
self.local_directory = os.path.abspath(os.curdir)
if not args: if not args:
args = ['.'] args = ['.']
self.parent = self.tail = os.path.abspath(os.path.commonprefix(args)) self.parent = self.tail = os.path.abspath(os.path.commonprefix(args))
@ -72,14 +70,14 @@ class ConfigFileFinder(object):
"""Find and generate all local config files.""" """Find and generate all local config files."""
tail = self.tail tail = self.tail
parent = self.parent parent = self.parent
local_dir = self.local_directory found_config_files = False
while tail: while tail and not found_config_files:
for project_filename in self.project_filenames: for project_filename in self.project_filenames:
filename = os.path.abspath(os.path.join(parent, filename = os.path.abspath(os.path.join(parent,
project_filename)) project_filename))
yield filename if os.path.exists(filename):
if parent == local_dir: yield filename
break found_config_files = True
(parent, tail) = os.path.split(parent) (parent, tail) = os.path.split(parent)
def local_config_files(self): def local_config_files(self):
@ -99,7 +97,6 @@ class ConfigFileFinder(object):
return [ return [
filename filename
for filename in self.generate_possible_local_files() for filename in self.generate_possible_local_files()
if os.path.exists(filename)
] + [f for f in self.extra_config_files if exists(f)] ] + [f for f in self.extra_config_files if exists(f)]
def local_configs(self): def local_configs(self):

View file

@ -43,27 +43,15 @@ def test_cli_config():
# No arguments, common prefix of abspath('.') # No arguments, common prefix of abspath('.')
([], ([],
[os.path.abspath('setup.cfg'), [os.path.abspath('setup.cfg'),
os.path.abspath('tox.ini'), os.path.abspath('tox.ini')]),
os.path.abspath('.flake8')]),
# Common prefix of "flake8/" # Common prefix of "flake8/"
(['flake8/options', 'flake8/'], (['flake8/options', 'flake8/'],
[os.path.abspath('flake8/setup.cfg'), [os.path.abspath('setup.cfg'),
os.path.abspath('flake8/tox.ini'), os.path.abspath('tox.ini')]),
os.path.abspath('flake8/.flake8'),
os.path.abspath('setup.cfg'),
os.path.abspath('tox.ini'),
os.path.abspath('.flake8')]),
# Common prefix of "flake8/options" # Common prefix of "flake8/options"
(['flake8/options', 'flake8/options/sub'], (['flake8/options', 'flake8/options/sub'],
[os.path.abspath('flake8/options/setup.cfg'), [os.path.abspath('setup.cfg'),
os.path.abspath('flake8/options/tox.ini'), os.path.abspath('tox.ini')]),
os.path.abspath('flake8/options/.flake8'),
os.path.abspath('flake8/setup.cfg'),
os.path.abspath('flake8/tox.ini'),
os.path.abspath('flake8/.flake8'),
os.path.abspath('setup.cfg'),
os.path.abspath('tox.ini'),
os.path.abspath('.flake8')]),
]) ])
def test_generate_possible_local_files(args, expected): def test_generate_possible_local_files(args, expected):
"""Verify generation of all possible config paths.""" """Verify generation of all possible config paths."""