simple-module-core 0.0.45__tar.gz → 0.0.47__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 (141) hide show
  1. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/PKG-INFO +1 -1
  2. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/pyproject.toml +1 -1
  3. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/__main__.py +5 -1
  4. simple_module_core-0.0.47/simple_module_core/_entry_point_errors.py +25 -0
  5. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/deprecation.py +1 -1
  6. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_expression_index.py +72 -7
  7. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_runner.py +7 -2
  8. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/discovery.py +7 -3
  9. simple_module_core-0.0.47/tests/test_core_discovery_stale_sys_path.py +64 -0
  10. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_expression_index_diagnostics.py +41 -0
  11. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/.gitignore +0 -0
  12. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/LICENSE +0 -0
  13. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/README.md +0 -0
  14. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/__init__.py +0 -0
  15. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_data_doctor.py +0 -0
  16. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_i18n_flatten.py +0 -0
  17. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_i18n_translator.py +0 -0
  18. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_migration_doctor.py +0 -0
  19. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_permission_grants.py +0 -0
  20. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/_request_hooks.py +0 -0
  21. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/activity_feed.py +0 -0
  22. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/app_state.py +0 -0
  23. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/audit_links.py +0 -0
  24. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/body_limits.py +0 -0
  25. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/correlation.py +0 -0
  26. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/cors.py +0 -0
  27. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/csp.py +0 -0
  28. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/data_compatibility.py +0 -0
  29. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/datetimes.py +0 -0
  30. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/design_packs.py +0 -0
  31. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/__init__.py +0 -0
  32. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_coupling.py +0 -0
  33. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_css.py +0 -0
  34. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_db_extensions.py +0 -0
  35. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_dependencies.py +0 -0
  36. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_durable_names.py +0 -0
  37. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_heavy_task_imports.py +0 -0
  38. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_i18n.py +0 -0
  39. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_inertia_api.py +0 -0
  40. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_js_workspace.py +0 -0
  41. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_migration.py +0 -0
  42. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_module.py +0 -0
  43. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_pages.py +0 -0
  44. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_spa_mount.py +0 -0
  45. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_tenancy.py +0 -0
  46. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/diagnostics/_types.py +0 -0
  47. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/dotenv.py +0 -0
  48. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/durable_events.py +0 -0
  49. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/environments.py +0 -0
  50. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/events.py +0 -0
  51. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/exceptions.py +0 -0
  52. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/feature_flags.py +0 -0
  53. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/health.py +0 -0
  54. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/i18n.py +0 -0
  55. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/i18n_overrides.py +0 -0
  56. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/invalidation.py +0 -0
  57. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/invalidation_refresh.py +0 -0
  58. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/leases.py +0 -0
  59. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/mail.py +0 -0
  60. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/menu.py +0 -0
  61. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/module.py +0 -0
  62. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/module_meta.py +0 -0
  63. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/module_settings.py +0 -0
  64. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/path_rules.py +0 -0
  65. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/permission_denied.py +0 -0
  66. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/permissions.py +0 -0
  67. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/public_routes.py +0 -0
  68. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/py.typed +0 -0
  69. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/rate_limit.py +0 -0
  70. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/redirect_safety.py +0 -0
  71. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/resources.py +0 -0
  72. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/secret_fields.py +0 -0
  73. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/services.py +0 -0
  74. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/settings_base.py +0 -0
  75. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/settings_hydrate.py +0 -0
  76. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/setup_steps.py +0 -0
  77. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/singleflight.py +0 -0
  78. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/spa_mount.py +0 -0
  79. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/stored_settings.py +0 -0
  80. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/tenancy.py +0 -0
  81. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/tenant_events.py +0 -0
  82. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/user_directory.py +0 -0
  83. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/user_events.py +0 -0
  84. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/simple_module_core/versioning.py +0 -0
  85. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_audit_links.py +0 -0
  86. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_auth_provider_selection.py +0 -0
  87. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_app_state.py +0 -0
  88. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_data_compatibility_doctor.py +0 -0
  89. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_datetimes.py +0 -0
  90. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_inline_delivery_context.py +0 -0
  91. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_invalidation_refresh.py +0 -0
  92. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_leases.py +0 -0
  93. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_lifecycle_docs.py +0 -0
  94. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_mail_resolution.py +0 -0
  95. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_module_settings.py +0 -0
  96. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_settings_source_cache.py +0 -0
  97. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_singleflight.py +0 -0
  98. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_core_user_directory.py +0 -0
  99. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_csp_registry.py +0 -0
  100. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_css_diagnostics.py +0 -0
  101. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_css_scanner.py +0 -0
  102. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_db_extensions_diagnostics.py +0 -0
  103. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_deprecation_helper.py +0 -0
  104. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_design_packs.py +0 -0
  105. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_diagnostics.py +0 -0
  106. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_diagnostics_tenancy.py +0 -0
  107. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_discovery.py +0 -0
  108. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_discovery_missing_deps.py +0 -0
  109. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_doctor_cli_overrides.py +0 -0
  110. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_dotenv.py +0 -0
  111. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_durable_events.py +0 -0
  112. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_environments.py +0 -0
  113. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_events.py +0 -0
  114. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_events_inline.py +0 -0
  115. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_feature_flags.py +0 -0
  116. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_feature_flags_decorator.py +0 -0
  117. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_health_registry.py +0 -0
  118. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_heavy_task_imports_diagnostics.py +0 -0
  119. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_i18n.py +0 -0
  120. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_i18n_diagnostics.py +0 -0
  121. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_i18n_overrides.py +0 -0
  122. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_invalidation.py +0 -0
  123. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_invalidation_handlers.py +0 -0
  124. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_menu.py +0 -0
  125. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_module_base.py +0 -0
  126. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_module_diagnostics.py +0 -0
  127. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_path_rule_registries.py +0 -0
  128. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_permission_sources.py +0 -0
  129. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_permissions.py +0 -0
  130. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_permissions_admin_principal.py +0 -0
  131. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_public_routes.py +0 -0
  132. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_public_routes_rate_precedence.py +0 -0
  133. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_redirect_safety.py +0 -0
  134. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_services.py +0 -0
  135. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_settings_base.py +0 -0
  136. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_sm003_page_render.py +0 -0
  137. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_sm009_dynamic_coupling.py +0 -0
  138. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_sm034_durable_names.py +0 -0
  139. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_tenant_exists.py +0 -0
  140. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_tenant_roles.py +0 -0
  141. {simple_module_core-0.0.45 → simple_module_core-0.0.47}/tests/test_versioning.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_core
