summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-03-06 00:57:45 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-06 00:59:57 -0800
commit773a8e0350db9751aae662b2640e19f3dda9fb1f (patch)
tree7871eaa285330f9da36d95ba1812051bedd899d6
parent91ae94e477d066f133a889d13f3bd25363785258 (diff)
downloadisort-773a8e0350db9751aae662b2640e19f3dda9fb1f.tar.gz
Update to include binary/pex improvement
-rw-r--r--isort/isort.py17
-rw-r--r--isort/main.py2
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('~'):