File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,11 @@ def open( # pytype: disable=signature-mismatch # overriding-parameter-count-ch
258
258
gfile = typing .cast (typing .IO [Union [str , bytes ]], gfile )
259
259
return gfile
260
260
261
+ def relative_to (self : _P , other : PathLike ) -> _P :
262
+ """Returns the current path relative to `other`."""
263
+ other_path = self ._new (other )
264
+ return super ().relative_to (other_path )
265
+
261
266
def rename (self : _P , target : PathLike ) -> _P :
262
267
"""Rename file or directory to the given target."""
263
268
# Note: Issue if WindowsPath and target is gs://. Rather than using `_new`,
Original file line number Diff line number Diff line change @@ -455,3 +455,11 @@ def test_public_access():
455
455
# Test a public bucket
456
456
p = epath .Path ('gs://tfds-data/datasets' )
457
457
assert p .exists ()
458
+
459
+
460
+ def test_relative_to ():
461
+ path = epath .Path ('gs://bucket/dir/subdir' )
462
+ assert path .relative_to (path ) == epath .Path ('.' )
463
+ assert path .relative_to ('gs://bucket/dir' ) == epath .Path ('subdir' )
464
+ with pytest .raises (ValueError , match = 'not in the subpath' ):
465
+ path .relative_to ('gs://bucket/other-dir' )
You can’t perform that action at this time.
0 commit comments