This commit is contained in:
2026-01-22 20:49:24 +08:00
parent 382c756dfe
commit 5238e105e4
3 changed files with 37 additions and 2 deletions

View File

@@ -174,6 +174,24 @@ def get_relative_path(base: Union[str, Path], target: Union[str, Path]) -> Path:
return (base_path / target_path).resolve()
def resolve_path(base: Union[str, Path], target: Union[str, Path]) -> Path:
"""
Resolve target path against base if target is relative.
Args:
base: base directory
target: target path (absolute or relative)
Returns:
Absolute Path
"""
base_path = Path(base) if isinstance(base, str) else base
target_path = Path(target) if isinstance(target, str) else target
if target_path.is_absolute():
return target_path
return (base_path / target_path).resolve()
def print_platform_summary():
"""打印平台摘要信息"""
info = get_platform_info()
@@ -212,4 +230,4 @@ if __name__ == "__main__":
print("\n路径处理测试:")
test_path = "some/path/to/file.txt"
print(f" 原始路径: {test_path}")
print(f" 安全路径: {safe_path(test_path)}")
print(f" 安全路径: {safe_path(test_path)}")