generated from jCloud/repository-template
Add function to get the path segments of a path relative to another
This commit is contained in:
@@ -151,4 +151,25 @@ def non_empty_str(value: Union[str, None]) -> Union[str, None]:
|
||||
if value.strip() == '':
|
||||
return None
|
||||
|
||||
return value
|
||||
return value
|
||||
|
||||
def get_relative_path_segments(path: pathlib.Path, root: pathlib.Path) -> list[str]:
|
||||
'''
|
||||
Returns the path segments relative to ``root``.
|
||||
|
||||
:param path: The path.
|
||||
:type path: pathlib.Path
|
||||
:param root: The root path.
|
||||
:type root: pathlib.Path
|
||||
|
||||
:return: The path segments relative to ``root``.
|
||||
:rtype: list[str]
|
||||
'''
|
||||
|
||||
return list(
|
||||
path.resolve()
|
||||
.relative_to(
|
||||
root.resolve()
|
||||
)
|
||||
.parts
|
||||
)
|
||||
Reference in New Issue
Block a user