summaryrefslogtreecommitdiff
path: root/src/click
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2021-10-10 10:14:55 -0700
committerDavid Lord <davidism@gmail.com>2021-10-10 10:14:55 -0700
commitc8ca29bd3581d3c5e36ea0254f6c8cf0bf6c40c4 (patch)
tree1f61481deaf7f316e4998cc3d4b43393011b76b3 /src/click
parent96146c9d0b25d700d00b65c916739bd491dd15e0 (diff)
downloadclick-c8ca29bd3581d3c5e36ea0254f6c8cf0bf6c40c4.tar.gz
use pathlib to resolve symlinks
Diffstat (limited to 'src/click')
-rw-r--r--src/click/types.py19
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)