Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for setup.cfg #4

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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