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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15']
session: ['tests']

include:
Expand All @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
pyv: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14', '3.15']

steps:
- name: Check out the repository
Expand Down
186 changes: 93 additions & 93 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/concepts/pathlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pathlib-abc extracts the core concepts from Python's pathlib module into abstrac
4. **Ensure compatibility** between different path implementations

!!! info "Relationship to Python's pathlib"
Currently (as of Python 3.14), the standard library `pathlib.Path` does **not** inherit from public pathlib-abc classes. However, there is ongoing work to incorporate these ABCs into future Python releases.
Currently (as of Python 3.15), the standard library `pathlib.Path` does **not** inherit from public pathlib-abc classes. However, there is ongoing work to incorporate these ABCs into future Python releases.

The library defines three main abstract base classes that represent different levels of path functionality:

Expand Down
2 changes: 1 addition & 1 deletion docs/why.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ s3_result = process_file(UPath("s3://bucket/file.txt"))
Universal Pathlib runs a large subset of CPython's pathlib test suite:

- :white_check_mark: **Compatibility tested** against standard library pathlib
- :white_check_mark: **Cross-version tested** on Python 3.9-3.14
- :white_check_mark: **Cross-version tested** on Python 3.9-3.15
- :white_check_mark: **Integration tested** with real filesystems
- :white_check_mark: **Regression tested** for each release

Expand Down
9 changes: 2 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
locations = ("upath",)
running_in_ci = os.environ.get("CI", "") != ""

SUPPORTED_PYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
SUPPORTED_PYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
BASE_PYTHON = SUPPORTED_PYTHONS[-3]
MIN_PYTHON = SUPPORTED_PYTHONS[0]

Expand Down Expand Up @@ -52,12 +52,7 @@ def FSSPEC_MIN_VERSION() -> str:
@nox.session(python=SUPPORTED_PYTHONS)
def tests(session: nox.Session) -> None:
"""Run the test suite."""
# workaround in case no aiohttp binary wheels are available
if session.python == "3.14":
session.env["AIOHTTP_NO_EXTENSIONS"] = "1"
session.install(".[tests,dev]", "pydantic>=2.12.0a1")
else:
session.install(".[tests,dev,dev-third-party]")
session.install(".[tests,dev,dev-third-party]")
session.run("uv", "pip", "freeze", silent=not running_in_ci)
session.run(
"pytest",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Development Status :: 4 - Beta",
]
keywords = ["filesystem-spec", "pathlib"]
Expand Down
2 changes: 1 addition & 1 deletion typesafety/test_upath_interface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from upath import UPath

p = UPath("abc")
reveal_type(p._url) # NR: Revealed type is "[Tt]uple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult\]"
reveal_type(p._url) # NR: Revealed type is "[Tt]uple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult(\[(builtins\.)?str\])?\]"

# === upath pathlib.PurePath interface ================================

Expand Down
2 changes: 1 addition & 1 deletion typesafety/test_upath_signatures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
from upath import UPath

p = UPath("")
reveal_type(p._url) # NR: Revealed type is "tuple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult\]"
reveal_type(p._url) # NR: Revealed type is "tuple\[(builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, (builtins\.)?str, fallback=urllib.parse.SplitResult(\[(builtins\.)?str\])?\]"

# FIXME fsspec types are not available
# - case: upath_attribute_fs
Expand Down
8 changes: 8 additions & 0 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,10 +1399,18 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
"""
Create a new directory at this given path.
"""
if parent_mode is not None:
warnings.warn(
f"{type(self).__name__}.mkdir(): parent_mode is currently ignored.",
UserWarning,
stacklevel=2,
)
if parents and not exist_ok and self.exists():
raise FileExistsError(str(self))
try:
Expand Down
7 changes: 6 additions & 1 deletion upath/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
self.__wrapped__.mkdir(mode=mode, parents=parents, exist_ok=exist_ok)
kw: dict[str, Any] = {}
if parent_mode is not None:
kw["parent_mode"] = parent_mode
self.__wrapped__.mkdir(mode=mode, parents=parents, exist_ok=exist_ok, **kw)

def __open_writer__(self, mode: Literal["a", "w", "x"]) -> BinaryIO:
return self.__wrapped__.__open_writer__(mode)
Expand Down
24 changes: 20 additions & 4 deletions upath/implementations/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,18 @@ def parts(self) -> Sequence[str]:
return parts

def mkdir(
self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False
self,
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
if not parents and not exist_ok and self.exists():
raise FileExistsError(self.path)
super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok)
super().mkdir(
mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode
)


