-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache_paths.py
More file actions
49 lines (40 loc) · 1.23 KB
/
cache_paths.py
File metadata and controls
49 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Den Rozhnovskiy
from __future__ import annotations
from pathlib import Path
def wire_filepath_from_runtime(
runtime_filepath: str,
*,
root: Path | None,
) -> str:
runtime_path = Path(runtime_filepath)
if root is None:
return runtime_path.as_posix()
try:
relative = runtime_path.relative_to(root)
return relative.as_posix()
except ValueError:
pass
try:
relative = runtime_path.resolve().relative_to(root.resolve())
return relative.as_posix()
except OSError:
return runtime_path.as_posix()
except ValueError:
return runtime_path.as_posix()
def runtime_filepath_from_wire(
wire_filepath: str,
*,
root: Path | None,
) -> str:
wire_path = Path(wire_filepath)
if root is None or wire_path.is_absolute():
return str(wire_path)
combined = root / wire_path
try:
return str(combined.resolve(strict=False))
except OSError:
return str(combined)