summaryrefslogtreecommitdiff
path: root/isort
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-02-25 11:18:31 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-02-25 11:18:31 -0800
commit47a5e29e2ee236752c948442ec2feda612ca372e (patch)
treef785a1cd01b63d64359ea79e29388cbfd2e8a7a4 /isort
parent519efdcd242b323afadd81cbea6add814d471bc2 (diff)
parentbfabca6bd1c178cda98de41149f55933cfe37e65 (diff)
downloadisort-47a5e29e2ee236752c948442ec2feda612ca372e.tar.gz
Merge in hot fix releases
Diffstat (limited to 'isort')
-rw-r--r--isort/__init__.py2
-rw-r--r--isort/finders.py36
-rw-r--r--isort/main.py6
3 files changed, 31 insertions, 13 deletions
diff --git a/isort/__init__.py b/isort/__init__.py
index d59d0785..3553b811 100644
--- a/isort/__init__.py
+++ b/isort/__init__.py
@@ -22,4 +22,4 @@ OTHER DEALINGS IN THE SOFTWARE.
from . import settings # noqa: F401
from .isort import SortImports # noqa: F401
-__version__ = "4.3.5"
+__version__ = "4.3.8"
diff --git a/isort/finders.py b/isort/finders.py
index 866fb680..8a67acb8 100644
--- a/isort/finders.py
+++ b/isort/finders.py
@@ -326,20 +326,32 @@ class FindersManager(object):
PipfileFinder,
RequirementsFinder,
DefaultFinder,
- ) # type: Sequence[Type[BaseFinder]]
-
- def __init__(
- self,
- config: Mapping[str, Any],
- sections: Any,
- finders: Optional[Iterable[BaseFinder]] = None
- ) -> None:
- if finders is not None:
- self.finders = finders
- self.finders = tuple(finder_cls(config, sections) for finder_cls in self._default_finders_classes)
+ )
+
+ def __init__(self, config: Mapping[str, Any], sections: Any, finders: Optional[Iterable[BaseFinder]]=None):
+ self.verbose = config.get('verbose', False)
+
+ finders = self.finders if finders is None else finders
+ self.finders = []
+ for finder in finders:
+ try:
+ self.finders.append(finder(config, sections))
+ except Exception as exception:
+ # if one finder fails to instantiate isort can continue using the rest
+ if self.verbose:
+ print('{} encountered an error ({}) during instantiation and cannot be used'.format(finder.__name__,
+ str(exception)))
+ self.finders = tuple(self.finders)
def find(self, module_name: str) -> Optional[str]:
for finder in self.finders:
- section = finder.find(module_name)
+ try:
+ section = finder.find(module_name)
+ except Exception as exception:
+ # isort has to be able to keep trying to identify the correct import section even if one approach fails
+ if self.verbose:
+ print('{} encountered an error ({}) while trying to identify the {} module'.format(finder.__name__,
+ str(exception),
+ module_name))
if section is not None:
return section
diff --git a/isort/main.py b/isort/main.py
index 0cad6904..b05cb48c 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -250,6 +250,7 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
help='Force sortImports to recognize a module as being part of the current python project.')
parser.add_argument('-q', '--quiet', action='store_true', dest="quiet",
help='Shows extra quiet output, only errors are outputted.')
+ parser.add_argument('-r', dest='ambiguous_r_flag', action='store_true')
parser.add_argument('-rm', '--remove-import', dest='remove_imports', action='append',
help='Removes the specified import from all files.')
parser.add_argument('-rc', '--recursive', dest='recursive', action='store_true',
@@ -305,6 +306,11 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
print(INTRO)
return
+ if arguments.get('ambiguous_r_flag'):
+ print('ERROR: Deprecated -r flag set. This flag has been replaced with -rm to remove ambiguity between it and '
+ '-rc for recursive')
+ sys.exit(1)
+
if 'settings_path' in arguments:
sp = arguments['settings_path']
arguments['settings_path'] = os.path.abspath(sp) if os.path.isdir(sp) else os.path.dirname(os.path.abspath(sp))