mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-15 03:04:29 +00:00
actually need to swap it out
This commit is contained in:
parent
3d326dfc8b
commit
ea0e8127fa
1 changed files with 21 additions and 18 deletions
|
@ -85,26 +85,26 @@ def _walk_and_apply(value: T, f: Callable[[U], U]) -> T:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def relative_path(target: Path, origin: Path) -> Path:
|
# def relative_path(target: Path, origin: Path) -> Path:
|
||||||
"""
|
# """
|
||||||
return path of target relative to origin, even if they're
|
# return path of target relative to origin, even if they're
|
||||||
not in the same subpath
|
# not in the same subpath
|
||||||
|
#
|
||||||
References:
|
# References:
|
||||||
- https://stackoverflow.com/a/71874881
|
# - https://stackoverflow.com/a/71874881
|
||||||
"""
|
# """
|
||||||
try:
|
# try:
|
||||||
return Path(target).resolve().relative_to(Path(origin).resolve())
|
# return Path(target).resolve().relative_to(Path(origin).resolve())
|
||||||
except ValueError: # target does not start with origin
|
# except ValueError: # target does not start with origin
|
||||||
# recursion with origin (eventually origin is root so try will succeed)
|
# # recursion with origin (eventually origin is root so try will succeed)
|
||||||
try:
|
# try:
|
||||||
return Path("..").joinpath(relative_path(target, Path(origin).parent))
|
# return Path("..").joinpath(relative_path(target, Path(origin).parent))
|
||||||
except ValueError:
|
# except ValueError:
|
||||||
# break recursion in windows when
|
# # break recursion in windows when
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
def relative_to(self: Path, other: Path, walk_up=True) -> Path:
|
def relative_path(self: Path, other: Path, walk_up: bool = True) -> Path:
|
||||||
"""
|
"""
|
||||||
"Backport" of :meth:`pathlib.Path.relative_to` with ``walk_up=True``
|
"Backport" of :meth:`pathlib.Path.relative_to` with ``walk_up=True``
|
||||||
that's not available pre 3.12.
|
that's not available pre 3.12.
|
||||||
|
@ -115,6 +115,9 @@ def relative_to(self: Path, other: Path, walk_up=True) -> Path:
|
||||||
|
|
||||||
The *walk_up* parameter controls whether `..` may be used to resolve
|
The *walk_up* parameter controls whether `..` may be used to resolve
|
||||||
the path.
|
the path.
|
||||||
|
|
||||||
|
References:
|
||||||
|
https://github.com/python/cpython/blob/8a2baedc4bcb606da937e4e066b4b3a18961cace/Lib/pathlib/_abc.py#L244-L270
|
||||||
"""
|
"""
|
||||||
if not isinstance(other, Path):
|
if not isinstance(other, Path):
|
||||||
other = self.with_segments(other)
|
other = self.with_segments(other)
|
||||||
|
|
Loading…
Reference in a new issue