infrasynth-backend-kit/infrasynth/tenancy/__init__.py
jcv-dev 5df0be1f5c feat: uniform extensibility across every module
Close the remaining places where an extension point was hardcoded, and
expose a stable public import surface for every app.

- files: register_storage_backend(...) / STORAGE_BACKENDS[name]["CLASS"];
  unknown backends now fail loudly instead of silently using local
- files: PipelineStepRegistry + @pipeline_step; PIPELINE_EXECUTOR setting
- billing: INVOICE_PDF_BUILDER setting
- security: TWO_FACTOR_SERVICE / TWO_FACTOR_RECOVERY_SERVICE settings
- all app packages expose lazy public exports (PEP 562); infrasynth.shared
  re-exports its primitives eagerly
- README documents the per-module extension-point table
- tests/test_extensibility.py pins each hook plus the public surface
2026-09-24 11:08:08 -05:00

67 lines
2 KiB
Python

"""Public surface of ``infrasynth.tenancy``.
The exports are resolved lazily (PEP 562) so importing this package never
triggers Django model imports before the app registry is ready. Import from
here::
from infrasynth.tenancy import TenantService, TenantManager, current_tenant
"""
from __future__ import annotations
from importlib import import_module
from typing import Any
__all__ = [
"AllObjectsManager",
"GlobalOrTenantManager",
"GlobalOrTenantModel",
"PlatformStaff",
"Tenant",
"TenantInvitation",
"TenantManager",
"TenantMembership",
"TenantMiddleware",
"TenantOwnedModel",
"TenantService",
"current_tenant",
"get_current_tenant",
"reset_current_tenant",
"set_current_tenant",
"tenant_context",
]
# public name -> module (relative to the ``infrasynth`` package) that defines it
_EXPORTS: dict[str, str] = {
"AllObjectsManager": "tenancy.managers",
"GlobalOrTenantManager": "tenancy.managers",
"GlobalOrTenantModel": "tenancy.mixins",
"PlatformStaff": "tenancy.models",
"Tenant": "tenancy.models",
"TenantInvitation": "tenancy.models",
"TenantManager": "tenancy.managers",
"TenantMembership": "tenancy.models",
"TenantMiddleware": "tenancy.middleware",
"TenantOwnedModel": "tenancy.mixins",
"TenantService": "tenancy.services",
"current_tenant": "tenancy.context",
"get_current_tenant": "tenancy.context",
"reset_current_tenant": "tenancy.context",
"set_current_tenant": "tenancy.context",
"tenant_context": "tenancy.context",
}
def __getattr__(name: str) -> Any:
module_path = _EXPORTS.get(name)
if module_path is not None:
return getattr(import_module(f"infrasynth.{module_path}"), name)
# Let ``infrasynth.<app>.<submodule>`` resolve as usual.
try:
return import_module(f"{__name__}.{name}")
except ModuleNotFoundError as exc:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from exc
def __dir__() -> list[str]:
return sorted(set(__all__) | set(globals()))