Skip to content

Commit cd12a7c

Browse files
committed
add IDOM_IGNORED_DJANGO_APPS option
1 parent a0b75e0 commit cd12a7c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/django_idom/app_components.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from django.conf import settings
66
from idom.core.proto import ComponentConstructor
77

8+
from .app_settings import IDOM_IGNORED_DJANGO_APPS
9+
810

911
logger = logging.getLogger(__name__)
1012
_LOADED_COMPONENTS: Dict[str, ComponentConstructor] = {}
@@ -19,6 +21,10 @@ def has_component(name: str) -> bool:
1921

2022

2123
for app_mod_name in settings.INSTALLED_APPS:
24+
if app_mod_name in IDOM_IGNORED_DJANGO_APPS:
25+
logger.debug(f"{idom_mod_name!r} skipped by IDOM_IGNORED_DJANGO_APPS")
26+
continue
27+
2228
idom_mod_name = f"{app_mod_name}.idom"
2329

2430
try:
@@ -36,17 +42,23 @@ def has_component(name: str) -> bool:
3642

3743
for component_constructor in idom_mod.components:
3844
if not callable(component_constructor):
39-
logger.warning(
45+
raise ValueError(
4046
f"{component_constructor} is not a callable component constructor"
4147
)
42-
continue
4348

4449
try:
4550
component_name = getattr(component_constructor, "__name__")
4651
except AttributeError:
47-
logger.warning(
52+
raise ValueError(
4853
f"Component constructor {component_constructor} has not attribute '__name__'"
4954
)
50-
continue
55+
56+
full_component_name = f"{app_mod_name}.{component_name}"
57+
58+
if full_component_name in _LOADED_COMPONENTS:
59+
raise ValueError(
60+
f"Component constructor named {component_name!r} has already been "
61+
f"declared by the app {app_mod_name!r}"
62+
)
5163

5264
_LOADED_COMPONENTS[f"{app_mod_name}.{component_name}"] = component_constructor

src/django_idom/app_settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
for file in (APP_DIR / "templates" / "idom").iterdir()
1111
}
1212

13+
IDOM_IGNORED_DJANGO_APPS = set(getattr(settings, "IDOM_IGNORED_DJANGO_APPS", []))
14+
1315
IDOM_BASE_URL = getattr(settings, "IDOM_BASE_URL", "_idom/")
1416
IDOM_WEBSOCKET_URL = IDOM_BASE_URL + "websocket/"
1517
IDOM_WEB_MODULES_URL = IDOM_BASE_URL + "web_module/"

0 commit comments

Comments
 (0)