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
2 changes: 0 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
strategy:
matrix:
include:
- python-version: "3.9"
tox-env: py39
- python-version: "3.10"
tox-env: py310
- python-version: "3.11"
Expand Down
1 change: 0 additions & 1 deletion .python-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
3.9
3.10
3.11
3.12
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ learning training with batteries included. It supports
## Dependency

- HDFS client and libhdfs for HDFS access
- CPython >= 3.9
- CPython >= 3.10

## Installation and Document build

Expand Down
31 changes: 6 additions & 25 deletions pfio/v2/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ def _has_directory_feature(fs: FS) -> bool:
return True


def _removeprefix(text: str, prefix: str) -> str:
# NOTE: `str.removeprefix` supports version 3.9 or higher.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I won't understand this change unless this comment, but I don't think this line is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it would be better to simply replace it with the default removeprefix function.

if text.startswith(prefix):
return text[len(prefix):]
return text


def _compare_fs(lhs: FS, rhs: FS) -> bool:
if type(lhs) is type(rhs):
assert isinstance(lhs.cwd, str)
Expand Down Expand Up @@ -254,7 +247,7 @@ def as_uri(self) -> str:

prefix = self._fs.cwd
assert isinstance(prefix, str)
key = _removeprefix(self.as_posix(), self.sep)
key = self.as_posix().removeprefix(self.sep)

parsed = ParseResult(
scheme=self.scheme,
Expand All @@ -273,11 +266,6 @@ def is_absolute(self) -> bool:
return self._pure.is_absolute()

def is_relative_to(self, *other: Union[str, PathLike]) -> bool:
if python_version_info.minor < 9:
raise NotImplementedError(
"`is_relative_to()` supports python 3.9 or higher"
)

# Same rationale as `relative_to`: unwrap pfio PurePath so
# 3.14's stdlib does not skip its `PurePosixPath` coercion,
# and shim the multi-arg form that stdlib removed in 3.14.
Expand Down Expand Up @@ -375,14 +363,7 @@ def with_name(self: SelfPurePathType, name: str) -> SelfPurePathType:
return self.with_segments(self._pure.with_name(name))

def with_stem(self: SelfPurePathType, stem: str) -> SelfPurePathType:
if python_version_info.minor < 9:
raise NotImplementedError(
"`with_stem()` supports python 3.9 or higher"
)
else:
return self.with_segments(
self._pure.with_stem(stem) # type: ignore
)
return self.with_segments(self._pure.with_stem(stem))

def with_suffix(self: SelfPurePathType, suffix: str) -> SelfPurePathType:
return self.with_segments(self._pure.with_suffix(suffix))
Expand Down Expand Up @@ -421,7 +402,7 @@ def __init__(
super().__init__(*args, fs=fs, scheme=scheme)

def _as_relative_to_fs(self) -> str:
return _removeprefix(self.as_posix(), self.anchor)
return self.as_posix().removeprefix(self.anchor)

# ---------------------------------------
# pathlib.Path compatible classmethods
Expand Down Expand Up @@ -622,13 +603,13 @@ def rename(
# we implemented by `copy` + `remove`.
# it is generic but poor performance...
target = self.with_segments(
_removeprefix(str(target), self.anchor)
str(target).removeprefix(self.anchor)
)
copy(self, target)
unlink(self)
else:
target = (
_removeprefix(target.as_posix(), self.anchor)
target.as_posix().removeprefix(self.anchor)
if isinstance(target, PurePath)
else target
)
Expand Down Expand Up @@ -660,7 +641,7 @@ def rglob(
case_sensitive: Optional[bool] = None,
) -> Iterator[SelfPathType]:
return self.glob(
joinpath("**", _removeprefix(pattern, self.sep)),
joinpath("**", pattern.removeprefix(self.sep)),
case_sensitive=case_sensitive,
)

Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ classifiers = [
"Intended Audience :: Developers",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: System :: Filesystems",
]
requires-python = ">=3.9"
requires-python = ">=3.10"
dependencies = [
"boto3",
"deprecation",
Expand Down Expand Up @@ -78,7 +77,7 @@ module = [
ignore_missing_imports = true

[tool.tox]
env_list = ["py39", "py310", "py311", "py312", "py313", "py314", "doc"]
env_list = ["py310", "py311", "py312", "py313", "py314", "doc"]

[tool.tox.env_run_base]
runner = "uv-venv-runner"
Expand Down
7 changes: 3 additions & 4 deletions tests/v2_tests/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from moto import mock_aws

from pfio.v2 import Local, from_url
from pfio.v2.pathlib import (Path, PurePath, _has_directory_feature,
_removeprefix, unlink)
from pfio.v2.pathlib import Path, PurePath, _has_directory_feature, unlink


class TemporaryS3Bucket:
Expand Down Expand Up @@ -423,7 +422,7 @@ def test_purepath_compatible_methods(
unparsed = ParseResult(
parsed.scheme,
parsed.netloc,
os.path.join(parsed.path, _removeprefix(path, "/")),
os.path.join(parsed.path, path.removeprefix("/")),
parsed.params,
parsed.query,
parsed.fragment,
Expand Down Expand Up @@ -476,7 +475,7 @@ def test_purepath_compatible_methods(
)
def test_path_stat(storage: str, path: str) -> None:
with from_url(url=storage) as fs:
p = Path(_removeprefix(path, "/"), fs=fs)
p = Path(path.removeprefix("/"), fs=fs)
if p.is_file():
stat = p.stat()
assert stat.size > 0 or stat.last_modified is not None
Expand Down
Loading