From 04af82d25004795b6514c393208764d579a3d709 Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Sat, 25 Mar 2017 21:52:27 +0100 Subject: [PATCH] Extract code to make it reusable --- flake8_isort.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/flake8_isort.py b/flake8_isort.py index 04de46e..261723d 100644 --- a/flake8_isort.py +++ b/flake8_isort.py @@ -86,34 +86,26 @@ def search_isort_config(self): partial_parts = path_parts[:dirs_missing] partial_path = os.sep.join(partial_parts) - isort_file = '{0}{1}.isort.cfg'.format(partial_path, os.sep) - if os.path.exists(isort_file): + if self._search_config_on_path(partial_path): 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(partial_path, os.sep) - if os.path.exists(setup_file): - config = ConfigParser() - config.read(setup_file) - 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) + """Search for isort configuration at current directory""" + return self._search_config_on_path(os.path.realpath('.')) + + def _search_config_on_path(self, path): + isort_file = '{0}{1}.isort.cfg'.format(path, 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) + setup_file = '{0}{1}setup.cfg'.format(path, os.sep) if os.path.exists(setup_file): config = ConfigParser() config.read(setup_file)