Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SHELL := /bin/bash
PROJECT_NAME := djhtmx

UV ?= uv
UV_RUN ?= uv run
UV_RUN ?= $(UV) run
UV_PYTHON_PREFERENCE ?= only-managed
RUN ?= $(UV_RUN)

Expand Down
31 changes: 17 additions & 14 deletions src/djhtmx/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import contextlib
import importlib
import logging
import pkgutil
import typing as t
from urllib.parse import urlparse
Expand Down Expand Up @@ -129,17 +129,20 @@
- htmx.py files (like standard autodiscover_modules("htmx"))
- All Python files under htmx/ directories in apps (recursively)
"""

def _import_modules_recursively(module_name):
"""Recursively import a module and all its submodules."""
with contextlib.suppress(ImportError):
module = importlib.import_module(module_name)

# If this is a package, recursively import all modules in it
if hasattr(module, "__path__"):
for _finder, submodule_name, _is_pkg in pkgutil.iter_modules(module.__path__):
_import_modules_recursively(f"{module_name}.{submodule_name}")

for app_config in apps.get_app_configs():
# Import htmx module and all its submodules recursively
_import_modules_recursively(f"{app_config.name}.htmx")
module_name = f"{app_config.module.__name__}.htmx"

Check failure on line 133 in src/djhtmx/utils.py

View workflow job for this annotation

GitHub Actions / Type Check

"__name__" is not a known attribute of "None" (reportOptionalMemberAccess)
try:
module = importlib.import_module(module_name)
except ImportError:
logger.warning("Could not import %s", module_name)
continue
if hasattr(module, "__path__"):
# If it's a package, recursively walk it importing all modules and packages.
for info in pkgutil.walk_packages(module.__path__, prefix=module_name + "."):
if not info.ispkg:
# `walk_packages` only imports packages, not modules; we need to import them
# all.
importlib.import_module(info.name)


logger = logging.getLogger(__name__)
Loading