diff options
author | Maxim Kurnikov <maxim.kurnikov@gmail.com> | 2019-04-29 22:08:37 +0300 |
---|---|---|
committer | Maxim Kurnikov <maxim.kurnikov@gmail.com> | 2019-04-29 22:08:37 +0300 |
commit | 9d48066e7e3418c491125342aa763ba84aa66cab (patch) | |
tree | 21fc44807a84a43db501e4107ec484ace40a42c3 | |
parent | cdb2dacfd594954ed83dd0b5c4b024fface71f0b (diff) | |
download | isort-9d48066e7e3418c491125342aa763ba84aa66cab.tar.gz |
add resolve() helper to address the differences between pathlib implementations
-rw-r--r-- | isort/compat.py | 11 |
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) |