]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/setuptools/_path.py
3 from typing
import Union
5 _Path
= Union
[str, os
.PathLike
]
8 def ensure_directory(path
):
9 """Ensure that the parent directory of `path` exists"""
10 dirname
= os
.path
.dirname(path
)
11 os
.makedirs(dirname
, exist_ok
=True)
14 def same_path(p1
: _Path
, p2
: _Path
) -> bool:
15 """Differs from os.path.samefile because it does not require paths to exist.
16 Purely string based (no comparison between i-nodes).
17 >>> same_path("a/b", "./a/b")
19 >>> same_path("a/b", "a/./b")
21 >>> same_path("a/b", "././a/b")
23 >>> same_path("a/b", "./a/b/c/..")
25 >>> same_path("a/b", "../a/b/c")
27 >>> same_path("a", "a/b")
30 return normpath(p1
) == normpath(p2
)
33 def normpath(filename
: _Path
) -> str:
34 """Normalize a file/dir name for comparison purposes."""
35 # See pkg_resources.normalize_path for notes about cygwin
36 file = os
.path
.abspath(filename
) if sys
.platform
== 'cygwin' else filename
37 return os
.path
.normcase(os
.path
.realpath(os
.path
.normpath(file)))