Skip to content

file_utils

File utilities for hot reload system.

Classes:

Functions:

Classes

FileHashTracker

Python
FileHashTracker()

Tracks file hashes to detect changes.

Initialize the file hash tracker.

Methods:

Functions

get_file_hash
Python
get_file_hash(file_path: Path) -> str

Get SHA-256 hash of file contents.

Returns:

  • str

    The SHA-256 hash of the file, or empty string if error.

has_changed
Python
has_changed(file_path: Path) -> bool

Check if file has changed since last check.

Returns:

  • bool

    True if file has changed, False otherwise.

update_hash
Python
update_hash(file_path: Path) -> None

Update stored hash for a file.

clear
Python
clear() -> None

Clear all stored hashes.

remove_file
Python
remove_file(file_path: Path) -> None

Remove file from tracking.

Functions

path_from_extension

Python
path_from_extension(extension: str, *, base_dir: Path | None = None) -> Path

Convert extension name to file path.

Returns:

  • Path

    The file path for the extension.

get_extension_from_path

Python
get_extension_from_path(file_path: Path, base_dir: Path) -> str | None

Convert file path to extension name.

Handles both flat and nested plugin structures: - src/tux/modules/admin/ban.py → tux.modules.admin.ban - src/tux/plugins/atl/deepfry.py → tux.plugins.atl.deepfry

Returns:

  • str | None

    The extension name if found, None otherwise.

validate_python_syntax

Python
validate_python_syntax(file_path: Path) -> bool

Validate Python syntax of a file.

Returns:

  • bool

    True if syntax is valid, False otherwise.

module_reload_context

Python
module_reload_context(module_name: str)

Context manager for safe module reloading.

reload_module_by_name

Python
reload_module_by_name(module_name: str) -> bool

Reload a module by name.

Returns:

  • bool

    True if reload was successful.

Raises: