Skip to content

Commit

Permalink
Merge pull request #342 from libAtoms/configset_nonexistent_files
Browse files Browse the repository at this point in the history
better error message when ConfigSet is passed a nonexistent file/glob
  • Loading branch information
bernstei authored Oct 10, 2024
2 parents fe86214 + a47203f commit 3a5c4e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wfl/configset.py
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ def __init__(self, items, *, file_root=None, read_kwargs={}, _open_reader=None,
# single item, could be a simple filename or a glob. Former needs to be stored as
# Path, latter as list(Path)
items_expanded = [Path(f) for f in sorted(glob.glob(str(file_root / items), recursive=True))]
if len(items_expanded) == 0:
raise ValueError(f"got file '{file_root}' / '{items}' that does not exist")
if len(items_expanded) == 1 and file_root / items == items_expanded[0]:
self.items = file_root / items
else:
@@ -95,7 +97,10 @@ def __init__(self, items, *, file_root=None, read_kwargs={}, _open_reader=None,
assert isinstance(file_path, (str, Path))
if file_root != Path("") and Path(file_path).is_absolute():
raise ValueError(f"Got file_root but file {file_path} is an absolute path")
self.items.extend([Path(f) for f in sorted(glob.glob(str(file_root / file_path), recursive=True))])
items_expanded = [Path(f) for f in sorted(glob.glob(str(file_root / file_path), recursive=True))]
if len(items_expanded) == 0:
raise ValueError(f"got file '{file_root}' / '{file_path}' that does not exist")
self.items.extend(items_expanded)
elif isinstance(items[0], ConfigSet):
self.items = []
for item in items:

0 comments on commit 3a5c4e5

Please sign in to comment.