Skip to content

Commit

Permalink
SPath: Add append_to_stem
Browse files Browse the repository at this point in the history
Append a list of suffixes to the current stem. This is mainly meant to be a convenience method for stuff like iterating over a list and storing the index in the filepath to disambiguate between files.

append_to_stem: `"` -> `'`

append_to_stem: Use to_arr

append_to_stem: list -> Iterable

append_to_stem: Add sep param
  • Loading branch information
LightArrowsEXE committed Jun 3, 2024
1 parent cbcc929 commit 8f2555b
Showing 1 changed file with 7 additions and 0 deletions.
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]

0 comments on commit 8f2555b

Please sign in to comment.