Skip to content

Commit

Permalink
fix crashes on Path.glob
Browse files Browse the repository at this point in the history
  • Loading branch information
jhidding committed Jul 9, 2024
1 parent 0edf419 commit a0ce301
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 13 additions & 2 deletions entangled/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
from pathlib import Path


def safe_glob(pattern):
"""The `glob` method of `Path` raises a FileNotFound error when
there are rapid changes in the filesystem.
`safe_glob` catches this error and returns an empty list instead."""
try:
return Path().glob(pattern)
except FileNotFoundError:
return []


def find_watch_dirs():
"""List all directories that contain files that need watching."""
input_file_list = list_input_files()
Expand All @@ -16,9 +27,9 @@ def find_watch_dirs():

def list_input_files():
"""List all input files."""
include_file_list = chain.from_iterable(map(Path().glob, config.watch_list))
include_file_list = chain.from_iterable(map(safe_glob, config.watch_list))
exclude_file_list = list(
chain.from_iterable(map(Path().glob, config.ignore_list))
chain.from_iterable(map(safe_glob, config.ignore_list))
)
return [path for path in include_file_list if not path in exclude_file_list]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "entangled-cli"
version = "2.0.3"
version = "2.0.4"
description = "Literate Programming toolbox"
repository = "https://github.com/entangled/entangled.py"
homepage = "https://entangled.github.io/"
Expand Down
4 changes: 4 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"venvPath": "/home/johannes/.cache/pypoetry/virtualenvs/",
"venv": "entangled-cli-iqC53p3h-py3.12"
}

0 comments on commit a0ce301

Please sign in to comment.