Skip to content

Commit

Permalink
Add error if the path does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed May 14, 2023
1 parent df49482 commit 9233827
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
32 changes: 16 additions & 16 deletions pyfileindex/pyfileindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ 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 Expand Up @@ -151,10 +154,7 @@ def _get_changes_quick(self):
list: pandas.DataFrame with new entries, list of changed files and list of deleted paths
"""
path_exists_bool_lst = [os.path.exists(p) for p in self._df.path.values]
if len(path_exists_bool_lst) != 0:
path_deleted_lst = self._df[~np.array(path_exists_bool_lst)].path.values
else:
path_deleted_lst = np.array([])
path_deleted_lst = self._df[~np.array(path_exists_bool_lst)].path.values
df_exists = self._df[path_exists_bool_lst]
stat_lst = [os.stat(p) for p in df_exists.path.values]
st_mtime = [s.st_mtime for s in stat_lst]
Expand Down
6 changes: 2 additions & 4 deletions tests/test_pyfileindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,5 @@ def test_get_changes_quick(self):
if os.name != "nt":
self.assertEqual(files_changed_lst, [])
self.assertEqual(path_deleted_lst.tolist(), [])
_, files_changed_lst, path_deleted_lst = self.fi_with_filter.open("no_such_folder")._get_changes_quick()
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 9233827

Please sign in to comment.