-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility with pathlib.Path to python readers (#699)
* add compatibility with pathlib.Path to root_io * outsource TypeError handling to os.fspath * add pathlib compatibility in sio_io as well * sio_io: only store first path in list returned by convert_to_str_paths * make ruff import sorting happy * outsource convert_to_str_paths * Fix imports to be absolute * Add module docstring to fix pylint complaints
- Loading branch information
1 parent
b5cddb7
commit d1bb7b0
Showing
3 changed files
with
45 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
"""utility functionality for podio""" | ||
|
||
import os | ||
from collections.abc import Iterable | ||
from pathlib import Path | ||
|
||
|
||
def convert_to_str_paths(filenames): | ||
"""Converts filenames to string paths, handling both string and pathlib.Path objects and | ||
iterables of such objects. | ||
Args: | ||
filenames (str, Path, or Iterable[str | Path]): A single filepath or an iterable of | ||
filepaths to convert to str object(s). | ||
Returns: | ||
list[str]: A list of filepaths as strings. | ||
""" | ||
|
||
if isinstance(filenames, Iterable) and not isinstance(filenames, (str, Path)): | ||
return [os.fspath(fn) for fn in filenames] | ||
|
||
return [os.fspath(filenames)] |