summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kurnikov <maxim.kurnikov@gmail.com>2019-04-29 22:08:37 +0300
committerMaxim Kurnikov <maxim.kurnikov@gmail.com>2019-04-29 22:08:37 +0300
commit9d48066e7e3418c491125342aa763ba84aa66cab (patch)
tree21fc44807a84a43db501e4107ec484ace40a42c3
parentcdb2dacfd594954ed83dd0b5c4b024fface71f0b (diff)
downloadisort-9d48066e7e3418c491125342aa763ba84aa66cab.tar.gz
add resolve() helper to address the differences between pathlib implementations
-rw-r--r--isort/compat.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/isort/compat.py b/isort/compat.py
index 2dd41fa0..5fa33729 100644
--- a/isort/compat.py
+++ b/isort/compat.py
@@ -43,12 +43,19 @@ def read_file_contents(file_path: Path, encoding: str, fallback_encoding: str) -
return None, None
+def resolve(path: Path) -> Path:
+ if sys.version_info[:2] >= (3, 6):
+ return path.resolve()
+ else:
+ return Path(os.path.abspath(str(path)))
+
+
def get_settings_path(settings_path: Optional[Path], current_file_path: Optional[Path]) -> Path:
if settings_path:
return settings_path
if current_file_path:
- return current_file_path.resolve().parent
+ return resolve(current_file_path).parent
else:
return Path.cwd()
@@ -83,7 +90,7 @@ class SortImports(object):
if file_path:
self.file_path = file_path # raw file path (unresolved) ?
- absolute_file_path = file_path.resolve()
+ absolute_file_path = resolve(file_path)
if check_skip:
if run_path and run_path in absolute_file_path.parents:
file_name = os.path.relpath(absolute_file_path, run_path)