Skip to content

Commit

Permalink
outsource convert_to_str_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-Schwan authored and tmadlener committed Nov 8, 2024
1 parent 692a728 commit ef70986
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
23 changes: 2 additions & 21 deletions python/podio/root_io.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
"""Python module for reading root files containing podio Frames"""

from collections.abc import Iterable
import os
from pathlib import Path
from ROOT import gSystem

from utils import convert_to_str_paths

gSystem.Load("libpodioRootIO") # noqa: E402
from ROOT import podio # noqa: E402 # pylint: disable=wrong-import-position

Expand All @@ -17,24 +16,6 @@
)


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)]


class Reader(BaseReaderMixin):
"""Reader class for reading podio root files."""

Expand Down
3 changes: 2 additions & 1 deletion python/podio/sio_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""Python module for reading sio files containing podio Frames"""

from ROOT import gSystem
from root_io import convert_to_str_paths

from utils import convert_to_str_paths

if gSystem.DynamicPathName("libpodioSioIO.so", True):
gSystem.Load("libpodioSioIO") # noqa: 402
Expand Down
21 changes: 21 additions & 0 deletions python/podio/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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)]

0 comments on commit ef70986

Please sign in to comment.