simple-module-core 0.0.24__tar.gz → 0.0.26__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/PKG-INFO +2 -1
  2. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/README.md +1 -0
  3. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/pyproject.toml +1 -1
  4. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/__init__.py +3 -0
  5. simple_module_core-0.0.26/simple_module_core/design_packs.py +88 -0
  6. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/module.py +17 -0
  7. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/services.py +2 -0
  8. simple_module_core-0.0.26/tests/test_design_packs.py +105 -0
  9. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_module_base.py +22 -0
  10. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_services.py +3 -0
  11. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/.gitignore +0 -0
  12. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/LICENSE +0 -0
  13. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/__main__.py +0 -0
  14. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/__init__.py +0 -0
  15. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_coupling.py +0 -0
  16. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_i18n.py +0 -0
  17. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_inertia_api.py +0 -0
  18. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_js_workspace.py +0 -0
  19. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_migration.py +0 -0
  20. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_module.py +0 -0
  21. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_pages.py +0 -0
  22. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_runner.py +0 -0
  23. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/diagnostics/_types.py +0 -0
  24. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/discovery.py +0 -0
  25. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/dotenv.py +0 -0
  26. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/environments.py +0 -0
  27. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/events.py +0 -0
  28. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/exceptions.py +0 -0
  29. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/feature_flags.py +0 -0
  30. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/health.py +0 -0
  31. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/i18n.py +0 -0
  32. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/menu.py +0 -0
  33. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/permissions.py +0 -0
  34. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/public_routes.py +0 -0
  35. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/py.typed +0 -0
  36. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/simple_module_core/versioning.py +0 -0
  37. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_diagnostics.py +0 -0
  38. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_discovery.py +0 -0
  39. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_dotenv.py +0 -0
  40. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_environments.py +0 -0
  41. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_events.py +0 -0
  42. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_feature_flags.py +0 -0
  43. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_feature_flags_decorator.py +0 -0
  44. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_health_registry.py +0 -0
  45. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_i18n.py +0 -0
  46. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_i18n_diagnostics.py +0 -0
  47. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_menu.py +0 -0
  48. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_module_diagnostics.py +0 -0
  49. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_permissions.py +0 -0
  50. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_public_routes.py +0 -0
  51. {simple_module_core-0.0.24 → simple_module_core-0.0.26}/tests/test_versioning.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple_module_core
3
- Version: 0.0.24
3
+ Version: 0.0.26
4
4
  Summary: Module-system primitives for the simple_module framework — ModuleBase, discovery, diagnostics, events
5
5
  Project-URL: Homepage, https://github.com/antosubash/simple_module_python
6
6
  Project-URL: Repository, https://github.com/antosubash/simple_module_python
@@ -63,6 +63,7 @@ class OrdersModule(ModuleBase):
63
63
 
64
64
  def register_routes(self, api_router, view_router):
65
65
  from .endpoints import api, views
66
+
66
67
  api_router.include_router(api.router)
67
68
  view_router.include_router(views.router)
