summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 09:32:39 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 09:37:32 -0500
commitdf2fa18a0865a202e91fcc0d8ca4a49b402baed3 (patch)
tree36c7d02c27ff1e5a236c6de238a7c6447eb0cdc9
parentf82b5d62d0c4e48b95466bb259f3401aecf28de7 (diff)
downloadflake8-df2fa18a0865a202e91fcc0d8ca4a49b402baed3.tar.gz
Fix project config file discovery
Flake8 3.0 was stopping once it found the current directory but the historical behaviour (that we didn't intend to break) searched past that (towards root) until it found one of the project/local config file names that could be read. Closes #181
-rw-r--r--docs/source/release-notes/3.0.1.rst4
-rw-r--r--docs/source/release-notes/3.0.2.rst9
-rw-r--r--docs/source/release-notes/index.rst1
-rw-r--r--src/flake8/options/config.py13
-rw-r--r--tests/unit/test_config_file_finder.py22
5 files changed, 22 insertions, 27 deletions
diff --git a/docs/source/release-notes/3.0.1.rst b/docs/source/release-notes/3.0.1.rst
index 0092dc8..20f6783 100644
--- a/docs/source/release-notes/3.0.1.rst
+++ b/docs/source/release-notes/3.0.1.rst
@@ -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.
(See also `GitLab#177`_)
diff --git a/docs/source/release-notes/3.0.2.rst b/docs/source/release-notes/3.0.2.rst
new file mode 100644
index 0000000..8605ce9
--- /dev/null
+++ b/docs/source/release-notes/3.0.2.rst
@@ -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
diff --git a/docs/source/release-notes/index.rst b/docs/source/release-notes/index.rst
index 8056b76..440079b 100644
--- a/docs/source/release-notes/index.rst
+++ b/docs/source/release-notes/index.rst
@@ -6,6 +6,7 @@ All of the release notes that have been recorded for Flake8 are organized here
with the newest releases first.
.. toctree::
+ 3.0.2
3.0.1
3.0.0
2.6.2
diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py
index ec5023b..d1408fe 100644
--- a/src/flake8/options/config.py
+++ b/src/flake8/options/config.py
@@ -43,8 +43,6 @@ 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))
@@ -72,14 +70,14 @@ class ConfigFileFinder(object):
"""Find and generate all local config files."""
tail = self.tail
parent = self.parent
- local_dir = self.local_directory
- while tail:
+ found_config_files = False
+ while tail and not found_config_files:
for project_filename in self.project_filenames:
filename = os.path.abspath(os.path.join(parent,
project_filename))
- yield filename
- if parent == local_dir:
- break
+ if os.path.exists(filename):
+ yield filename
+ found_config_files = True
(parent, tail) = os.path.split(parent)
def local_config_files(self):
@@ -99,7 +97,6 @@ class ConfigFileFinder(object):
return [
filename
for filename in self.generate_possible_local_files()
- if os.path.exists(filename)
] + [f for f in self.extra_config_files if exists(f)]
def local_configs(self):
diff --git a/tests/unit/test_config_file_finder.py b/tests/unit/test_config_file_finder.py
index 2e1a1e5..3f321da 100644
--- a/tests/unit/test_config_file_finder.py
+++ b/tests/unit/test_config_file_finder.py
@@ -43,27 +43,15 @@ def test_cli_config():
# No arguments, common prefix of abspath('.')
([],
[os.path.abspath('setup.cfg'),
- os.path.abspath('tox.ini'),
- os.path.abspath('.flake8')]),
+ os.path.abspath('tox.ini')]),
# Common prefix of "flake8/"
(['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')]),
+ [os.path.abspath('setup.cfg'),
+ os.path.abspath('tox.ini')]),
# Common prefix of "flake8/options"
(['flake8/options', 'flake8/options/sub'],
- [os.path.abspath('flake8/options/setup.cfg'),
- os.path.abspath('flake8/options/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')]),
+ [os.path.abspath('setup.cfg'),
+ os.path.abspath('tox.ini')]),
])
def test_generate_possible_local_files(args, expected):
"""Verify generation of all possible config paths."""