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

No configuration found when is used with git hook #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion flake8_isort.py
Expand Up @@ -35,8 +35,9 @@ class Flake8Isort(object):

config_file = None

def __init__(self, tree, filename):
def __init__(self, tree, filename, search_current=True):
self.filename = filename
self.search_current = search_current

@classmethod
def add_options(cls, parser):
Expand Down Expand Up @@ -98,6 +99,27 @@ def search_isort_config(self):
if 'isort' in config.sections():
return True

if self.search_current:
return self.search_isort_config_at_current()

return False

def search_isort_config_at_current(self):
"""Search for isort configuration at current directory
"""
isort_file = '{0}{1}.isort.cfg'.format(os.path.realpath('.'), os.sep)
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 = '{0}{1}setup.cfg'.format(os.path.realpath('.'), os.sep)
if os.path.exists(setup_file):
config = ConfigParser()
config.read(setup_file)
if 'isort' in config.sections():
return True

return False

def sortimports_linenum_msg(self, sort_result):
Expand Down
2 changes: 1 addition & 1 deletion run_tests.py
Expand Up @@ -205,7 +205,7 @@ def test_isortcfg_not_found(self):
os.remove(isortcfg_path)

with OutputCapture():
checker = Flake8Isort(None, file_path)
checker = Flake8Isort(None, file_path, search_current=False)
checker.config_file = True
ret = list(checker.run())
self.assertEqual(len(ret), 1)
Expand Down