68
69
  ```
@@ -32,6 +32,7 @@ class OrdersModule(ModuleBase):
32
32
 
33
33
  def register_routes(self, api_router, view_router):
34
34
  from .endpoints import api, views
35
+
35
36
  api_router.include_router(api.router)
36
37
  view_router.include_router(views.router)
37
38
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_core"
3
- version = "0.0.24"
3
+ version = "0.0.26"
4
4
  description = "Module-system primitives for the simple_module framework — ModuleBase, discovery, diagnostics, events"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,5 +1,6 @@
1
1
  """SimpleModule Core - Module system, menu, permissions, events, and diagnostics."""
2
2
 
3
+ from simple_module_core.design_packs import DesignPack, DesignPackRegistry
3
4
  from simple_module_core.diagnostics import (
4
5
  DiagnosticLevel,
5
6
  MigrationDiagnostics,
@@ -40,6 +41,8 @@ from simple_module_core.versioning import FRAMEWORK_API_VERSION, check_framework
40
41
  __all__ = [
41
42
  "FRAMEWORK_API_VERSION",
42
43
  "CircularDependencyError",
44
+ "DesignPack",
45
+ "DesignPackRegistry",
43
46
  "DiagnosticLevel",
44
47
  "Event",
45
48
  "EventBus",
@@ -0,0 +1,88 @@
1
+ """Design-pack registry — modules contribute a selectable look for the public site.
2
+
3
+ A *design pack* is a stylesheet a module ships that restyles the reader-facing
4
+ site by overriding the base design tokens beneath a ``<value>-root`` class. A
5
+ module declares the packs it provides via
6
+ :meth:`~simple_module_core.module.ModuleBase.register_design_packs`; the host
7
+ collects them into one registry at boot and stores it on
8
+ ``app.state.design_packs``.
9
+
10
+ **The registry supplies the dropdown, not the stylesheet.** A pack's CSS still
11
+ reaches the bundle through the host's ``styles.css`` importing it by package
12
+ specifier. The registry's only job is to stop an administrator selecting a pack
13
+ that no installed module provides — which would otherwise put a class on the
14
+ document with nothing behind it and silently do nothing.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import re
20
+ from dataclasses import dataclass
21
+
22
+ SLUG_RE = re.compile(r"^[a-z0-9][a-z0-9-]*$")
23
+ """A pack slug: lowercase alphanumerics and dashes, not starting with a dash.
24
+
25
+ The site root class is ``f"{value}-root"``, so the slug has to be usable as a
26
+ bare CSS identifier fragment.
27
+ """
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class DesignPack:
32
+ """One selectable look.
33
+
34
+ Args:
35
+ value: Slug identifying the pack. The public site's root element
36
+ carries ``f"{value}-root"``, which is the hook the pack's own
37
+ stylesheet selects on.
38
+ label: Human-readable name, shown in the branding dropdown.
39
+ """
40
+
41
+ value: str
42
+ label: str
43
+
44
+ def __post_init__(self) -> None:
45
+ if not SLUG_RE.match(self.value):
46
+ raise ValueError(
47
+ f"DesignPack value {self.value!r} is not a usable class-name "
48
+ f"fragment; it must match {SLUG_RE.pattern}"
49
+ )
50
+
51
+
52
+ class DesignPackRegistry:
53
+ """Aggregates every module's :class:`DesignPack` declarations.
54
+
55
+ Populated once during boot (``register_design_packs`` hook) and read
56
+ thereafter — by the branding view to build its dropdown, and by the
57
+ branding API to validate a submitted slug.
58
+ """
59
+
60
+ def __init__(self) -> None:
61
+ self._packs: dict[str, DesignPack] = {}
62
+
63
+ def register(self, pack: DesignPack) -> None:
64
+ """Add *pack*, rejecting a slug another module already claimed.
65
+
66
+ Duplicate slugs are an error rather than a silent overwrite: two packs
67
+ sharing one root class would leave whichever stylesheet happened to
68
+ load last in charge, which is not something an administrator could
69
+ diagnose from the UI.
70
+ """
71
+ existing = self._packs.get(pack.value)
72
+ if existing is not None:
73
+ raise ValueError(
74
+ f"Design pack {pack.value!r} is already registered "
75
+ f"(as {existing.label!r}); slugs must be unique across modules"
76
+ )
77
+ self._packs[pack.value] = pack
78
+
79
+ def all(self) -> list[DesignPack]:
80
+ """Every registered pack, in registration order (a copy)."""
81
+ return list(self._packs.values())
82
+
83
+ def has(self, value: str) -> bool:
84
+ """Return ``True`` if some module registered a pack with this slug."""
85
+ return value in self._packs
86
+
87
+
88
+ __all__ = ["DesignPack", "DesignPackRegistry"]
@@ -10,6 +10,7 @@ from typing import TYPE_CHECKING
10
10
  if TYPE_CHECKING:
11
11
  from fastapi import APIRouter, FastAPI
12
12
 
13
+ from simple_module_core.design_packs import DesignPackRegistry
13
14
  from simple_module_core.events import EventBus
14
15
  from simple_module_core.feature_flags import FeatureFlagRegistry
15
16
  from simple_module_core.health import HealthRegistry
@@ -137,6 +138,22 @@ class ModuleBase(ABC):
137
138
  mutations. Called once at boot, in dependency order.
138
139
  """
139
140
 
141
+ def register_design_packs(self, registry: DesignPackRegistry) -> None:
142
+ """Declare design packs this module ships for the public site.
143
+
144
+ A design pack is a stylesheet that restyles the reader-facing site by
145
+ overriding the base tokens beneath a ``<value>-root`` class. Override
146
+ this hook to make the pack selectable in branding::
147
+
148
+ def register_design_packs(self, registry):
149
+ registry.register(DesignPack(value="gca", label="Canopy Atlas"))
150
+
151
+ Registering only advertises the pack — the stylesheet itself still
152
+ reaches the bundle through the host's ``styles.css``. Slugs are unique
153
+ across modules; a collision raises at boot. Called once, in dependency
154
+ order.
155
+ """
156
+
140
157
  def register_middleware(self, app: FastAPI) -> None:
141
158
  """Add middleware to the application.
142
159
 
@@ -20,6 +20,7 @@ if TYPE_CHECKING:
20
20
  from simple_module_db.session import DatabaseState
21
21
  from simple_module_hosting.settings import Settings
22
22
 
23
+ from simple_module_core.design_packs import DesignPackRegistry
23
24
  from simple_module_core.events import EventBus
24
25
  from simple_module_core.feature_flags import FeatureFlagRegistry
25
26
  from simple_module_core.health import HealthRegistry
@@ -42,6 +43,7 @@ class Services:
42
43
  feature_flags: FeatureFlagRegistry
43
44
  health_registry: HealthRegistry
44
45
  public_routes: PublicRouteRegistry
46
+ design_packs: DesignPackRegistry
45
47
  i18n_registry: I18nRegistry
46
48
  inertia_config: InertiaConfig
47
49
  modules: tuple[ModuleBase, ...]
@@ -0,0 +1,105 @@
1
+ """Tests for DesignPackRegistry — modules contribute site-wide design packs.
2
+
3
+ A design pack is a stylesheet a module ships that restyles the public site by
4
+ overriding the base tokens beneath a ``<value>-root`` class. The registry is
5
+ what lets branding offer an administrator only the packs an installed module
6
+ actually provides: selecting one nothing ships would put a class on the
7
+ document with no stylesheet behind it, silently doing nothing.
8
+
9
+ The registry supplies the dropdown, not the stylesheet — a pack's CSS still
10
+ reaches the bundle through the host's ``styles.css``.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import dataclasses
16
+
17
+ import pytest
18
+ from simple_module_core.design_packs import DesignPack, DesignPackRegistry
19
+
20
+
21
+ class TestDesignPack:
22
+ def test_carries_slug_and_label(self):
23
+ pack = DesignPack(value="gca", label="Canopy Atlas")
24
+ assert pack.value == "gca"
25
+ assert pack.label == "Canopy Atlas"
26
+
27
+ def test_is_frozen(self):
28
+ pack = DesignPack(value="gca", label="Canopy Atlas")
29
+ with pytest.raises(dataclasses.FrozenInstanceError):
30
+ pack.value = "other"
31
+
32
+ @pytest.mark.parametrize("value", ["gca", "g", "7", "canopy-atlas", "a1-b2"])
33
+ def test_accepts_a_css_safe_slug(self, value):
34
+ assert DesignPack(value=value, label="X").value == value
35
+
36
+ @pytest.mark.parametrize(
37
+ "value",
38
+ ["", "-gca", "GCA", "canopy_atlas", "canopy atlas", "gca!", "gca.pack"],
39
+ )
40
+ def test_rejects_a_slug_that_would_not_survive_a_class_name(self, value):
41
+ # The site root class is f"{value}-root", so anything that isn't a bare
42
+ # lowercase CSS identifier fragment either fails to select or, worse,
43
+ # silently selects something else.
44
+ with pytest.raises(ValueError, match="value"):
45
+ DesignPack(value=value, label="X")
46
+
47
+
48
+ class TestDesignPackRegistry:
49
+ def test_starts_empty(self):
50
+ assert DesignPackRegistry().all() == []
51
+
52
+ def test_registered_pack_is_returned(self):
53
+ registry = DesignPackRegistry()
54
+ pack = DesignPack(value="gca", label="Canopy Atlas")
55
+ registry.register(pack)
56
+ assert registry.all() == [pack]
57
+
58
+ def test_all_preserves_registration_order(self):
59
+ registry = DesignPackRegistry()
60
+ first = DesignPack(value="gca", label="Canopy Atlas")
61
+ second = DesignPack(value="aurora", label="Aurora")
62
+ registry.register(first)
63
+ registry.register(second)
64
+ assert registry.all() == [first, second]
65
+
66
+ def test_all_returns_a_copy(self):
67
+ registry = DesignPackRegistry()
68
+ registry.register(DesignPack(value="gca", label="Canopy Atlas"))
69
+ registry.all().clear()
70
+ assert len(registry.all()) == 1
71
+
72
+ def test_duplicate_value_is_rejected(self):
73
+ # Two modules claiming one root class would leave whichever stylesheet
74
+ # loaded last in charge — a silent overwrite is the wrong answer.
75
+ registry = DesignPackRegistry()
76
+ registry.register(DesignPack(value="gca", label="Canopy Atlas"))
77
+ with pytest.raises(ValueError, match="gca"):
78
+ registry.register(DesignPack(value="gca", label="Someone Else's Pack"))
79
+
80
+ def test_distinct_values_sharing_a_label_are_allowed(self):
81
+ registry = DesignPackRegistry()
82
+ registry.register(DesignPack(value="gca", label="Atlas"))
83
+ registry.register(DesignPack(value="gca-dark", label="Atlas"))
84
+ assert [p.value for p in registry.all()] == ["gca", "gca-dark"]
85
+
86
+ def test_has_reports_membership(self):
87
+ # Branding's PUT validates the submitted slug against this.
88
+ registry = DesignPackRegistry()
89
+ registry.register(DesignPack(value="gca", label="Canopy Atlas"))
90
+ assert registry.has("gca")
91
+ assert not registry.has("aurora")
92
+
93
+ def test_has_is_false_on_an_empty_registry(self):
94
+ assert not DesignPackRegistry().has("gca")
95
+
96
+
97
+ class TestPublicSurface:
98
+ def test_both_names_are_exported_from_the_package_root(self):
99
+ # Module authors import registries from ``simple_module_core``, the
100
+ # same way they reach MenuRegistry or PublicRouteRegistry.
101
+ import simple_module_core
102
+
103
+ assert simple_module_core.DesignPack is DesignPack
104
+ assert simple_module_core.DesignPackRegistry is DesignPackRegistry
105
+ assert {"DesignPack", "DesignPackRegistry"} <= set(simple_module_core.__all__)
@@ -125,6 +125,28 @@ class TestModuleNewHooks:
125
125
  assert reg.matches("GET", "/api/with-public/datasets/9/tilejson")
126
126
  assert not reg.matches("PATCH", "/api/with-public/datasets/9/tilejson")
127
127
 
128
+ async def test_register_design_packs_default_noop(self):
129
+ from simple_module_core.design_packs import DesignPackRegistry
130
+
131
+ mod = DummyModule()
132
+ reg = DesignPackRegistry()
133
+ mod.register_design_packs(reg)
134
+ assert reg.all() == []
135
+
136
+ async def test_register_design_packs_override(self):
137
+ from simple_module_core.design_packs import DesignPack, DesignPackRegistry
138
+
139
+ class ModWithPack(ModuleBase):
140
+ meta = ModuleMeta(name="WithPack")
141
+
142
+ def register_design_packs(self, registry):
143
+ registry.register(DesignPack(value="with-pack", label="With Pack"))
144
+
145
+ reg = DesignPackRegistry()
146
+ ModWithPack().register_design_packs(reg)
147
+ assert reg.has("with-pack")
148
+ assert [p.label for p in reg.all()] == ["With Pack"]
149
+
128
150
 
129
151
  class TestModuleAssetHooks:
130
152
  async def test_template_dirs_default_empty(self):
@@ -30,6 +30,7 @@ class TestServices:
30
30
  assert s.feature_flags is _SENTINEL_FLAGS
31
31
  assert s.health_registry is _SENTINEL_HEALTH
32
32
  assert s.public_routes is _SENTINEL_PUBLIC_ROUTES
33
+ assert s.design_packs is _SENTINEL_DESIGN_PACKS
33
34
  assert s.i18n_registry is _SENTINEL_I18N
34
35
  assert s.inertia_config is _SENTINEL_INERTIA
35
36
  assert s.modules == ()
@@ -43,6 +44,7 @@ _SENTINEL_PERMS = object()
43
44
  _SENTINEL_FLAGS = object()
44
45
  _SENTINEL_HEALTH = object()
45
46
  _SENTINEL_PUBLIC_ROUTES = object()
47
+ _SENTINEL_DESIGN_PACKS = object()
46
48
  _SENTINEL_I18N = object()
47
49
  _SENTINEL_INERTIA = object()
48
50
 
@@ -58,6 +60,7 @@ def _make_services() -> Services:
58
60
  feature_flags=_SENTINEL_FLAGS, # type: ignore[arg-type]
59
61
  health_registry=_SENTINEL_HEALTH, # type: ignore[arg-type]
60
62
  public_routes=_SENTINEL_PUBLIC_ROUTES, # type: ignore[arg-type]
63
+ design_packs=_SENTINEL_DESIGN_PACKS, # type: ignore[arg-type]
61
64
  i18n_registry=_SENTINEL_I18N, # type: ignore[arg-type]
62
65
  inertia_config=_SENTINEL_INERTIA, # type: ignore[arg-type]
63
66
  modules=(),