simple-module-core 0.0.45__tar.gz → 0.0.46__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.46}/PKG-INFO +1 -1
  2. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/pyproject.toml +1 -1
  3. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/__main__.py +3 -1
  4. simple_module_core-0.0.46/simple_module_core/_entry_point_errors.py +25 -0
  5. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/deprecation.py +1 -1
  6. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_expression_index.py +30 -4
  7. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/discovery.py +7 -3
  8. simple_module_core-0.0.46/tests/test_core_discovery_stale_sys_path.py +64 -0
  9. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/.gitignore +0 -0
  10. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/LICENSE +0 -0
  11. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/README.md +0 -0
  12. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/__init__.py +0 -0
  13. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_data_doctor.py +0 -0
  14. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_i18n_flatten.py +0 -0
  15. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_i18n_translator.py +0 -0
  16. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_migration_doctor.py +0 -0
  17. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_permission_grants.py +0 -0
  18. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/_request_hooks.py +0 -0
  19. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/activity_feed.py +0 -0
  20. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/app_state.py +0 -0
  21. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/audit_links.py +0 -0
  22. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/body_limits.py +0 -0
  23. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/correlation.py +0 -0
  24. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/cors.py +0 -0
  25. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/csp.py +0 -0
  26. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/data_compatibility.py +0 -0
  27. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/datetimes.py +0 -0
  28. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/design_packs.py +0 -0
  29. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/__init__.py +0 -0
  30. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_coupling.py +0 -0
  31. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_css.py +0 -0
  32. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_db_extensions.py +0 -0
  33. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_dependencies.py +0 -0
  34. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_durable_names.py +0 -0
  35. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_heavy_task_imports.py +0 -0
  36. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_i18n.py +0 -0
  37. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_inertia_api.py +0 -0
  38. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_js_workspace.py +0 -0
  39. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_migration.py +0 -0
  40. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_module.py +0 -0
  41. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_pages.py +0 -0
  42. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_runner.py +0 -0
  43. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_spa_mount.py +0 -0
  44. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_tenancy.py +0 -0
  45. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_types.py +0 -0
  46. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/dotenv.py +0 -0
  47. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/durable_events.py +0 -0
  48. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/environments.py +0 -0
  49. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/events.py +0 -0
  50. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/exceptions.py +0 -0
  51. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/feature_flags.py +0 -0
  52. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/health.py +0 -0
  53. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/i18n.py +0 -0
  54. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/i18n_overrides.py +0 -0
  55. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/invalidation.py +0 -0
  56. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/invalidation_refresh.py +0 -0
  57. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/leases.py +0 -0
  58. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/mail.py +0 -0
  59. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/menu.py +0 -0
  60. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/module.py +0 -0
  61. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/module_meta.py +0 -0
  62. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/module_settings.py +0 -0
  63. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/path_rules.py +0 -0
  64. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/permission_denied.py +0 -0
  65. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/permissions.py +0 -0
  66. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/public_routes.py +0 -0
  67. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/py.typed +0 -0
  68. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/rate_limit.py +0 -0
  69. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/redirect_safety.py +0 -0
  70. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/resources.py +0 -0
  71. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/secret_fields.py +0 -0
  72. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/services.py +0 -0
  73. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/settings_base.py +0 -0
  74. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/settings_hydrate.py +0 -0
  75. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/setup_steps.py +0 -0
  76. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/singleflight.py +0 -0
  77. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/spa_mount.py +0 -0
  78. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/stored_settings.py +0 -0
  79. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/tenancy.py +0 -0
  80. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/tenant_events.py +0 -0
  81. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/user_directory.py +0 -0
  82. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/user_events.py +0 -0
  83. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/simple_module_core/versioning.py +0 -0
  84. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_audit_links.py +0 -0
  85. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_auth_provider_selection.py +0 -0
  86. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_app_state.py +0 -0
  87. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_data_compatibility_doctor.py +0 -0
  88. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_datetimes.py +0 -0
  89. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_inline_delivery_context.py +0 -0
  90. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_invalidation_refresh.py +0 -0
  91. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_leases.py +0 -0
  92. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_lifecycle_docs.py +0 -0
  93. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_mail_resolution.py +0 -0
  94. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_module_settings.py +0 -0
  95. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_settings_source_cache.py +0 -0
  96. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_singleflight.py +0 -0
  97. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_core_user_directory.py +0 -0
  98. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_csp_registry.py +0 -0
  99. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_css_diagnostics.py +0 -0
  100. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_css_scanner.py +0 -0
  101. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_db_extensions_diagnostics.py +0 -0
  102. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_deprecation_helper.py +0 -0
  103. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_design_packs.py +0 -0
  104. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_diagnostics.py +0 -0
  105. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_diagnostics_tenancy.py +0 -0
  106. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_discovery.py +0 -0
  107. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_discovery_missing_deps.py +0 -0
  108. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_doctor_cli_overrides.py +0 -0
  109. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_dotenv.py +0 -0
  110. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_durable_events.py +0 -0
  111. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_environments.py +0 -0
  112. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_events.py +0 -0
  113. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_events_inline.py +0 -0
  114. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_expression_index_diagnostics.py +0 -0
  115. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_feature_flags.py +0 -0
  116. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_feature_flags_decorator.py +0 -0
  117. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_health_registry.py +0 -0
  118. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_heavy_task_imports_diagnostics.py +0 -0
  119. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_i18n.py +0 -0
  120. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_i18n_diagnostics.py +0 -0
  121. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_i18n_overrides.py +0 -0
  122. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_invalidation.py +0 -0
  123. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_invalidation_handlers.py +0 -0
  124. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_menu.py +0 -0
  125. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_module_base.py +0 -0
  126. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_module_diagnostics.py +0 -0
  127. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_path_rule_registries.py +0 -0
  128. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_permission_sources.py +0 -0
  129. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_permissions.py +0 -0
  130. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_permissions_admin_principal.py +0 -0
  131. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_public_routes.py +0 -0
  132. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_public_routes_rate_precedence.py +0 -0
  133. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_redirect_safety.py +0 -0
  134. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_services.py +0 -0
  135. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_settings_base.py +0 -0
  136. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_sm003_page_render.py +0 -0
  137. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_sm009_dynamic_coupling.py +0 -0
  138. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_sm034_durable_names.py +0 -0
  139. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_tenant_exists.py +0 -0
  140. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/tests/test_tenant_roles.py +0 -0
  141. {simple_module_core-0.0.45 → simple_module_core-0.0.46}/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.46
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.46"
4
4
  description = "Module-system primitives for the simple_module framework — ModuleBase, discovery, diagnostics, events"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -98,7 +98,9 @@ def _database_dialect() -> str:
