From 1109dfc28309b4438965075140d1a786b3383d5e Mon Sep 17 00:00:00 2001 From: Andrew Plummer Date: Thu, 14 Jan 2016 15:39:53 +0000 Subject: [PATCH] Check for setup.cfg --- flake8_isort.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/flake8_isort.py b/flake8_isort.py index f0443f3..a91dc36 100644 --- a/flake8_isort.py +++ b/flake8_isort.py @@ -2,6 +2,10 @@ from isort import SortImports import os +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import ConfigParser class Flake8Isort(object): @@ -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) @@ -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