]> jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/setuptools/_path.py
init: venv aand flask
[dlqueue.git] / venv / lib / python3.11 / site-packages / setuptools / _path.py
1 import os
2 import sys
3 from typing import Union
4
5 _Path = Union[str, os.PathLike]
6
7
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)
12
13
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")
18 True
19 >>> same_path("a/b", "a/./b")
20 True
21 >>> same_path("a/b", "././a/b")
22 True
23 >>> same_path("a/b", "./a/b/c/..")
24 True
25 >>> same_path("a/b", "../a/b/c")
26 False
27 >>> same_path("a", "a/b")
28 False
29 """
30 return normpath(p1) == normpath(p2)
31
32
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)))