1from functools
import total_ordering
21 last_slash = path.rfind(
"/")
22 return path[last_slash + 1 :]
31 f
"Expected {self} to be a folder but it doesn't end with `/`"
36 raise ValueError(
"Path does not have a parent folder")
38 last_idx = trimmed_path.rfind(
"/")
39 return TypedPath.of_folder(trimmed_path[: last_idx + 1])
43 if child.startswith(
"/")
or child.endswith(
"/"):
44 raise ValueError(
"Child path is not valid for file resolution")
45 return self.
of_file(f
"{self.absolute_path}{child}")
49 if child.startswith(
"/"):
50 raise ValueError(
"Child path starts with a slash")
51 return self.
of_folder(f
"{self.absolute_path}{child}/")
56 raise ValueError(f
"Expected {child} to start with {self.absolute_path}")
59 def __eq__(self, other: object) -> bool:
60 if not isinstance(other, TypedPath):
64 def __lt__(self, other:
"TypedPath") -> bool:
69 unix_path = path.replace(
"\\",
"/")
70 if not unix_path.endswith(
"/"):
75 def of_file(cls, path: str) ->
"TypedPath":
76 unix_path = path.replace(
"\\",
"/")
77 if unix_path.endswith(
"/"):
78 raise ValueError(
"Expected path to not end with a slash for a file")
"TypedPath" of_file(cls, str path)
str relativize(self, "TypedPath" child)
"TypedPath" resolve_file(self, str child)
bool __lt__(self, "TypedPath" other)
bool __eq__(self, object other)
"TypedPath" resolve_folder(self, str child)
"TypedPath" of_folder(cls, str path)
"TypedPath" parent_folder(self)
__init__(self, str absolute_path)