3
- Version: 0.0.45
3
+ Version: 0.0.47
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_core"
3
- version = "0.0.45"
3
+ version = "0.0.47"
4
4
  description = "Module-system primitives for the simple_module framework — ModuleBase, discovery, diagnostics, events"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -33,6 +33,7 @@ from simple_module_core.diagnostics import (
33
33
  run_diagnostics,
34
34
  )
35
35
  from simple_module_core.diagnostics._dependencies import CODE as MISSING_DEPENDENCY_CODE
36
+ from simple_module_core.diagnostics._expression_index import sqlite_file_index_names
36
37
  from simple_module_core.diagnostics._i18n import unknown_overrides_for
37
38
  from simple_module_core.discovery import (
38
39
  discover_modules,
@@ -98,7 +99,9 @@ def _database_dialect() -> str:
98
99
 
99
100
 
100
101
  def _hosting_locales() -> Path | None:
101
- """The framework's own ``hosting`` catalog (setup wizard), found without importing it.
102
+ """The framework's own ``hosting`` catalog, found without importing it.
103
+
104
+ It holds the setup wizard's and the admin overview's strings.
102
105
 
103
106
  The running app's ``build_i18n_registry`` always adds it, so doctor must
104
107
  too, or every ``hosting.*`` host override reads as unknown (SM027). Core
@@ -192,6 +195,7 @@ def main() -> int:
192
195
  i18n_extra_sources=extra,
193
196
  i18n_unknown_overrides=unknown_overrides,
194
197
  database_dialect=_database_dialect(),
198
+ existing_index_names=sqlite_file_index_names(_database_url()),
195
199
  )
