Skip to content

Commit

Permalink
sort glob.glob in ConfigSet input to make sure order is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
bernstei committed Mar 6, 2024
1 parent d0e2c66 commit 88458c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/test_configset.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_mult_files_mult_Atoms_glob_dir(tmp_path, ats):
(tmp_path / "dir_0").mkdir()
(tmp_path / "dir_1").mkdir()
ase.io.write(tmp_path / "dir_0" / "ats.xyz", ats[0:5])
ase.io.write(tmp_path / "dir_1" /"ats.xyz", ats[5:10])
ase.io.write(tmp_path / "dir_1" / "ats.xyz", ats[5:10])
locs = [f" / {i0} / {i1}" for i0 in range(2) for i1 in range(5)]

# glob for dir name, but same filename
Expand Down
4 changes: 2 additions & 2 deletions wfl/configset.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, items, *, file_root=None, read_kwargs={}, _open_reader=None,
raise ValueError(f"Got file_root but file {items} is an absolute path")
# 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 glob.glob(str(file_root / items), recursive=True)]
items_expanded = [Path(f) for f in sorted(glob.glob(str(file_root / items), recursive=True))]
if len(items_expanded) == 1 and file_root / items == items_expanded[0]:
self.items = file_root / items
else:
Expand All @@ -95,7 +95,7 @@ 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 glob.glob(str(file_root / file_path), recursive=True)])
self.items.extend([Path(f) for f in sorted(glob.glob(str(file_root / file_path), recursive=True))])
elif isinstance(items[0], ConfigSet):
self.items = []
for item in items:
Expand Down

0 comments on commit 88458c3

Please sign in to comment.