diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-06 00:57:45 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-06 00:57:45 -0800 |
commit | df6de29b987d314f0d7c6e8d87434e0107af5677 (patch) | |
tree | e251677dee7261cc20dee01db3f5d954bc43ffa4 | |
parent | bcec89b0ea45e310a90bc2ca472f4c3a0ba481ce (diff) | |
download | isort-df6de29b987d314f0d7c6e8d87434e0107af5677.tar.gz |
Fix handling of binary and .pex python files
-rw-r--r-- | isort/isort.py | 17 | ||||
-rw-r--r-- | isort/main.py | 2 |
2 files changed, 15 insertions, 4 deletions
diff --git a/isort/isort.py b/isort/isort.py index 330755bc..80f12c53 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -100,10 +100,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 io.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 616dc2f0..98e827c7 100644 --- a/isort/main.py +++ b/isort/main.py @@ -61,6 +61,8 @@ def is_python_file(path): _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('~'): |