Skip to content

Commit

Permalink
Merge pull request #4 from plumdog/check_for_setup_cfg
Browse files Browse the repository at this point in the history
Check for setup.cfg
  • Loading branch information
gforcada committed Feb 16, 2016
2 parents 4d546f9 + 1109dfc commit be8cdd7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion flake8_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from isort import SortImports

import os
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser


class Flake8Isort(object):
Expand Down Expand Up @@ -39,7 +43,9 @@ def run(self):
yield 0, 0, self.message, type(self)

def search_isort_config(self):
"""Search for a .isort.cfg all the way up to the root folder"""
"""Search for a .isort.cfg or setup.cfg all the way up to the root
folder
"""
full_path = os.path.abspath(self.filename)
path_parts = full_path.split(os.path.sep)
dirs_missing = len(path_parts)
Expand All @@ -53,4 +59,13 @@ def search_isort_config(self):
if os.path.exists(isort_file):
return True

# If the setup file exists and has an "isort" section,
# then we've found the configuration.
setup_file = os.path.join(partial_path, 'setup.cfg')
if os.path.exists(setup_file):
config = ConfigParser()
config.read(setup_file)
if 'isort' in config.sections():
return True

return False

0 comments on commit be8cdd7

Please sign in to comment.