This issue is part of a Codex global repository code scan.
MultiSystems.from_dir() prepends ./ to dir_name before globbing. When dir_name is already absolute, the search path becomes relative to the current working directory, so valid absolute directories can silently return an empty MultiSystems.
Affected code:
|
def from_dir( |
|
cls, |
|
dir_name: str, |
|
file_name: str, |
|
fmt: str = "auto", |
|
type_map: list[str] | None = None, |
|
): |
|
multi_systems = cls() |
|
target_file_list = sorted( |
|
glob.glob(f"./{dir_name}/**/{file_name}", recursive=True) |
|
) |
|
for target_file in target_file_list: |
|
multi_systems.append( |
|
LabeledSystem(file_name=target_file, fmt=fmt, type_map=type_map) |
|
) |
Minimal reproducer from the repository root:
from pathlib import Path
import dpdata
rel = dpdata.MultiSystems.from_dir("tests/poscars", "OUTCAR.h2o.md", fmt="vasp/outcar")
print("relative", len(rel), rel.get_nframes())
absdir = str(Path("tests/poscars").resolve())
abs_ms = dpdata.MultiSystems.from_dir(absdir, "OUTCAR.h2o.md", fmt="vasp/outcar")
print("absolute", len(abs_ms), abs_ms.get_nframes())
Current output:
relative 1 3
absolute 0 0
Expected behavior: absolute and relative directory arguments should search the same target directory and return the same systems.
This issue is part of a Codex global repository code scan.
MultiSystems.from_dir()prepends./todir_namebefore globbing. Whendir_nameis already absolute, the search path becomes relative to the current working directory, so valid absolute directories can silently return an emptyMultiSystems.Affected code:
dpdata/dpdata/system.py
Lines 1478 to 1492 in a7a50bf
Minimal reproducer from the repository root:
Current output:
Expected behavior: absolute and relative directory arguments should search the same target directory and return the same systems.