Skip to content

Commit

Permalink
Stop using as_posix in _path.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Mar 1, 2024
1 parent 7b6cd5c commit 0420972
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
20 changes: 6 additions & 14 deletions fiona/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import os
import pathlib
import re
import sys
Expand Down Expand Up @@ -71,7 +72,8 @@ def from_uri(cls, uri):
else:
parsed_path = parts.path
parsed_netloc = parts.netloc
path = pathlib.Path(parsed_path).as_posix() if parsed_path else parsed_path

path = parsed_path
scheme = parts.scheme or None

if parts.query:
Expand Down Expand Up @@ -150,31 +152,21 @@ def _parse_path(path):
"""
if isinstance(path, _Path):
return path

elif pathlib and isinstance(path, pathlib.PurePath):
return _ParsedPath(path.as_posix(), None, None)

elif isinstance(path, pathlib.PurePath):
return _ParsedPath(os.fspath(path), None, None)
elif isinstance(path, str):

if sys.platform == "win32" and re.match(r"^[a-zA-Z]\:", path):
if pathlib:
return _ParsedPath(pathlib.Path(path).as_posix(), None, None)
else:
return _UnparsedPath(path)

return _ParsedPath(path, None, None)
elif path.startswith('/vsi'):
return _UnparsedPath(path)

else:
parts = urlparse(path)

else:
raise PathError("invalid path '{!r}'".format(path))

# if the scheme is not one of Rasterio's supported schemes, we
# return an UnparsedPath.
if parts.scheme:

if all(p in SCHEMES for p in parts.scheme.split('+')):
return _ParsedPath.from_uri(path)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ def shapefile(self, path_coutwildrnp_shp):

def test_open_repr(self, path_coutwildrnp_shp):
assert repr(self.c) == (
f"<open Collection '{Path(path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<open Collection '{path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

def test_closed_repr(self, path_coutwildrnp_shp):
self.c.close()
assert repr(self.c) == (
f"<closed Collection '{Path(path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<closed Collection '{path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

def test_path(self, path_coutwildrnp_shp):
assert self.c.path == Path(path_coutwildrnp_shp).as_posix()
assert self.c.path == path_coutwildrnp_shp

def test_name(self):
assert self.c.name == "coutwildrnp"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_collection_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def tearDown(self):

def test_open_repr(self):
assert repr(self.c) == (
f"<open Collection '{Path(self.path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<open Collection '{self.path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

def test_closed_repr(self):
self.c.close()
assert repr(self.c) == (
f"<closed Collection '{Path(self.path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<closed Collection '{self.path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def shapefile(self, path_coutwildrnp_shp):

def test_open_repr(self, path_coutwildrnp_shp):
assert repr(self.c) == (
f"<open Collection '{Path(path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<open Collection '{path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

def test_closed_repr(self, path_coutwildrnp_shp):
self.c.close()
assert repr(self.c) == (
f"<closed Collection '{Path(path_coutwildrnp_shp).as_posix()}:coutwildrnp', "
f"<closed Collection '{path_coutwildrnp_shp}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

Expand All @@ -46,14 +46,14 @@ def shapefile(self, data_dir):

def test_open_repr(self, data_dir):
assert repr(self.c) == (
f"<open Collection '{Path(data_dir).as_posix()}:coutwildrnp', "
f"<open Collection '{data_dir}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

def test_closed_repr(self, data_dir):
self.c.close()
assert repr(self.c) == (
f"<closed Collection '{Path(data_dir).as_posix()}:coutwildrnp', "
f"<closed Collection '{data_dir}:coutwildrnp', "
f"mode 'r' at {hex(id(self.c))}>"
)

Expand Down

0 comments on commit 0420972

Please sign in to comment.