Skip to content

Commit

Permalink
Merge pull request #77 from pyiron/handle_empty_path_lst
Browse files Browse the repository at this point in the history
Handle files which do not exist
  • Loading branch information
jan-janssen committed May 14, 2023
2 parents 24709ed + 8150a08 commit b5aea98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pyfileindex/pyfileindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,25 @@ def open(self, path):
PyFileIndex: PyFileIndex for subdirectory
"""
abs_path = os.path.abspath(os.path.expanduser(os.path.join(self._path, path)))
if abs_path == self._path:
return self
elif os.path.commonpath([abs_path, self._path]) == self._path:
return PyFileIndex(
path=abs_path,
filter_function=self._filter_function,
debug=self._debug,
df=self._df[self._df["path"].str.contains(abs_path)],
)
if os.path.exists(abs_path):
if abs_path == self._path:
return self
elif os.path.commonpath([abs_path, self._path]) == self._path:
return PyFileIndex(
path=abs_path,
filter_function=self._filter_function,
debug=self._debug,
df=self._df[self._df["path"].str.contains(abs_path)],
)
else:
return PyFileIndex(
path=abs_path,
filter_function=self._filter_function,
debug=self._debug,
)
else:
return PyFileIndex(
path=abs_path, filter_function=self._filter_function, debug=self._debug
raise FileNotFoundError(
"The path " + abs_path + " does not exist on your filesystem."
)

def update(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pyfileindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,5 @@ def test_get_changes_quick(self):
if os.name != "nt":
self.assertEqual(files_changed_lst, [])
self.assertEqual(path_deleted_lst.tolist(), [])
with self.assertRaises(FileNotFoundError):
_, files_changed_lst, path_deleted_lst = self.fi_with_filter.open("no_such_folder")._get_changes_quick()

0 comments on commit b5aea98

Please sign in to comment.