BlendPath: don't use os.path.join() for slash notations
The BlendPath should just use forward slashes, and not be depending on the current platform.
This commit is contained in:
parent
0e392f27c9
commit
d81fe590db
@ -79,13 +79,13 @@ class BlendPath(bytes):
|
|||||||
sub = BlendPath(subpath)
|
sub = BlendPath(subpath)
|
||||||
if sub.is_absolute():
|
if sub.is_absolute():
|
||||||
raise ValueError("'a / b' only works when 'b' is a relative path")
|
raise ValueError("'a / b' only works when 'b' is a relative path")
|
||||||
return BlendPath(os.path.join(self, sub))
|
return BlendPath(self.rstrip(b'/') + b'/' + sub)
|
||||||
|
|
||||||
def __rtruediv__(self, parentpath: bytes):
|
def __rtruediv__(self, parentpath: bytes):
|
||||||
"""Slash notation like pathlib.Path."""
|
"""Slash notation like pathlib.Path."""
|
||||||
if self.is_absolute():
|
if self.is_absolute():
|
||||||
raise ValueError("'a / b' only works when 'b' is a relative path")
|
raise ValueError("'a / b' only works when 'b' is a relative path")
|
||||||
return BlendPath(os.path.join(parentpath, self))
|
return BlendPath(parentpath.rstrip(b'/') + b'/' + self)
|
||||||
|
|
||||||
def to_path(self) -> pathlib.PurePath:
|
def to_path(self) -> pathlib.PurePath:
|
||||||
"""Convert this path to a pathlib.PurePath.
|
"""Convert this path to a pathlib.PurePath.
|
||||||
|
|||||||
@ -45,6 +45,11 @@ class BlendPathTest(unittest.TestCase):
|
|||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
b'/root/and' / BlendPath(b'/parent.blend')
|
b'/root/and' / BlendPath(b'/parent.blend')
|
||||||
|
|
||||||
|
# On Windows+Python 3.5.4 this resulted in b'//root//parent.blend',
|
||||||
|
# but only if the root is a single term (so not b'//root/and/').
|
||||||
|
self.assertEqual(BlendPath(b'//root/parent.blend'),
|
||||||
|
BlendPath(b'//root/') / b'parent.blend')
|
||||||
|
|
||||||
def test_mkrelative(self):
|
def test_mkrelative(self):
|
||||||
self.assertEqual(b'//asset.png', BlendPath.mkrelative(
|
self.assertEqual(b'//asset.png', BlendPath.mkrelative(
|
||||||
Path('/path/to/asset.png'),
|
Path('/path/to/asset.png'),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user