196
200
  diagnostics.extend(override_findings)
197
201
  diagnostics.extend(migration_diagnostics(modules, _database_url(), find_env_file().parent))
@@ -0,0 +1,25 @@
1
+ """Telling an unimportable module entry point apart from a broken module."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ def own_package_missing(ep, exc: BaseException) -> bool:
7
+ """Whether the entry point's own package, not a dependency, is unimportable.
8
+
9
+ A package installed after this process started looks like that: the entry
10
+ point is listed (metadata is read fresh) but ``sys.path`` was fixed at
11
+ start-up, so an editable install's ``.pth`` entry is not on it (GH #915).
12
+ """
13
+ if not isinstance(exc, ModuleNotFoundError) or not exc.name:
14
+ return False
15
+ target = getattr(ep, "module", "") or ""
16
+ return target == exc.name or target.startswith(f"{exc.name}.")
17
+
18
+
19
+ def stale_path_message(ep, exc: BaseException) -> str:
20
+ missing = getattr(exc, "name", None)
21
+ return (
22
+ f"Module entry point '{ep.name}' is installed but {missing!r} cannot be imported "
23
+ "in this process. If it was added after the server started (smpy add, uv sync), "
24
+ "restart the server (`make dev`): a reload keeps the old import path"
25
+ )
@@ -75,7 +75,7 @@ def deprecated(
75
75
  entry.warn(stacklevel=2)
76
76
  original_init(self, *args, **kwargs)
77
77
 
78
- obj.__init__ = init # ty: ignore[invalid-assignment]
78
+ obj.__init__ = init
79
79
  return obj
80
80
 
81
81
  @functools.wraps(cast("Callable[..., Any]", obj))
@@ -4,7 +4,8 @@ SQLAlchemy cannot reflect expression indexes (``lower(email)``) on SQLite, so
4
4
  autogenerate and ``alembic check`` silently skip them there and report a clean
5
5
  diff. That is "unverified", not "clean": on Postgres the same index is either
6
6
  missing from the history or drifted. SM026 says so whenever the configured
7
- database is SQLite and any module model declares such an index.
7
+ database is SQLite and a module model declares such an index the database
8
+ does not have by name.
8
9
 
9
10
  Duck-typed on SQLAlchemy ``Table``/``Index`` objects (core does not depend on
10
11
  SQLAlchemy).
@@ -14,7 +15,11 @@ from __future__ import annotations
14
15
 
15
16
  import importlib
16
17
  import logging
18
+ import re
19
+ import sqlite3
17
20
  from collections.abc import Iterable
21
+ from contextlib import closing
22
+ from pathlib import Path
18
23
  from typing import TYPE_CHECKING, Any
19
24
 
20
25
  from simple_module_core.diagnostics._types import Diagnostic, DiagnosticLevel
@@ -94,13 +99,74 @@ def module_all_tables(mod: ModuleBase) -> list[Any]:
94
99
  return list(seen.values())
95
100
 
96
101
 
102
+ _ROUNDTRIP_TARGET = re.compile(r"^migrations-roundtrip-pg:", re.MULTILINE)
103
+ _DOCS_URL = "https://docs.py.simplemodule.dev/module-authoring"
104
+
105
+
106
+ def expression_index_advice(root: Path | None = None) -> str:
107
+ """How to verify expression indexes, in terms of what this project has.
108
+
109
+ The framework repository has a Postgres round-trip make target; an app made
110
+ by ``smpy new`` does not, so pointing it there sends users nowhere (GH #917).
111
+ ``root`` defaults to the working directory, where make, alembic and doctor run.
112
+ """
113
+ try:
114
+ makefile = (root or Path.cwd()) / "Makefile"
115
+ has_target = _ROUNDTRIP_TARGET.search(makefile.read_text(encoding="utf-8")) is not None
116
+ except OSError:
117
+ has_target = False
118
+ if has_target:
119
+ return "verify them on PostgreSQL with `make migrations-roundtrip-pg`"
120
+ return (
121
+ "verify them on PostgreSQL: point `SM_DATABASE_URL` at a PostgreSQL database, "
122
+ "run `make migrate`, then `alembic check` with the app's alembic.ini "
123
+ "(`uv run alembic -c host/alembic.ini check` in a `smpy new` app), which "
124
+ f"reports a missing index. See {_DOCS_URL}"
125
+ )
126
+
127
+
128
+ def sqlite_file_index_names(database_url: str) -> frozenset[str] | None:
129
+ """Every index name in the SQLite file ``database_url`` names, or ``None``.
130
+
131
+ SQLite records an expression index's name even though SQLAlchemy cannot
132
+ reflect its definition. ``None`` when that cannot be read: another
133
+ database, an in-memory or URI-mode path, or a file that is missing (it is
134
+ opened read-only, so it is never created) or unreadable.
135
+ """
136
+ if not database_url.startswith("sqlite"):
137
+ return None
138
+ _, sep, rest = database_url.partition(":///")
139
+ path = rest.partition("?")[0]
140
+ if not sep or not path or path.startswith((":memory:", "file:")) or not Path(path).is_file():
141
+ return None
142
+ try:
143
+ uri = f"{Path(path).resolve().as_uri()}?mode=ro"
144
+ with closing(sqlite3.connect(uri, uri=True)) as conn:
145
+ rows = conn.execute("SELECT name FROM sqlite_master WHERE type = 'index'").fetchall()
146
+ except sqlite3.Error:
147
+ return None
148
+ return frozenset(row[0] for row in rows)
149
+
150
+
97
151
  def check_expression_indexes_unverifiable(
98
- tables: Iterable[Any], dialect: str | None, module_name: str
152
+ tables: Iterable[Any],
153
+ dialect: str | None,
154
+ module_name: str,
155
+ *,
156
+ existing_index_names: frozenset[str] | None = None,
99
157
  ) -> list[Diagnostic]:
100
- """SM026: INFO on SQLite when the models declare indexes it cannot verify."""
158
+ """SM026: INFO on SQLite when the models declare indexes it cannot verify.
159
+
160
+ ``existing_index_names`` (from :func:`sqlite_file_index_names`) drops the
161
+ indexes the database already has by name, as the revision hook does, so a
162
+ migrated app hears only about the ones it lacks (GH #933). ``None`` reports
163
+ them all.
164
+ """
101
165
  if dialect != "sqlite":
102
166
  return []
103
167
  found = find_expression_indexes(tables)
168
+ if existing_index_names is not None:
169
+ found = [(table, index) for table, index in found if index not in existing_index_names]
104
170
  if not found:
105
171
  return []
106
172
  names = ", ".join(f"{idx} ({tbl})" for tbl, idx in found)
@@ -114,18 +180,17 @@ def check_expression_indexes_unverifiable(
114
180
  f"about them"
115
181
  ),
116
182
  module_name=module_name,
117
- suggestion=(
118
- "Add them to a revision by hand and verify on Postgres: "
119
- "`make migrations-roundtrip-pg`"
120
- ),
183
+ suggestion=f"Add them to a revision by hand and {expression_index_advice()}",
121
184
  )
122
185
  ]
123
186
 
124
187
 
125
188
  __all__ = [
126
189
  "check_expression_indexes_unverifiable",
190
+ "expression_index_advice",
127
191
  "find_expression_indexes",
128
192
  "index_is_expression_based",
129
193
  "module_all_tables",
194
+ "sqlite_file_index_names",
130
195
  "unwrap_ordering",
131
196
  ]
@@ -33,6 +33,7 @@ def run_diagnostics(
33
33
  i18n_extra_sources: list[tuple[str, str, Path]] | None = None,
34
34
  database_dialect: str | None = None,
35
35
  i18n_unknown_overrides: dict[str, list[str]] | None = None,
36
+ existing_index_names: frozenset[str] | None = None,
36
37
  ) -> list[Diagnostic]:
37
38
  """Convenience function to run all diagnostics.
38
39
 
@@ -44,7 +45,8 @@ def run_diagnostics(
44
45
  host/ui locale dirs that aren't owned by a ``ModuleBase``.
45
46
  ``database_dialect`` (``"sqlite"``, ``"postgresql"``...) enables SM026, which
46
47
  flags expression indexes a SQLite database cannot verify, and SM029, which flags
47
- modules declaring ``db_extensions`` on SQLite.
48
+ modules declaring ``db_extensions`` on SQLite. ``existing_index_names``
49
+ (``sqlite_file_index_names``) limits SM026 to indexes the database lacks.
48
50
  ``i18n_unknown_overrides`` (``I18nRegistry.unknown_override_keys``) enables SM027.
49
51
  """
50
52
  diagnostics = ModuleDiagnostics().run(modules)
@@ -53,7 +55,10 @@ def run_diagnostics(
53
55
  for mod in modules:
54
56
  diagnostics.extend(
55
57
  check_expression_indexes_unverifiable(
56
- module_all_tables(mod), database_dialect, mod.meta.name
58
+ module_all_tables(mod),
59
+ database_dialect,
60
+ mod.meta.name,
61
+ existing_index_names=existing_index_names,
57
62
  )
58
63
  )
59
64
  diagnostics.extend(check_db_extensions_need_postgres(mod, database_dialect))
@@ -6,6 +6,7 @@ import logging
6
6
  from collections.abc import Sequence
7
7
  from importlib.metadata import entry_points
8
8
 
9
+ from simple_module_core._entry_point_errors import own_package_missing, stale_path_message
9
10
  from simple_module_core.dotenv import env_str, load_dotenv_into_environ
10
11
  from simple_module_core.exceptions import (
11
12
  CircularDependencyError,
@@ -63,10 +64,10 @@ def discover_modules(
63
64
  # Imported here to avoid a circular import at module load time.
64
65
  from simple_module_core.versioning import check_framework_compatibility
65
66
 
66
- def fail(msg: str, exc: BaseException | None = None) -> None:
67
+ def fail(msg: str, exc: BaseException | None = None, *, with_traceback: bool = True) -> None:
67
68
  if strict:
68
69
  raise InvalidModuleError(msg) from exc
69
- if exc is not None:
70
+ if exc is not None and with_traceback:
70
71
  logger.exception("%s — skipping", msg)
71
72
  else:
72
73
  logger.error("%s — skipping", msg)
@@ -79,7 +80,10 @@ def discover_modules(
79
80
  try:
80
81
  module_cls = ep.load()
81
82
  except Exception as exc:
82
- fail(f"Failed to load module entry point '{ep.name}': {exc}", exc)
83
+ if own_package_missing(ep, exc):
84
+ fail(stale_path_message(ep, exc), exc, with_traceback=False)
85
+ else:
86
+ fail(f"Failed to load module entry point '{ep.name}': {exc}", exc)
83
87
  continue
84
88
 
85
89
  try:
@@ -0,0 +1,64 @@
1
+ """A module installed after the process started reports "restart", not a crash.
2
+
3
+ GH #915: with ``make dev`` running, ``smpy add`` installs a module as an
4
+ editable package. uvicorn's reloader keeps the ``sys.path`` it started with,
5
+ so the new entry point is listed but its package cannot be imported until a
6
+ restart. Discovery used to log ``No module named 'notes.module'`` with a
7
+ traceback, which reads as a broken module.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+
14
+ import pytest
15
+ import simple_module_core.discovery as discovery_mod
16
+ from simple_module_core.discovery import InvalidModuleError, discover_modules
17
+
18
+
19
+ class _EntryPoint:
20
+ def __init__(self, name: str, module: str, exc: Exception) -> None:
21
+ self.name = name
22
+ self.module = module
23
+ self._exc = exc
24
+
25
+ def load(self):
26
+ raise self._exc
27
+
28
+
29
+ def _missing(name: str) -> ModuleNotFoundError:
30
+ return ModuleNotFoundError(f"No module named {name!r}", name=name)
31
+
32
+
33
+ @pytest.mark.parametrize("missing", ["notes", "notes.module"])
34
+ def test_unimportable_own_package_says_restart(monkeypatch, caplog, missing) -> None:
35
+ ep = _EntryPoint("notes", "notes.module", _missing(missing))
36
+ monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
37
+
38
+ with caplog.at_level(logging.ERROR, logger="simple_module_core.discovery"):
39
+ assert discover_modules(strict=False) == []
40
+
41
+ (record,) = [r for r in caplog.records if "notes" in r.getMessage()]
42
+ assert "restart" in record.getMessage()
43
+ assert record.exc_info is None # no traceback: the module is not broken
44
+
45
+
46
+ def test_strict_mode_still_refuses(monkeypatch) -> None:
47
+ ep = _EntryPoint("notes", "notes.module", _missing("notes.module"))
48
+ monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
49
+
50
+ with pytest.raises(InvalidModuleError, match="restart"):
51
+ discover_modules(strict=True)
52
+
53
+
54
+ def test_a_missing_third_party_import_is_still_a_failure(monkeypatch, caplog) -> None:
55
+ """The module's own code importing something absent is a real bug."""
56
+ ep = _EntryPoint("notes", "notes.module", _missing("somelib"))
57
+ monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
58
+
59
+ with caplog.at_level(logging.ERROR, logger="simple_module_core.discovery"):
60
+ discover_modules(strict=False)
61
+
62
+ (record,) = [r for r in caplog.records if "notes" in r.getMessage()]
63
+ assert "restart" not in record.getMessage()
64
+ assert record.exc_info is not None
@@ -120,3 +120,44 @@ def test_text_ordering_and_literal_columns_still_count_as_expressions():
120
120
  ("t", "ix_t_literal"),
121
121
  ("t", "ix_t_text"),
122
122
  ]
123
+
124
+
125
+ def test_sm026_skips_indexes_the_database_already_has():
126
+ """GH #933: a migrated fresh app has the index; SM026 has nothing to say."""
127
+ assert (
128
+ check_expression_indexes_unverifiable(
129
+ _tables(),
130
+ "sqlite",
131
+ "Users",
132
+ existing_index_names=frozenset({"ix_users_user_email_lower"}),
133
+ )
134
+ == []
135
+ )
136
+ missing = check_expression_indexes_unverifiable(
137
+ _tables(), "sqlite", "Users", existing_index_names=frozenset()
138
+ )
139
+ assert [d.code for d in missing] == ["SM026"]
140
+
141
+
142
+ def test_sqlite_file_index_names_reads_the_file(tmp_path):
143
+ from simple_module_core.diagnostics._expression_index import sqlite_file_index_names
144
+
145
+ db = tmp_path / "app.db"
146
+ engine = sa.create_engine(f"sqlite:///{db}")
147
+ with engine.begin() as conn:
148
+ _tables()[0].metadata.create_all(conn)
149
+ engine.dispose()
150
+
151
+ names = sqlite_file_index_names(f"sqlite+aiosqlite:///{db}")
152
+ assert names is not None
153
+ assert "ix_users_user_email_lower" in names
154
+
155
+
156
+ def test_sqlite_file_index_names_is_none_when_it_cannot_tell(tmp_path):
157
+ from simple_module_core.diagnostics._expression_index import sqlite_file_index_names
158
+
159
+ missing = tmp_path / "missing.db"
160
+ assert sqlite_file_index_names(f"sqlite+aiosqlite:///{missing}") is None
161
+ assert not missing.exists() # read-only: never creates the file
162
+ assert sqlite_file_index_names("sqlite+aiosqlite:///:memory:") is None
163
+ assert sqlite_file_index_names("postgresql+asyncpg://u@h/db") is None