Skip to content

Commit e3f9a91

Browse files
authored
Restore _kwargs and _url on local paths for now (#131)
1 parent 53b5710 commit e3f9a91

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

upath/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _FSSpecAccessor:
3434
__slots__ = ("_fs",)
3535

3636
def __init__(self, parsed_url: SplitResult | None, **kwargs: Any) -> None:
37-
if parsed_url:
37+
if parsed_url and parsed_url.scheme:
3838
cls = get_filesystem_class(parsed_url.scheme)
3939
url_kwargs = cls._get_kwargs_from_urls(urlunsplit(parsed_url))
4040
else:
@@ -166,7 +166,7 @@ def __new__(cls: type[PT], *args: str | PathLike, **kwargs: Any) -> PT:
166166
_kwargs = getattr(other, "_kwargs", {})
167167
_url = getattr(other, "_url", None)
168168
other_kwargs = _kwargs.copy()
169-
if _url:
169+
if _url and _url.scheme:
170170
other_kwargs["url"] = _url
171171
new_kwargs = _kwargs.copy()
172172
new_kwargs.update(kwargs)

upath/implementations/local.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import WindowsPath
77
from typing import Any
88
from typing import Iterable
9+
from urllib.parse import SplitResult
910

1011
from fsspec.implementations.local import LocalFileSystem
1112

@@ -49,19 +50,18 @@ class PosixUPath(PosixPath, UPath):
4950

5051
@property
5152
def fs(self):
52-
try:
53-
return self._cached_fs
54-
except AttributeError:
55-
self._cached_fs = fs = LocalFileSystem()
56-
return fs
53+
return LocalFileSystem()
5754

5855
@property
5956
def path(self) -> str:
6057
return str(self)
6158

6259
@classmethod
6360
def _from_parts(cls, args, *, url=None, **kw):
64-
return super(UPath, cls)._from_parts(args)
61+
obj = super(UPath, cls)._from_parts(args)
62+
obj._kwargs = {}
63+
obj._url = SplitResult("", "", str(obj), "", "")
64+
return obj
6565

6666

6767
class WindowsUPath(WindowsPath, UPath):
@@ -77,16 +77,15 @@ class WindowsUPath(WindowsPath, UPath):
7777

7878
@property
7979
def fs(self):
80-
try:
81-
return self._cached_fs
82-
except AttributeError:
83-
self._cached_fs = fs = LocalFileSystem()
84-
return fs
80+
return LocalFileSystem()
8581

8682
@property
8783
def path(self) -> str:
8884
return str(self)
8985

9086
@classmethod
9187
def _from_parts(cls, args, *, url=None, **kw):
92-
return super(UPath, cls)._from_parts(args)
88+
obj = super(UPath, cls)._from_parts(args)
89+
obj._kwargs = {}
90+
obj._url = SplitResult("", "", str(obj), "", "")
91+
return obj

upath/tests/test_core.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pickle
44
import sys
55
import warnings
6+
from urllib.parse import SplitResult
67

78
import pytest
89

@@ -242,6 +243,24 @@ def test_copy_path_append():
242243
assert str(path / "folder2" / "folder3") == str(copy_path)
243244

244245

246+
@pytest.mark.parametrize(
247+
"urlpath",
248+
[
249+
os.getcwd(),
250+
pathlib.Path.cwd().as_uri(),
251+
"mock:///abc",
252+
],
253+
)
254+
def test_access_to_private_kwargs_and_url(urlpath):
255+
# fixme: this should be deprecated...
256+
pth = UPath(urlpath)
257+
assert isinstance(pth._kwargs, dict)
258+
assert pth._kwargs == {}
259+
assert isinstance(pth._url, SplitResult)
260+
assert pth._url.scheme == "" or pth._url.scheme in pth.fs.protocol
261+
assert pth._url.path == pth.path
262+
263+
245264
def test_copy_path_append_kwargs():
246265
path = UPath("gcs://bucket/folder", anon=True)
247266
copy_path = UPath(path, anon=False)

0 commit comments

Comments
 (0)