From 773a8e0350db9751aae662b2640e19f3dda9fb1f Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Wed, 6 Mar 2019 00:57:45 -0800 Subject: Update to include binary/pex improvement --- isort/isort.py | 17 +++++++++++++---- isort/main.py | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/isort/isort.py b/isort/isort.py index 481d7d14..0acadaf8 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -97,10 +97,19 @@ class SortImports(object): " or matches a glob in 'skip_glob' setting".format(file_path)) file_contents = None elif not file_contents: - self.file_path = file_path - self.file_encoding = coding_check(file_path) - with open(file_path, encoding=self.file_encoding, newline='') as file_to_import_sort: - file_contents = file_to_import_sort.read() + file_encoding = coding_check(file_path) + with io.open(file_path, encoding=file_encoding, newline='') as file_to_import_sort: + try: + file_contents = file_to_import_sort.read() + self.file_path = file_path + self.file_encoding = file_encoding + except UnicodeDecodeError: + file_contents = None + self.skipped = True + if self.config['verbose']: + print("WARNING: {} was skipped as it " + "couldn't be opened with the given {} encoding".format(file_path, + self.file_encoding)) if file_contents is None or ("isort:" + "skip_file") in file_contents: self.skipped = True diff --git a/isort/main.py b/isort/main.py index de30bd25..8842a318 100644 --- a/isort/main.py +++ b/isort/main.py @@ -60,6 +60,8 @@ def is_python_file(path: str) -> bool: _root, ext = os.path.splitext(path) if ext in ('.py', '.pyi'): return True + if ext in ('.pex', ): + return False # Skip editor backup files. if path.endswith('~'): -- cgit v1.2.1