98
98
 
99
99
 
100
100
  def _hosting_locales() -> Path | None:
101
- """The framework's own ``hosting`` catalog (setup wizard), found without importing it.
101
+ """The framework's own ``hosting`` catalog, found without importing it.
102
+
103
+ It holds the setup wizard's and the admin overview's strings.
102
104
 
103
105
  The running app's ``build_i18n_registry`` always adds it, so doctor must
104
106
  too, or every ``hosting.*`` host override reads as unknown (SM027). Core
@@ -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))
@@ -14,7 +14,9 @@ from __future__ import annotations
14
14
 
15
15
  import importlib
16
16
  import logging
17
+ import re
17
18
  from collections.abc import Iterable
19
+ from pathlib import Path
18
20
  from typing import TYPE_CHECKING, Any
19
21
 
20
22
  from simple_module_core.diagnostics._types import Diagnostic, DiagnosticLevel
@@ -94,6 +96,32 @@ def module_all_tables(mod: ModuleBase) -> list[Any]:
94
96
  return list(seen.values())
95
97
 
96
98
 
99
+ _ROUNDTRIP_TARGET = re.compile(r"^migrations-roundtrip-pg:", re.MULTILINE)
100
+ _DOCS_URL = "https://docs.py.simplemodule.dev/module-authoring"
101
+
102
+
103
+ def expression_index_advice(root: Path | None = None) -> str:
104
+ """How to verify expression indexes, in terms of what this project has.
105
+
106
+ The framework repository has a Postgres round-trip make target; an app made
107
+ by ``smpy new`` does not, so pointing it there sends users nowhere (GH #917).
108
+ ``root`` defaults to the working directory, where make, alembic and doctor run.
109
+ """
110
+ try:
111
+ makefile = (root or Path.cwd()) / "Makefile"
112
+ has_target = _ROUNDTRIP_TARGET.search(makefile.read_text(encoding="utf-8")) is not None
113
+ except OSError:
114
+ has_target = False
115
+ if has_target:
116
+ return "verify them on PostgreSQL with `make migrations-roundtrip-pg`"
117
+ return (
118
+ "verify them on PostgreSQL: point `SM_DATABASE_URL` at a PostgreSQL database, "
119
+ "run `make migrate`, then `alembic check` with the app's alembic.ini "
120
+ "(`uv run alembic -c host/alembic.ini check` in a `smpy new` app), which "
121
+ f"reports a missing index. See {_DOCS_URL}"
122
+ )
123
+
124
+
97
125
  def check_expression_indexes_unverifiable(
98
126
  tables: Iterable[Any], dialect: str | None, module_name: str
99
127
  ) -> list[Diagnostic]:
@@ -114,16 +142,14 @@ def check_expression_indexes_unverifiable(
114
142
  f"about them"
115
143
  ),
116
144
  module_name=module_name,
117
- suggestion=(
118
- "Add them to a revision by hand and verify on Postgres: "
119
- "`make migrations-roundtrip-pg`"
120
- ),
145
+ suggestion=f"Add them to a revision by hand and {expression_index_advice()}",
121
146
  )
122
147
  ]
123
148
 
124
149
 
125
150
  __all__ = [
126
151
  "check_expression_indexes_unverifiable",
152
+ "expression_index_advice",
127
153
  "find_expression_indexes",
128
154
  "index_is_expression_based",
129
155
  "module_all_tables",
@@ -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