Skip to content

Commit

Permalink
[IMP] add helper method to get a path relative to another
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-halleux committed Feb 14, 2025
1 parent 3a5acf8 commit af522c1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os.path
import re
import warnings
from pathlib import Path
from typing import AnyStr

import fsspec
Expand Down Expand Up @@ -518,3 +519,10 @@ def _get_root_filesystem(self):
while hasattr(fs, "fs"):
fs = fs.fs
return fs

Check warning on line 521 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L520-L521

Added lines #L520 - L521 were not covered by tests

@api.model
def get_relative_path(self, absolute_path, root_path):
path = Path(absolute_path)

Check warning on line 525 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L525

Added line #L525 was not covered by tests
if path.is_relative_to(root_path):
return path.relative_to(root_path).as_posix()
return absolute_path

Check warning on line 528 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L527-L528

Added lines #L527 - L528 were not covered by tests

0 comments on commit af522c1

Please sign in to comment.