class GCSPath(CloudPath):
Expand All @@ -121,10 +128,17 @@ def __init__(
raise ValueError("non key-like path provided (bucket/container missing)")

def mkdir(
self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False
self,
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
try:
super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok)
super().mkdir(
mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode
)
except TypeError as err:
if "unexpected keyword argument 'create_parents'" in str(err):
self.fs.mkdir(self.path)
Expand Down Expand Up @@ -230,6 +244,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise UnsupportedOperation

Expand Down
7 changes: 6 additions & 1 deletion upath/implementations/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ def full_match(self, pattern, *, case_sensitive: bool | None = None) -> bool:
return super().full_match(pattern, case_sensitive=case_sensitive)

def mkdir(
self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False
self,
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise FileExistsError(str(self))

Expand Down
4 changes: 3 additions & 1 deletion upath/implementations/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
try:
return super().mkdir(mode, parents, exist_ok)
return super().mkdir(mode, parents, exist_ok, parent_mode=parent_mode)
except FTPPermanentError as e:
if e.args[0].startswith("550") and exist_ok:
return
Expand Down
2 changes: 2 additions & 0 deletions upath/implementations/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise UnsupportedOperation

Expand Down
11 changes: 9 additions & 2 deletions upath/implementations/hdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ def __init__(
) -> None: ...

def mkdir(
self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False
self,
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
if not exist_ok and self.exists():
raise FileExistsError(str(self))
super().mkdir(mode=mode, parents=parents, exist_ok=exist_ok)
super().mkdir(
mode=mode, parents=parents, exist_ok=exist_ok, parent_mode=parent_mode
)
2 changes: 2 additions & 0 deletions upath/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise UnsupportedOperation

Expand Down
42 changes: 42 additions & 0 deletions upath/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,48 @@ def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None:
else:
shutil.rmtree(self)

if sys.version_info < (3, 15):

def mkdir(
self,
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
if parent_mode is None:
return super().mkdir(mode, parents, exist_ok)
# backport of the parent_mode argument added in python 3.15
try:
super().mkdir(mode, parents=False, exist_ok=exist_ok)
except FileNotFoundError:
if not parents or self.parent == self:
raise
self.parent.mkdir(
mode=parent_mode,
parents=True,
exist_ok=True,
parent_mode=parent_mode,
)
super().mkdir(mode, parents=False, exist_ok=exist_ok)

else:

def is_reserved(self) -> bool:
# pathlib.PurePath.is_reserved() was removed in python 3.15
warnings.warn(
f"{type(self).__name__}.is_reserved() is deprecated. Use"
" os.path.isreserved() to detect reserved paths on Windows.",
DeprecationWarning,
stacklevel=2,
)
if os.name == "nt":
import ntpath

return ntpath.isreserved(self)
return False

# we need to override pathlib.Path._copy_from to support it as a
# WritablePath._copy_from target with support for on_name_collision
# Issue: https://github.com/barneygale/pathlib-abc/issues/48
Expand Down
2 changes: 2 additions & 0 deletions upath/implementations/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
# smbclient does not support setting mode externally
from smbprotocol.exceptions import SMBOSError
Expand Down
2 changes: 2 additions & 0 deletions upath/implementations/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise UnsupportedOperation

Expand Down
2 changes: 2 additions & 0 deletions upath/implementations/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def mkdir(
mode: int = 0o777,
parents: bool = False,
exist_ok: bool = False,
*,
parent_mode: int | None = None,
) -> None:
raise UnsupportedOperation

Expand Down
9 changes: 9 additions & 0 deletions upath/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,15 @@ def test_mkdir_parents_true_exists_ok_false(self):
with pytest.raises(FileExistsError):
new_dir.mkdir(parents=True, exist_ok=False)

def test_mkdir_parent_mode(self):
new_dir = self.path.joinpath("parent_mode", "new_dir")
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "parent_mode is currently ignored")
new_dir.mkdir(parents=True, parent_mode=0o755)
if not self.SUPPORTS_EMPTY_DIRS:
new_dir.joinpath(".file").touch()
assert new_dir.is_dir()

def test_touch_exists_ok_false(self):
f = self.path.joinpath("file1.txt")
assert f.exists()
Expand Down
26 changes: 26 additions & 0 deletions upath/tests/implementations/test_local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import sys
import warnings
from pathlib import Path

import pytest
Expand All @@ -9,6 +11,7 @@
from ..cases import BaseTests
from ..utils import OverrideMeta
from ..utils import overrides_base
from ..utils import skip_on_windows
from ..utils import xfail_if_version


Expand Down Expand Up @@ -60,3 +63,26 @@ def path(self, local_testdir):
)
def test_local_paths_are_pathlike(protocol, path):
assert isinstance(UPath(path, protocol=protocol), os.PathLike)


@skip_on_windows
def test_local_mkdir_parent_mode(tmp_path):
umask = os.umask(0)
try:
pth = UPath(tmp_path).joinpath("a", "b", "c")
pth.mkdir(mode=0o700, parents=True, parent_mode=0o750)
finally:
os.umask(umask)
assert pth.stat().st_mode & 0o777 == 0o700
assert pth.parent.stat().st_mode & 0o777 == 0o750
assert pth.parent.parent.stat().st_mode & 0o777 == 0o750


def test_local_is_reserved():
pth = UPath("file.txt")
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
assert pth.is_reserved() is False
if sys.version_info >= (3, 13):
with pytest.warns(DeprecationWarning):
pth.is_reserved()
Loading