Skip to content

Dev#232

Closed
JulianKimmig wants to merge 2 commits intotestfrom
dev
Closed

Dev#232
JulianKimmig wants to merge 2 commits intotestfrom
dev

Conversation

@JulianKimmig
Copy link
Member

No description provided.

Introduce cache helpers for path/meta handling and atomic writes.
Cover cache read/write and clearing flows with funcnodes pytest cases.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bumps the version from 2.1.0 to 2.2.0 and introduces cache utility functions for managing cached data with atomic write operations and metadata support.

  • Adds a new cache utilities module (cache.py) with functions for managing cache directories, files, and metadata
  • Implements comprehensive test coverage for all cache utility functions
  • Updates version across project files and adds changelog entry

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pyproject.toml Version bump from 2.1.0 to 2.2.0
uv.lock Synchronized version update to 2.2.0
CHANGELOG.md Added v2.2.0 release entry documenting new cache utilities feature
src/funcnodes_core/utils/cache.py New module providing cache directory management, atomic file writes, and metadata handling functions
tests/test_cache_utils.py Comprehensive test suite covering all cache utility functions including edge cases and error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



def set_cache_meta_for(cache_path: Path, meta: dict[str, Any]):
"""Write JSON metadata for a given cache file (atomic)."""
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is missing documentation for the meta parameter. According to best practices, all function parameters should be documented, especially for public API functions.

Suggested change
"""Write JSON metadata for a given cache file (atomic)."""
"""
Write JSON metadata for a given cache file (atomic).
Args:
cache_path: Path to the cache file.
meta: Metadata dictionary to write as JSON.
"""

Copilot uses AI. Check for mistakes.


def get_cache_meta_for(cache_path: Path) -> Optional[dict[str, Any]]:
"""Read JSON metadata for a given cache file, if present."""
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is missing documentation for the cache_path parameter. According to best practices, all function parameters should be documented, especially for public API functions.

Suggested change
"""Read JSON metadata for a given cache file, if present."""
"""
Read JSON metadata for a given cache file, if present.
Args:
cache_path: Path to the cache file whose metadata should be read.
"""

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +57
Write text to cache_path using a temp file + atomic replace.

This avoids partially-written cache files if the process crashes mid-write.
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is missing documentation for parameters (cache_path, text, encoding) and lacks a description of the return value or behavior. According to best practices, all function parameters should be documented, especially for public API functions.

Suggested change
Write text to cache_path using a temp file + atomic replace.
This avoids partially-written cache files if the process crashes mid-write.
Write text to a cache file atomically.
This function writes the given text to the specified cache_path using a temporary file and atomic replace,
which avoids partially-written cache files if the process crashes mid-write.
Args:
cache_path (Path): The path to the cache file to write.
text (str): The text content to write to the cache file.
encoding (str, optional): The encoding to use when writing the file. Defaults to "utf-8".
Returns:
None

Copilot uses AI. Check for mistakes.


@funcnodes_test
def test_chache_meta_exception_handling():
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name contains a typo: "chache" should be spelled "cache".

Suggested change
def test_chache_meta_exception_handling():
def test_cache_meta_exception_handling():

Copilot uses AI. Check for mistakes.
return None


def set_cache_meta_for(cache_path: Path, meta: dict[str, Any]):
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for the meta parameter is dict[str, Any], but the function actually accepts any type as demonstrated in the test where a string "hello" is passed. The type annotation should be Any to match the actual behavior, or the function should validate that only dict types are accepted.

Suggested change
def set_cache_meta_for(cache_path: Path, meta: dict[str, Any]):
def set_cache_meta_for(cache_path: Path, meta: Any):

Copilot uses AI. Check for mistakes.
return cache_path.with_suffix(cache_path.suffix + ".meta.json")


def get_cache_meta_for(cache_path: Path) -> Optional[dict[str, Any]]:
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation is Optional[dict[str, Any]], but the function can return any type that was stored via set_cache_meta_for. As shown in the test, a string "hello" can be stored and retrieved. The return type should be Optional[Any] to accurately reflect the actual behavior.

Suggested change
def get_cache_meta_for(cache_path: Path) -> Optional[dict[str, Any]]:
def get_cache_meta_for(cache_path: Path) -> Optional[Any]:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants