Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPath: Add append_to_stem #4

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
7 changes: 7 additions & 0 deletions stgpytools/types/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, TypeAlias, Union

from ..functions import to_arr

__all__ = [
'FilePathType', 'FileDescriptor',
'FileOpener',
Expand Down Expand Up @@ -99,5 +101,10 @@ def write_lines(
) -> int:
return super().write_text('\n'.join(data), encoding, errors, newline)

def append_to_stem(self, suffixes: str | Iterable[str], sep: str = '_') -> SPath:
"""Append a suffix to the stem of the path"""

return self.with_stem(sep.join([self.stem, *to_arr(suffixes)])) # type:ignore[list-item]


SPathLike = Union[str, Path, SPath]
Loading