Skip to content

Commit 3ee8477

Browse files
committed
seppl.io.locate_files can take a default_glob now that gets appended to inputs that point to dirs
1 parent 8637403 commit 3ee8477

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
0.2.5 (2024-06-18)
5+
------------------
6+
7+
- the `seppl.io.locate_files` method can take a default glob now, which gets appended
8+
to inputs that point to directories
9+
10+
411
0.2.4 (2024-05-06)
512
------------------
613

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _read(f):
3030
'': 'src'
3131
},
3232
packages=find_namespace_packages(where='src'),
33-
version="0.2.4",
33+
version="0.2.5",
3434
author='Peter Reutemann',
3535
author_email='fracpete@waikato.ac.nz',
3636
entry_points={

src/seppl/io/_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55

66

77
def locate_files(inputs: Union[str, List[str]], input_lists: Union[str, List[str]] = None,
8-
fail_if_empty: bool = False) -> List[str]:
8+
fail_if_empty: bool = False, default_glob: str = None) -> List[str]:
99
"""
1010
Locates all the files from the specified inputs, which may contain globs.
1111
glob results get sorted to ensure the same file order each time.
12+
If default_glob is not None and the inputs are pointing to directories, then default_glob
13+
gets appended.
1214
1315
:param inputs: the input path(s) with optional globs
1416
:type inputs: str or list
1517
:param input_lists: text file(s) that list the actual input files to use
1618
:type input_lists: str or list
1719
:param fail_if_empty: whether to throw an exception if no files were located
1820
:type fail_if_empty: bool
21+
:param default_glob: the default glob to use, ignored if None
22+
:type default_glob: str
1923
:return: the expanded list of files
2024
:rtype: list
2125
"""
@@ -30,6 +34,11 @@ def locate_files(inputs: Union[str, List[str]], input_lists: Union[str, List[str
3034
else:
3135
raise Exception("Invalid inputs, must be string(s)!")
3236

37+
if default_glob is not None:
38+
for i, inp in enumerate(inputs):
39+
if os.path.isdir(inp):
40+
inputs[i] = os.path.join(inp, default_glob)
41+
3342
if input_lists is not None:
3443
if isinstance(input_lists, str):
3544
input_lists = [input_lists]

0 commit comments

Comments
 (0)