Skip to content

Commit

Permalink
Restore _kwargs and _url on local paths for now (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- authored Aug 7, 2023
1 parent 53b5710 commit e3f9a91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _FSSpecAccessor:
__slots__ = ("_fs",)

def __init__(self, parsed_url: SplitResult | None, **kwargs: Any) -> None:
if parsed_url:
if parsed_url and parsed_url.scheme:
cls = get_filesystem_class(parsed_url.scheme)
url_kwargs = cls._get_kwargs_from_urls(urlunsplit(parsed_url))
else:
Expand Down Expand Up @@ -166,7 +166,7 @@ def __new__(cls: type[PT], *args: str | PathLike, **kwargs: Any) -> PT:
_kwargs = getattr(other, "_kwargs", {})
_url = getattr(other, "_url", None)
other_kwargs = _kwargs.copy()
if _url:
if _url and _url.scheme:
other_kwargs["url"] = _url
new_kwargs = _kwargs.copy()
new_kwargs.update(kwargs)
Expand Down
23 changes: 11 additions & 12 deletions upath/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import WindowsPath
from typing import Any
from typing import Iterable
from urllib.parse import SplitResult

from fsspec.implementations.local import LocalFileSystem

Expand Down Expand Up @@ -49,19 +50,18 @@ class PosixUPath(PosixPath, UPath):

@property
def fs(self):
try:
return self._cached_fs
except AttributeError:
self._cached_fs = fs = LocalFileSystem()
return fs
return LocalFileSystem()

@property
def path(self) -> str:
return str(self)

@classmethod
def _from_parts(cls, args, *, url=None, **kw):
return super(UPath, cls)._from_parts(args)
obj = super(UPath, cls)._from_parts(args)
obj._kwargs = {}
obj._url = SplitResult("", "", str(obj), "", "")
return obj


class WindowsUPath(WindowsPath, UPath):
Expand All @@ -77,16 +77,15 @@ class WindowsUPath(WindowsPath, UPath):

@property
def fs(self):
try:
return self._cached_fs
except AttributeError:
self._cached_fs = fs = LocalFileSystem()
return fs
return LocalFileSystem()

@property
def path(self) -> str:
return str(self)

@classmethod
def _from_parts(cls, args, *, url=None, **kw):
return super(UPath, cls)._from_parts(args)
obj = super(UPath, cls)._from_parts(args)
obj._kwargs = {}
obj._url = SplitResult("", "", str(obj), "", "")
return obj
19 changes: 19 additions & 0 deletions upath/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pickle
import sys
import warnings
from urllib.parse import SplitResult

import pytest

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


@pytest.mark.parametrize(
"urlpath",
[
os.getcwd(),
pathlib.Path.cwd().as_uri(),
"mock:///abc",
],
)
def test_access_to_private_kwargs_and_url(urlpath):
# fixme: this should be deprecated...
pth = UPath(urlpath)
assert isinstance(pth._kwargs, dict)
assert pth._kwargs == {}
assert isinstance(pth._url, SplitResult)
assert pth._url.scheme == "" or pth._url.scheme in pth.fs.protocol
assert pth._url.path == pth.path


def test_copy_path_append_kwargs():
path = UPath("gcs://bucket/folder", anon=True)
copy_path = UPath(path, anon=False)
Expand Down

0 comments on commit e3f9a91

Please sign in to comment.