Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ def path(self) -> str:
path = str(current_dir)
else:
path = current_dir.parser.join(str(self), self_path)
else:
path = str(self)
return self.parser.strip_protocol(path)
return self.parser.strip_protocol(path)
return self._chain.active_path

def joinuri(self, uri: JoinablePathLike) -> UPath:
"""Join with urljoin behavior for UPath instances"""
Expand Down
7 changes: 7 additions & 0 deletions upath/implementations/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def __vfspath__(self) -> str:
return f"{path}{self.root}"
return path

@property
def path(self) -> str:
self_path = super().path
if self._relative_base is None and self.parser.sep not in self_path:
return self_path + self.root
return self_path

def mkdir(
self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False
) -> None:
Expand Down
5 changes: 5 additions & 0 deletions upath/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def __str__(self) -> str:
sr = urlsplit(super().__str__())
return sr._replace(path=sr.path or "/").geturl()

@property
def path(self) -> str:
sr = urlsplit(super().path)
return sr._replace(path=sr.path or "/").geturl()

def is_file(self) -> bool:
try:
next(super().iterdir())
Expand Down
28 changes: 28 additions & 0 deletions upath/tests/test_chain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pytest
Expand All @@ -18,6 +19,33 @@ def test_chaining_upath_protocol(urlpath, expected):
assert pth.protocol == expected


def add_current_drive_on_windows(pth: str) -> str:
drive = os.path.splitdrive(Path.cwd().as_posix())[0]
return f"{drive}{pth}"


@pytest.mark.parametrize(
"urlpath,expected",
[
pytest.param(
"simplecache::file:///tmp",
add_current_drive_on_windows("/tmp"),
),
pytest.param(
"zip://file.txt::file:///tmp.zip",
"file.txt",
),
pytest.param(
"zip://a/b/c.txt::simplecache::memory://zipfile.zip",
"a/b/c.txt",
),
],
)
def test_chaining_upath_path(urlpath, expected):
pth = UPath(urlpath)
assert pth.path == expected


@pytest.mark.parametrize(
"urlpath,expected",
[
Expand Down