Skip to content

Commit

Permalink
add more comments to explain the weird function caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Walavouchey committed Nov 23, 2023
1 parent 97769c9 commit a12c8f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


def clear_function_cache():
# exists_case_insensitive does some internal caching, making it stateful
# exists_case_insensitive does some internal caching of the directory tree, making it stateful
# during normal execution, the current working directory never changes, but tests use a new temporary directory for each test case
if hasattr(exists_case_insensitive, 'all_article_paths_lowercased'):
delattr(exists_case_insensitive, 'all_article_paths_lowercased')

Expand Down
1 change: 1 addition & 0 deletions wikitools/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def exists_case_insensitive(path: pathlib.Path):
return path.exists()
else:
# case-insensitive directory/file existence checking isn't trivial in case-sensitive file systems because os-provided existence checks can't be relied upon
# this cache would only become invalid when the current working directory changes, which only happens in tests and not during normal execution
if not hasattr(exists_case_insensitive, 'all_article_paths_lowercased'):
article_set = set(normalised(article_path.lower()) for article_path in itertools.chain(list_all_article_dirs(), list_all_files(["wiki", "news"])))
setattr(exists_case_insensitive, 'all_article_paths_lowercased', article_set)
Expand Down

0 comments on commit a12c8f3

Please sign in to comment.