-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Upon trying to send in pathlib.Path objects to exodusii.exo_file() I end up getting an error in glob.glob() that kind of says what the problem is but isn't very user friendly to newer python developers.
I'd like to get full support for pathlib.Path objects or a strong type check on the files with a well-written error message. It seems that it is possible to put stars and question marks in pathlib.Path objects, so maybe all we need to do is cast pathlib.Path to str if we encounter any?
>>> p = pathlib.Path("foo/bar.?.*")
>>> p
PosixPath('foo/bar.?.*')
>>> p.resolve()
PosixPath('/Users/mswan/foo/bar.?.*')
>>> str(p)
'foo/bar.?.*'
Other than testing the new feature, an implementation would be this:
mswan@cee-pp-ldrd02 $ git diff __init__.py
diff --git a/exodusii/__init__.py b/exodusii/__init__.py
index 19e62be..c696f7f 100644
--- a/exodusii/__init__.py
+++ b/exodusii/__init__.py
@@ -32,9 +32,13 @@ exo_file = File
def _find_files(*files):
import glob
+ import pathlib
found = []
for file in files:
+ if isinstance(file, pathlib.Path):
+ found.append(str(file.resolve()))
+ continue
globbed_files = glob.glob(file)
if not globbed_files:
raise FileNotFoundError(file)
Metadata
Metadata
Assignees
Labels
No labels