-
Notifications
You must be signed in to change notification settings - Fork 7
Fix file glob not correctly reading sdfs with prefixed files #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,21 +96,35 @@ def _process_latex_name(variable_name: str) -> str: | |||||
| return variable_name | ||||||
|
|
||||||
|
|
||||||
| def _resolve_glob(path_glob: PathLike | Iterable[PathLike]): | ||||||
| """ | ||||||
| Normalise input path_glob into a sorted list of absolute, resolved Path objects. | ||||||
| def _resolve_glob(path_glob: PathLike | Iterable[PathLike]) -> list[Path]: | ||||||
| """Resolve an input path/glob to sorted absolute SDF file paths. | ||||||
|
|
||||||
| Accepts either a single path-like glob pattern (e.g. ``"*.sdf"``) or a | ||||||
| list of path-like file names. | ||||||
| """ | ||||||
|
|
||||||
| try: | ||||||
| if isinstance(path_glob, PathLike): | ||||||
| p = Path(path_glob) | ||||||
| paths = list(p.parent.glob(p.name)) if p.name == "*.sdf" else list(p) | ||||||
| except TypeError: | ||||||
| if p.is_dir(): | ||||||
| raise TypeError( | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is less an issue of typing and more an issue of passing an incompatible value.
Suggested change
|
||||||
| "Directory paths are not supported; pass a glob pattern" | ||||||
| f"(e.g. {(p / '*.sdf').as_posix()}) or a list of file paths" | ||||||
| f"(e.g. {[(p / '0000.sdf').as_posix(), (p / '0001.sdf').as_posix()]})." | ||||||
| ) | ||||||
| paths = list(p.parent.glob(p.name)) | ||||||
| else: | ||||||
| paths = list({Path(p) for p in path_glob}) | ||||||
|
|
||||||
| paths = sorted(p.resolve() for p in paths) | ||||||
| if not paths: | ||||||
| resolved_paths = sorted(p.resolve() for p in paths) | ||||||
| if not resolved_paths: | ||||||
| raise FileNotFoundError(f"No files matched pattern or input: {path_glob!r}") | ||||||
| return paths | ||||||
|
|
||||||
| for p in resolved_paths: | ||||||
| if not p.is_file(): | ||||||
| raise FileNotFoundError(f"{p.as_posix()} does not exist or is not a file.") | ||||||
| if p.suffix.lower() != ".sdf": | ||||||
| raise FileNotFoundError(f"{p.as_posix()} is not an SDF file.") | ||||||
|
Comment on lines
+125
to
+126
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it matter if users are renaming their |
||||||
| return resolved_paths | ||||||
|
|
||||||
|
|
||||||
| def _build_datatree_from_dataset( | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this change. I'd normally trust duck typing over direct type checks. Trying
p = Path(path_glob)and catching the exception if it fails is probably safer.