diff options
author | David Lord <davidism@gmail.com> | 2021-10-10 10:14:55 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2021-10-10 10:14:55 -0700 |
commit | c8ca29bd3581d3c5e36ea0254f6c8cf0bf6c40c4 (patch) | |
tree | 1f61481deaf7f316e4998cc3d4b43393011b76b3 /src/click | |
parent | 96146c9d0b25d700d00b65c916739bd491dd15e0 (diff) | |
download | click-c8ca29bd3581d3c5e36ea0254f6c8cf0bf6c40c4.tar.gz |
use pathlib to resolve symlinks
Diffstat (limited to 'src/click')
-rw-r--r-- | src/click/types.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/click/types.py b/src/click/types.py index a7de43b..103d218 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -836,20 +836,11 @@ class Path(ParamType): if not is_dash: if self.resolve_path: - # Get the absolute directory containing the path. - dir_ = os.path.dirname(os.path.abspath(rv)) - - # Resolve a symlink. realpath on Windows Python < 3.9 - # doesn't resolve symlinks. This might return a relative - # path even if the path to the link is absolute. - if os.path.islink(rv): - rv = os.readlink(rv) - - # Join dir_ with the resolved symlink if the resolved - # path is relative. This will make it relative to the - # original containing directory. - if not os.path.isabs(rv): - rv = os.path.join(dir_, rv) + # os.path.realpath doesn't resolve symlinks on Windows + # until Python 3.8. Use pathlib for now. + import pathlib + + rv = os.fsdecode(pathlib.Path(rv).resolve()) try: st = os.stat(rv) |