Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(hot_reload): enhance extension loading by checking parent direct…
…ory modules

- Added functionality to check for a setup function in the parent directory's module file, improving the extension loading process.
- Introduced logging for found modules to aid in debugging and traceability of loaded extensions.
  • Loading branch information
kzndotsh committed Jan 25, 2026
commit 515197e446ee5ed5bbf3cd5f699170179bc9c062
14 changes: 13 additions & 1 deletion src/tux/services/hot_reload/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def path_from_extension(extension: str, *, base_dir: Path | None = None) -> Path
return base_dir / Path(*parts[1:]) / f"{parts[-1]}.py"


def get_extension_from_path(file_path: Path, base_dir: Path) -> str | None:
def get_extension_from_path(file_path: Path, base_dir: Path) -> str | None: # noqa: PLR0911
"""
Convert file path to extension name.

Expand Down Expand Up @@ -68,6 +68,7 @@ def get_extension_from_path(file_path: Path, base_dir: Path) -> str | None:
# Check parent directory for cog (for supporting files in subdirs)
if len(parts) > 1:
parent_module_name = "tux." + ".".join(parts[:-1])
parent_dir_name = parts[-2] # Name of the parent directory

# Try parent's __init__.py for setup
with suppress(ImportError, AttributeError):
Expand All @@ -83,6 +84,17 @@ def get_extension_from_path(file_path: Path, base_dir: Path) -> str | None:
logger.trace(f"Found cog.py: {parent_module_name}.cog")
return f"{parent_module_name}.cog"

# Try {parent_dir_name}.py in parent directory (e.g., info.py for info module)
with suppress(ImportError, AttributeError):
module_file = importlib.import_module(
f"{parent_module_name}.{parent_dir_name}",
)
if hasattr(module_file, "setup") and callable(module_file.setup):
logger.trace(
f"Found {parent_dir_name}.py: {parent_module_name}.{parent_dir_name}",
)
return f"{parent_module_name}.{parent_dir_name}"
Comment on lines 87 to 96

Choose a reason for hiding this comment

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

Good addition! This enhancement to the hot reload system properly handles the new module structure where the main cog file has the same name as its parent directory (e.g., info.py in the info module). This ensures that changes to the main info command file will trigger proper hot reloading.


logger.trace(f"Not a loadable extension: {module_name}")
return None

Expand Down
Loading