Skip to content

Commit 09b2e9a

Browse files
committed
Check if input files exist before using them
1 parent 18d5efd commit 09b2e9a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/pybkgmodel/processing.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import reduce
2-
import glob
2+
from pathlib import Path
33
import inspect
44
from operator import getitem
55
import os
@@ -144,7 +144,19 @@ def __init__(
144144
processing object
145145
"""
146146

147-
self.files = glob.glob(files)
147+
input_files_mask = Path(files).parent
148+
if not input_files_mask.is_dir():
149+
raise FileNotFoundError(
150+
"The configuration key data mask does not point to a valid directory."
151+
)
152+
153+
self.files = [
154+
file_path for file_path in input_files_mask.glob(input_files_mask.name)
155+
]
156+
if len(self.files) == 0:
157+
raise FileNotFoundError(
158+
"No files can be found with the data mask provided in the configuration file."
159+
)
148160
self.runs = tuple(
149161
filter(
150162
lambda r: r.obs_id is not None,

0 commit comments

Comments
 (0)