simple-module-cli 0.0.47__py3-none-any.whl → 0.0.49__py3-none-any.whl

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 (186) hide show
  1. simple_module_cli/_add_install.py +51 -13
  2. simple_module_cli/_app_project_manifests.py +1 -0
  3. simple_module_cli/_generation_cache.py +63 -0
  4. simple_module_cli/_lint_tooling.py +1 -24
  5. simple_module_cli/_migration_support.py +67 -0
  6. simple_module_cli/_module_build.py +1 -1
  7. simple_module_cli/_module_host.py +22 -0
  8. simple_module_cli/add_cmd.py +5 -3
  9. simple_module_cli/app_project.py +0 -8
  10. simple_module_cli/cli.py +26 -27
  11. simple_module_cli/dev_cmd.py +174 -0
  12. simple_module_cli/docker_assets.py +3 -6
  13. simple_module_cli/docker_cmd.py +86 -20
  14. simple_module_cli/gen_cmd.py +213 -0
  15. simple_module_cli/migration_recipes/__init__.py +11 -0
  16. simple_module_cli/migrations_cmd.py +120 -24
  17. simple_module_cli/module_cmd.py +4 -4
  18. simple_module_cli/new.py +6 -3
  19. simple_module_cli/openapi_cmd.py +6 -8
  20. simple_module_cli/openapi_types.py +8 -3
  21. simple_module_cli/package_update.py +90 -44
  22. simple_module_cli/package_update_deps.py +15 -5
  23. simple_module_cli/package_update_git.py +84 -0
  24. simple_module_cli/package_update_npm.py +12 -0
  25. simple_module_cli/pins.py +34 -1
  26. simple_module_cli/recipes.py +4 -4
  27. simple_module_cli/scaffolding.py +53 -59
  28. simple_module_cli/skills/simple-module-cli/SKILL.md +114 -84
  29. simple_module_cli/skills/simple-module-conventions/SKILL.md +27 -10
  30. simple_module_cli/skills/simple-module-creating/SKILL.md +81 -25
  31. simple_module_cli/skills/simple-module-doctor/SKILL.md +7 -7
  32. simple_module_cli/skills/simple-module-inertia-pages/SKILL.md +42 -7
  33. simple_module_cli/skills/simple-module-locales/SKILL.md +11 -16
  34. simple_module_cli/skills/simple-module-migrations/SKILL.md +51 -22
  35. simple_module_cli/skills/simple-module-page-perf/SKILL.md +1 -1
  36. simple_module_cli/skills/simple-module-page-perf/scripts/page_audit/audit_server.py +1 -1
  37. simple_module_cli/skills/simple-module-registries/SKILL.md +98 -18
  38. simple_module_cli/skills/simple-module-testing/SKILL.md +9 -3
  39. simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +4 -4
  40. simple_module_cli/templates/docker/compose-tasks-sqlite.yml.tpl +4 -4
  41. simple_module_cli/templates/docker/host-flat.Dockerfile +1 -0
  42. simple_module_cli/templates/docker/host.Dockerfile +1 -0
  43. simple_module_cli/templates/host/.env.example +7 -1
  44. simple_module_cli/templates/host/.gitignore +8 -0
  45. simple_module_cli/templates/host/Makefile +22 -26
  46. simple_module_cli/templates/host/README.md.tpl +1 -1
  47. simple_module_cli/templates/host/_optional/background_tasks/Makefile.snippet +1 -1
  48. simple_module_cli/templates/host/client_app/app.tsx +12 -1
  49. simple_module_cli/templates/host/client_app/module-assets.ts +3 -129
  50. simple_module_cli/templates/host/client_app/package.json.tpl +2 -1
  51. simple_module_cli/templates/host/client_app/vite.config.ts +9 -198
  52. simple_module_cli/templates/host/client_app/vite.dev-url.ts +6 -89
  53. simple_module_cli/templates/host/client_app/vite.i18n.ts +2 -0
  54. simple_module_cli/templates/host/main.py +4 -56
  55. simple_module_cli/templates/host/migrations/env.py +3 -111
  56. simple_module_cli/templates/host/pyproject.toml.tpl +3 -3
  57. simple_module_cli/templates/module/.github/workflows/ci.yml +0 -8
  58. simple_module_cli/templates/module/.gitignore +1 -1
  59. simple_module_cli/templates/module/README.md.tpl +13 -20
  60. simple_module_cli/templates/module/__PACKAGE__/core/constants.py.tpl +9 -11
  61. simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +15 -45
  62. simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl +3 -3
  63. simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl +2 -1
  64. simple_module_cli/templates/module/__PACKAGE__/pages/Edit.tsx.tpl +2 -1
  65. simple_module_cli/templates/module/__PACKAGE__/pages/api.generated.ts.tpl +4 -0
  66. simple_module_cli/templates/module/__PACKAGE__/pages/i18n.generated.ts.tpl +56 -0
  67. simple_module_cli/templates/module/__PACKAGE__/web/endpoints/api.py.tpl +6 -9
  68. simple_module_cli/templates/module/__PACKAGE__/web/endpoints/views.py.tpl +9 -14
  69. simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +4 -3
  70. simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +0 -5
  71. simple_module_cli/templates/module/_optional/settings-hook.py.tpl +13 -0
  72. simple_module_cli/templates/module/pyproject.toml.tpl +3 -11
  73. simple_module_cli/templates/workspace/.env.example +7 -1
  74. simple_module_cli/templates/workspace/.gitignore +7 -0
  75. simple_module_cli/templates/workspace/Makefile +25 -29
  76. simple_module_cli/update_cmd.py +39 -113
  77. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/compose-tasks-postgres.yml.tpl +4 -4
  78. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/compose-tasks-sqlite.yml.tpl +4 -4
  79. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/host-flat.Dockerfile +1 -0
  80. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/host.Dockerfile +1 -0
  81. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/.env.example +7 -1
  82. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/.gitignore +8 -0
  83. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/Makefile +72 -0
  84. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/README.md.tpl +1 -1
  85. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/_optional/background_tasks/Makefile.snippet +1 -1
  86. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/app.tsx +12 -1
  87. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/client_app/module-assets.ts +3 -0
  88. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/package.json.tpl +2 -1
  89. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/client_app/vite.config.ts +29 -0
  90. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/client_app/vite.dev-url.ts +9 -0
  91. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/client_app/vite.i18n.ts +2 -0
  92. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/main.py +10 -0
  93. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/host/migrations/env.py +6 -0
  94. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/pyproject.toml.tpl +3 -3
  95. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/.github/workflows/ci.yml +0 -8
  96. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/.gitignore +1 -1
  97. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/README.md.tpl +13 -20
  98. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/constants.py.tpl +9 -11
  99. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +62 -0
  100. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Browse.tsx.tpl +3 -3
  101. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Create.tsx.tpl +2 -1
  102. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/Edit.tsx.tpl +2 -1
  103. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.generated.ts.tpl +4 -0
  104. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/module/__PACKAGE__/pages/i18n.generated.ts.tpl +56 -0
  105. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/api.py.tpl +6 -9
  106. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/views.py.tpl +9 -14
  107. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/_optional/framework_repo/README.md.tpl +4 -3
  108. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/_optional/framework_repo/pyproject.toml.tpl +0 -5
  109. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/module/_optional/settings-hook.py.tpl +13 -0
  110. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/pyproject.toml.tpl +3 -11
  111. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/workspace/.env.example +7 -1
  112. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/workspace/.gitignore +7 -0
  113. simple_module_cli-0.0.49.data/data/simple_module_cli/templates/workspace/Makefile +86 -0
  114. {simple_module_cli-0.0.47.dist-info → simple_module_cli-0.0.49.dist-info}/METADATA +16 -10
  115. simple_module_cli-0.0.49.dist-info/RECORD +225 -0
  116. simple_module_cli-0.0.49.dist-info/entry_points.txt +7 -0
  117. simple_module_cli/templates/module/__PACKAGE__/pages/api.ts.tpl +0 -10
  118. simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Browse.tsx.tpl +0 -60
  119. simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Create.tsx.tpl +0 -46
  120. simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Edit.tsx.tpl +0 -49
  121. simple_module_cli/templates/module/_optional/standalone/package.json.tpl +0 -29
  122. simple_module_cli/templates/module/_optional/standalone/tsconfig.json.tpl +0 -10
  123. simple_module_cli/templates/module/package.json.tpl +0 -16
  124. simple_module_cli/templates/module/tsconfig.json.tpl +0 -10
  125. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/Makefile +0 -76
  126. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/client_app/module-assets.ts +0 -129
  127. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/client_app/vite.config.ts +0 -218
  128. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/client_app/vite.dev-url.ts +0 -92
  129. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/main.py +0 -62
  130. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/host/migrations/env.py +0 -114
  131. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/__PACKAGE__/module.py.tpl +0 -92
  132. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/__PACKAGE__/pages/api.ts.tpl +0 -10
  133. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Browse.tsx.tpl +0 -60
  134. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Create.tsx.tpl +0 -46
  135. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/_optional/standalone/__PACKAGE__/pages/Edit.tsx.tpl +0 -49
  136. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/_optional/standalone/package.json.tpl +0 -29
  137. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/_optional/standalone/tsconfig.json.tpl +0 -10
  138. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/package.json.tpl +0 -16
  139. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module/tsconfig.json.tpl +0 -10
  140. simple_module_cli-0.0.47.data/data/simple_module_cli/templates/workspace/Makefile +0 -90
  141. simple_module_cli-0.0.47.dist-info/RECORD +0 -229
  142. simple_module_cli-0.0.47.dist-info/entry_points.txt +0 -3
  143. /simple_module_cli/templates/module/{__PACKAGE__ → _optional/settings/__PACKAGE__}/core/services.py.tpl +0 -0
  144. /simple_module_cli/templates/module/{__PACKAGE__ → _optional/settings/__PACKAGE__}/core/settings.py.tpl +0 -0
  145. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/Makefile.snippet +0 -0
  146. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/compose-base-postgres.yml.tpl +0 -0
  147. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/compose-base-sqlite.yml.tpl +0 -0
  148. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/compose-worker.yml.tpl +0 -0
  149. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/dockerignore +0 -0
  150. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/docker/worker.Dockerfile.tpl +0 -0
  151. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/_optional/background_tasks/run_worker.py +0 -0
  152. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/alembic.ini +0 -0
  153. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/main.tsx +0 -0
  154. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/pages/Error.tsx +0 -0
  155. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/pages/Landing.tsx +0 -0
  156. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/pages.ts +0 -0
  157. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/styles.css +0 -0
  158. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/client_app/tsconfig.json +0 -0
  159. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/migrations/script.py.mako +0 -0
  160. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/migrations/versions/.gitkeep +0 -0
  161. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/routes.py +0 -0
  162. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/host/templates/index.html +0 -0
  163. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/.github/workflows/publish.yml.tpl +0 -0
  164. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/__init__.py +0 -0
  165. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/__init__.py.tpl +0 -0
  166. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/contracts/schemas.py.tpl +0 -0
  167. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/core/__init__.py +0 -0
  168. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/locales/en.json.tpl +0 -0
  169. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/models.py.tpl +0 -0
  170. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/py.typed +0 -0
  171. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/__init__.py +0 -0
  172. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/deps.py.tpl +0 -0
  173. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/endpoints/__init__.py +0 -0
  174. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/__PACKAGE__/web/service.py.tpl +0 -0
  175. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/_optional/framework_repo/LICENSE +0 -0
  176. {simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module → simple_module_cli-0.0.49.data/data/simple_module_cli/templates/module/_optional/settings}/__PACKAGE__/core/services.py.tpl +0 -0
  177. {simple_module_cli-0.0.47.data/data/simple_module_cli/templates/module → simple_module_cli-0.0.49.data/data/simple_module_cli/templates/module/_optional/settings}/__PACKAGE__/core/settings.py.tpl +0 -0
  178. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/tests/conftest.py +0 -0
  179. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/tests/core/contracts/test___PACKAGE___schemas.py.tpl +0 -0
  180. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/tests/core/module/test___PACKAGE___module.py.tpl +0 -0
  181. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/module/tests/web/crud/test___PACKAGE___crud.py.tpl +0 -0
  182. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/workspace/README.md.tpl +0 -0
  183. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/workspace/package.json.tpl +0 -0
  184. {simple_module_cli-0.0.47.data → simple_module_cli-0.0.49.data}/data/simple_module_cli/templates/workspace/pyproject.toml.tpl +0 -0
  185. {simple_module_cli-0.0.47.dist-info → simple_module_cli-0.0.49.dist-info}/WHEEL +0 -0
  186. {simple_module_cli-0.0.47.dist-info → simple_module_cli-0.0.49.dist-info}/licenses/LICENSE +0 -0
@@ -9,11 +9,17 @@ from pathlib import Path
9
9
 
10
10
  import typer
11
11
 
12
+ from simple_module_cli.package_update_deps import workspace_member_dirs
13
+ from simple_module_cli.package_update_npm import install_roots, load_manifests
14
+ from simple_module_cli.pyproject_edit import load_pyproject
12
15
  from simple_module_cli.uv_workspace import find_workspace_root, is_workspace_member
13
16
 
14
17
  ExecRunner = Callable[[list[str], Path], int]
15
18
 
16
19
  _DIST_PREFIX = re.compile(r"^simple[-_]module[-_]", re.IGNORECASE)
20
+ _SKIP_IF_MISSING = "--skip-if-missing"
21
+ #: Click's exit code for an unknown option.
22
+ _USAGE_ERROR = 2
17
23
 
18
24
 
19
25
  _ENTRYPOINT_CHECK = (
@@ -42,15 +48,36 @@ def _sync_command(project_dir: Path) -> tuple[list[str], Path]:
42
48
  root, as ``make install`` does.
43
49
  """
44
50
  root = find_workspace_root(project_dir)
45
- if (
46
- root is not None
47
- and root != project_dir.resolve()
48
- and is_workspace_member(project_dir, project_dir)
51
+ if root is not None and (
52
+ root == project_dir.resolve() or is_workspace_member(project_dir, project_dir)
49
53
  ):
50
54
  return ["uv", "sync", "--all-packages"], root
51
55
  return ["uv", "sync"], project_dir
52
56
 
53
57
 
58
+ def sync_project(
59
+ project_dir: Path, exec_runner: ExecRunner, *, upgrade: list[str] | None = None
60
+ ) -> None:
61
+ """Finish manifest changes using the app's installation and generation flow."""
62
+ sync_cmd, root = _sync_command(project_dir)
63
+ for name in upgrade or []:
64
+ sync_cmd.extend(["--upgrade-package", name])
65
+ commands = [(sync_cmd, root)]
66
+ client = next((p for p in (root / "host/client_app", root / "client_app") if p.is_dir()), None)
67
+ if client is not None:
68
+ pyproject = root / "pyproject.toml"
69
+ files = [pyproject, *workspace_member_dirs(pyproject, load_pyproject(pyproject))]
70
+ manifests = load_manifests([file.parent for file in files])
71
+ commands.extend((["npm", "install"], directory) for directory in install_roots(manifests))
72
+ commands.append((["uv", "run", "smpy", "gen"], root))
73
+ for cmd, cwd in commands:
74
+ if exec_runner(cmd, cwd) != 0:
75
+ raise _fail(
76
+ f"`{' '.join(cmd)}` failed — manifests are already updated. "
77
+ f"Fix the error, then run `make install` from {root} to finish installation."
78
+ )
79
+
80
+
54
81
  def _fail(message: str) -> typer.Exit:
55
82
  typer.echo(f"ERROR: {message}", err=True)
56
83
  return typer.Exit(code=1)
@@ -62,16 +89,25 @@ def post_install(
62
89
  models_dists: list[str],
63
90
  exec_runner: ExecRunner,
64
91
  ) -> None:
65
- """uv sync → gen-pages → sync-js-deps → entry-point check → reminders."""
92
+ """Sync dependencies, regenerate frontend files, and check entry points."""
66
93
  sync_cmd, sync_dir = _sync_command(project_dir)
67
- if exec_runner(sync_cmd, sync_dir) != 0:
68
- shown = " ".join(sync_cmd)
69
- raise _fail(
70
- f"`{shown}` failed — pyproject was written; fix and re-run `{shown}` from {sync_dir}."
94
+ has_frontend = (project_dir / "client_app").is_dir()
95
+ commands = [(sync_cmd, sync_dir)]
96
+ if has_frontend:
97
+ commands.extend(
98
+ (["uv", "run", "smpy", "host", *step], project_dir)
99
+ for step in (("gen-pages",), ("sync-js-deps",), ("gen-i18n", _SKIP_IF_MISSING))
71
100
  )
72
- if (project_dir / "client_app").is_dir():
73
- exec_runner(["uv", "run", "smpy", "host", "gen-pages"], project_dir)
74
- exec_runner(["uv", "run", "smpy", "host", "sync-js-deps"], project_dir)
101
+ for cmd, cwd in commands:
102
+ code = exec_runner(cmd, cwd)
103
+ if code == _USAGE_ERROR and _SKIP_IF_MISSING in cmd:
104
+ # A hosting plugin older than the global smpy has no --skip-if-missing.
105
+ code = exec_runner([part for part in cmd if part != _SKIP_IF_MISSING], cwd)
106
+ if code != 0:
107
+ raise _fail(
108
+ f"`{' '.join(cmd)}` failed — dependencies are already recorded in pyproject.toml. "
109
+ "Fix the error, then rerun the original `smpy add` command."
110
+ )
75
111
  for dist in dists:
76
112
  code = exec_runner(["uv", "run", "python", "-c", _ENTRYPOINT_CHECK, dist], project_dir)
77
113
  if code != 0:
@@ -89,4 +125,6 @@ def post_install(
89
125
  # Only `pyproject.toml` changed, which the dev reloader does not watch; and a
90
126
  # reload still logs the new module as not importable in that process (GH #915,
91
127
  # #931), so only a restart serves it.
92
- typer.echo("If `make dev` is running, restart it: modules are discovered at start-up.")
128
+ if has_frontend:
129
+ typer.echo("Run `make install` from the app root to link pages and generate i18n keys.")
130
+ typer.echo("If `make dev` is running, restart it to discover the installed modules.")
@@ -41,6 +41,7 @@ _APP_NPM_DEPS = {
41
41
  # with templates/host/client_app/package.json.tpl.
42
42
  _APP_NPM_DEV_DEPS = {
43
43
  "@simple-module-py/tsconfig": _FRAMEWORK_VERSION,
44
+ "@simple-module-py/vite-plugin": _FRAMEWORK_VERSION,
44
45
  "@tailwindcss/vite": "^4.0.0",
45
46
  "@types/node": "^26.5.0",
46
47
  "@types/react": "^19.0.0",
@@ -0,0 +1,63 @@
1
+ """Content fingerprints for the generation pipeline (never cache a failed stage)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ import os
8
+ from collections.abc import Callable, Iterable
9
+ from pathlib import Path
10
+
11
+
12
+ def file_hashes(paths: Iterable[Path]) -> dict[str, str | None]:
13
+ result = {}
14
+ for path in sorted(set(paths)):
15
+ result[str(path)] = (
16
+ hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
17
+ )
18
+ return result
19
+
20
+
21
+ def source_files(root: Path, suffixes: set[str]) -> list[Path]:
22
+ files = []
23
+ for directory, dirs, names in os.walk(root):
24
+ dirs[:] = [
25
+ d
26
+ for d in dirs
27
+ if not d.startswith(".")
28
+ and d not in {"node_modules", "__pycache__", "tests", "tests-js", "static"}
29
+ ]
30
+ files.extend(Path(directory) / n for n in names if Path(n).suffix in suffixes)
31
+ return files
32
+
33
+
34
+ class GenerationCache:
35
+ def __init__(self, path: Path):
36
+ self.path = path
37
+ try:
38
+ self.state = json.loads(path.read_text(encoding="utf-8"))
39
+ if not isinstance(self.state, dict):
40
+ self.state = {}
41
+ except (OSError, ValueError):
42
+ self.state = {}
43
+
44
+ def run(
45
+ self,
46
+ name: str,
47
+ inputs: Callable[[], object],
48
+ outputs: list[Path],
49
+ generate: Callable[[], object],
50
+ ) -> bool:
51
+ def stamp():
52
+ return {"inputs": inputs(), "outputs": file_hashes(outputs)}
53
+
54
+ if self.state.get(name) == stamp():
55
+ return False
56
+ generate()
57
+ self.state[name] = stamp()
58
+ self.path.parent.mkdir(parents=True, exist_ok=True)
59
+ # Replace atomically: an interrupted generation must leave a readable cache.
60
+ temporary = self.path.with_suffix(f".{os.getpid()}.tmp")
61
+ temporary.write_text(json.dumps(self.state, sort_keys=True), encoding="utf-8")
62
+ temporary.replace(self.path)
63
+ return True
@@ -5,32 +5,9 @@ from __future__ import annotations
5
5
  # ty is pre-1.0 and renames rules between releases, so
6
6
  # new apps get the range this repo is tested on, not the newest ty.
7
7
  # ``test_scaffold_lint_tooling.py`` fails once ``uv.lock`` moves past it.
8
- TY_REQUIREMENT = "ty>=0.0.100,<0.0.101"
8
+ TY_REQUIREMENT = "ty>=0.0.104,<0.0.105"
9
9
 
10
10
  # Apps turn ty's ``invalid-assignment`` off, so this ignore would be reported as
11
11
  # unused there; only a module inside the framework repo, which checks the rule,
12
12
  # gets it.
13
13
  MODEL_CONFIG_TY_IGNORE = " # ty: ignore[invalid-assignment]"
14
-
15
- _MODULE_CONSTANTS = (
16
- "API_PREFIX",
17
- "LOCALE_NAMESPACE",
18
- "MENU_ICON",
19
- "MENU_LABEL",
20
- "MENU_LABEL_KEY",
21
- "MENU_ORDER",
22
- "MENU_URL",
23
- "PERM_GROUP",
24
- "VIEW_PREFIX",
25
- )
26
- _MODULE_PERMISSIONS = ("CREATE", "DELETE", "EDIT", "VIEW")
27
-
28
-
29
- def module_constants_import(package_upper: str) -> str:
30
- """The ``module.py`` constants import list, in the order ruff's isort wants.
31
-
32
- Where ``PERM_GROUP`` falls among ``PERM_<PACKAGE>_*`` depends on the package
33
- name, so a fixed template order is unsorted for half of all names.
34
- """
35
- names = [*_MODULE_CONSTANTS, *(f"PERM_{package_upper}_{p}" for p in _MODULE_PERMISSIONS)]
36
- return "\n".join(f" {name}," for name in sorted(names, key=str.lower))
@@ -0,0 +1,67 @@
1
+ """Migration discovery. Keep core and the standalone CLI's vendored copy identical."""
2
+
3
+ import os
4
+ from importlib.metadata import EntryPoints, entry_points
5
+ from pathlib import Path
6
+
7
+ NO_ALEMBIC_CONFIG = "No Alembic config found. Provide alembic.ini or host/alembic.ini."
8
+ _PROJECT_WALK_LIMIT = 4
9
+ _PROJECT_MARKERS = (".git", ".env.example", ".env")
10
+
11
+
12
+ def resolve_project_root(*, fallback: Path | None = None) -> Path:
13
+ """Find the host project from cwd, including from an inner workspace package."""
14
+ override = os.environ.get("SM_PROJECT_ROOT")
15
+ if override:
16
+ return Path(override)
17
+
18
+ cwd = Path.cwd()
19
+ package_root = None
20
+ try:
21
+ home = Path.home()
22
+ except RuntimeError:
23
+ home = None
24
+ for depth, root in enumerate((cwd, *cwd.parents[:_PROJECT_WALK_LIMIT])):
25
+ if root == home or (root != cwd and root.stat().st_mode & 0o002):
26
+ break
27
+ if any((root / marker).exists() for marker in _PROJECT_MARKERS):
28
+ return root
29
+ if (root / "alembic.ini").is_file():
30
+ # A workspace root may also have a flat config, which takes precedence.
31
+ parent = root.parent
32
+ if (
33
+ root.name == "host"
34
+ and depth < _PROJECT_WALK_LIMIT
35
+ and parent != home
36
+ and not parent.stat().st_mode & 0o002
37
+ and any(
38
+ (parent / marker).exists()
39
+ for marker in (*_PROJECT_MARKERS, "pyproject.toml", "alembic.ini")
40
+ )
41
+ ):
42
+ return parent
43
+ return root
44
+ if (root / "host/alembic.ini").is_file():
45
+ return root
46
+ if package_root is None and (root / "pyproject.toml").is_file():
47
+ package_root = root
48
+ return package_root or fallback or cwd
49
+
50
+
51
+ def resolve_alembic_ini(
52
+ project_root: str | Path | None = None, *, override: str | Path | None = None
53
+ ) -> Path | None:
54
+ """Find the host's ini. An explicit path is cwd-relative and disables fallback."""
55
+ if override is not None:
56
+ candidate = Path(override)
57
+ return candidate if candidate.is_file() else None
58
+ root = Path(project_root) if project_root is not None else resolve_project_root()
59
+ for candidate in (root / "alembic.ini", root / "host" / "alembic.ini"):
60
+ if candidate.is_file():
61
+ return candidate
62
+ return None
63
+
64
+
65
+ def data_upgrade_entry_points() -> EntryPoints:
66
+ """Find registered recipes without importing any recipe code."""
67
+ return entry_points(group="simple_module.data_upgrades")
@@ -44,7 +44,7 @@ def run_build(info: ModuleInfo, *, fresh: bool = False, runner=subprocess.run) -
44
44
  raise typer.Exit(code=1)
45
45
 
46
46
  out_dir = info.root / info.package_name / "static" / "dist"
47
- config_path = info.root / ".smpy" / "module-build.config.mjs"
47
+ config_path = client_app / "module-build.config.mjs"
48
48
  config_path.parent.mkdir(parents=True, exist_ok=True)
49
49
  config_path.write_text(
50
50
  _vite_lib_config(entry, out_dir, global_name=to_pascal_case(info.package_name)),
@@ -12,7 +12,10 @@ import tomllib
12
12
  from dataclasses import dataclass
13
13
  from pathlib import Path
14
14
 
15
+ import tomlkit
15
16
  import typer
17
+ from packaging.requirements import Requirement
18
+ from packaging.utils import canonicalize_name
16
19
 
17
20
  from simple_module_cli.scaffolding import create_host, resolve_framework_version
18
21
 
@@ -71,9 +74,28 @@ def ensure_verify_host(info: ModuleInfo, *, fresh: bool = False) -> Path:
71
74
  framework_version=resolve_framework_version(),
72
75
  )
73
76
  _wire_module_dep(host_dir / "pyproject.toml", info.pypi_name)
77
+ _ensure_host_cli(host_dir / "pyproject.toml")
74
78
  return host_dir
75
79
 
76
80
 
81
+ def _ensure_host_cli(path: Path) -> None:
82
+ """Cached hosts predating smpy gen also need the CLI in their own venv."""
83
+ doc = tomlkit.parse(path.read_text(encoding="utf-8"))
84
+ groups = doc.setdefault("dependency-groups", {})
85
+ current = groups.get("dev", [])
86
+ wanted = [
87
+ dep
88
+ for dep in current
89
+ if not (
90
+ isinstance(dep, str) and canonicalize_name(Requirement(dep).name) == "simple-module-cli"
91
+ )
92
+ ]
93
+ wanted.append(f"simple_module_cli=={resolve_framework_version()}")
94
+ if list(current) != wanted:
95
+ groups["dev"] = wanted
96
+ path.write_text(tomlkit.dumps(doc), encoding="utf-8")
97
+
98
+
77
99
  def _wire_module_dep(pyproject_path: Path, pypi_name: str) -> None:
78
100
  """Add the module as an editable path dependency of the verify host."""
79
101
  text = pyproject_path.read_text(encoding="utf-8")
@@ -5,8 +5,10 @@ is resolved first (ls-remote + shallow clone + entry-point scan); the host
5
5
  pyproject is written only after resolution succeeds. A git spec without
6
6
  ``#subdirectory`` is scanned for module packages — one match is added
7
7
  directly, several go through ``--module``/``--all`` or an interactive
8
- picker. Then: ``uv sync`` → ``smpy host gen-pages`` → ``smpy host
9
- sync-js-deps`` → entry-point verification, unless ``--no-sync``.
8
+ picker. Unless ``--no-sync`` is set, run ``uv sync`` and verify entry points.
9
+ Before verification, a host with a ``client_app`` runs ``smpy host gen-pages``
10
+ and ``smpy host sync-js-deps``, followed by ``smpy host gen-i18n`` if the
11
+ i18n package is installed.
10
12
  """
11
13
 
12
14
  from __future__ import annotations
@@ -168,7 +170,7 @@ def add_module(
168
170
  ] = Path(),
169
171
  no_sync: Annotated[
170
172
  bool,
171
- typer.Option("--no-sync", help="Write pyproject only; skip uv sync / gen-pages."),
173
+ typer.Option("--no-sync", help="Write pyproject only; skip post-install steps."),
172
174
  ] = False,
173
175
  yes: Annotated[bool, typer.Option("--yes", "-y", help="Never prompt (fail instead).")] = False,
174
176
  ) -> None:
@@ -123,14 +123,6 @@ def create_app_project(
123
123
  # Generated secrets go to the gitignored .env, never the committed
124
124
  # .env.example (GH #441) — see write_local_env below.
125
125
  secret_keys = ["SM_SECRET_KEY"]
126
- if "users" in resolved:
127
- # UsersSettings refuses its placeholder token secrets when
128
- # SM_ENVIRONMENT=production — the mode the compose containers run
129
- # in — so generate real ones, same as SM_SECRET_KEY.
130
- secret_keys += [
131
- "SM_USERS_RESET_PASSWORD_TOKEN_SECRET",
132
- "SM_USERS_VERIFICATION_TOKEN_SECRET",
133
- ]
134
126
  db_name = to_snake_case(name)
135
127
  env_path = target / ".env.example"
136
128
  env_text = env_path.read_text(encoding="utf-8") if env_path.exists() else ""
simple_module_cli/cli.py CHANGED
@@ -14,12 +14,12 @@ group are mounted as named subgroups (e.g. ``smpy host gen-pages``).
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- import os
18
17
  from pathlib import Path
19
18
  from typing import Annotated
20
19
 
21
20
  import typer
22
21
 
22
+ from simple_module_cli import _add_install
23
23
  from simple_module_cli._project_cli_check import (
24
24
  app_framework_pin,
25
25
  running_cli,
@@ -27,7 +27,9 @@ from simple_module_cli._project_cli_check import (
27
27
  )
28
28
  from simple_module_cli.add_cmd import add_module, run_add
29
29
  from simple_module_cli.case import to_kebab_case
30
+ from simple_module_cli.dev_cmd import dev_command
30
31
  from simple_module_cli.docker_cmd import docker_app
32
+ from simple_module_cli.gen_cmd import gen_command
31
33
  from simple_module_cli.migrations_cmd import migrations_app
32
34
  from simple_module_cli.module_cmd import module_app
33
35
  from simple_module_cli.new import new_project
@@ -54,6 +56,8 @@ def _check_project_cli(ctx: typer.Context) -> None:
54
56
 
55
57
 
56
58
  app.command("new")(new_project)
59
+ app.command("gen")(gen_command)
60
+ app.command("dev")(dev_command)
57
61
  app.command("add")(add_module)
58
62
  app.command("update")(update_modules)
59
63
  app.command("package-update")(package_update)
@@ -144,35 +148,26 @@ def create_host(
144
148
  typer.echo(" python main.py")
145
149
 
146
150
 
147
- def _app_add_command(target: Path) -> str | None:
148
- """``smpy add …`` wiring a module into its app's host, or None outside an app (GH #442)."""
151
+ def _app_host(target: Path) -> Path | None:
152
+ """Host owning a newly scaffolded workspace member, or None outside an app."""
149
153
  root = find_workspace_root(target.parent)
150
154
  if root is None:
151
155
  return None
152
156
  host = root / "host"
153
157
  if not (host / "pyproject.toml").is_file() or not is_workspace_member(host, target):
154
158
  return None
155
- rel = os.path.relpath(target.resolve(), host.resolve())
156
- if not rel.startswith("."):
157
- rel = f"./{rel}" # parse_add_spec reads a bare "a/b" as a PyPI requirement
158
- # The steps are printed "from the app root", so name the host relative to it.
159
- host_arg = host.resolve().relative_to(root.resolve()).as_posix()
160
- # `uv run`: after `uvx … smpy new`, `smpy` itself is not on PATH (GH #931).
161
- return f"uv run smpy add {rel} --path {host_arg}"
159
+ return host
162
160
 
163
161
 
164
- def _echo_app_next_steps(add_command: str, slug: str) -> None:
162
+ def _echo_app_next_steps(package: str) -> None:
165
163
  """The module lives in an app's workspace: wire it in with the app's own commands.
166
164
 
167
165
  Never ``uv sync`` inside the module: that syncs the module alone and
168
166
  uninstalls the rest of the app from the shared venv (GH #916).
169
167
  """
170
- typer.echo("\nNext steps (from the app root):")
171
- typer.echo(f" {add_command} # adds it as {{ workspace = true }}")
172
- typer.echo(" make install # links its pages (npm) and generates its i18n keys")
173
- typer.echo(f' make migration msg="add {slug}"')
168
+ typer.echo("\nNext step (from the app root): generate and review the migration, then apply it:")
169
+ typer.echo(f' uv run smpy migrations new {package} -m "init"')
174
170
  typer.echo(" make migrate")
175
- typer.echo(" make test")
176
171
  typer.echo("Then restart `make dev`: modules are discovered at start-up, not on reload.")
177
172
 
178
173
 
@@ -192,13 +187,16 @@ def create_module(
192
187
  "existing repo/host (nested workflows never run there).",
193
188
  ),
194
189
  ] = False,
190
+ with_settings: Annotated[
191
+ bool, typer.Option("--with-settings", help="Include DB-backed settings and services.")
192
+ ] = False,
195
193
  ) -> None:
196
194
  """Scaffold a publishable SimpleModule module package."""
197
195
  slug = to_kebab_case(name)
198
196
  package = slug.replace("-", "_")
199
197
  target = dest or Path.cwd() / f"simple_module_{package}"
200
198
  # An in-repo module (the documented modules/* layout) gets no .github/ and
201
- # keeps the workspace JS configs: nested workflows never run and publish.yml
199
+ # uses host-generated JS configs: nested workflows never run and publish.yml
202
200
  # is a PyPI footgun. --standalone forces the standalone layout for a module
203
201
  # that lives in its own repo. See GH #210.
204
202
  standalone_mode = standalone or not is_inside_existing_repo(target)
@@ -211,6 +209,7 @@ def create_module(
211
209
  name=name,
212
210
  framework_version=resolve_framework_version(),
213
211
  standalone=standalone_mode,
212
+ with_settings=with_settings,
214
213
  )
215
214
  except FileExistsError as exc:
216
215
  typer.echo(f"ERROR: {exc}", err=True)
@@ -222,22 +221,22 @@ def create_module(
222
221
  "Skipped .github/ workflows: this module is inside an existing repo, "
223
222
  "where nested workflows never run. Use --standalone to emit them."
224
223
  )
225
- add_command = _app_add_command(target)
226
- if add_command is not None:
227
- _echo_app_next_steps(add_command, slug)
224
+ host = _app_host(target)
225
+ if host is not None:
226
+ run_add(str(target.resolve()), pyproject=host / "pyproject.toml", no_sync=True)
227
+ _add_install.sync_project(host, _add_install._default_exec_runner)
228
+ _echo_app_next_steps(package)
228
229
  else:
229
230
  typer.echo("\nNext steps:")
230
231
  typer.echo(f" cd {target}")
231
232
  typer.echo(" uv sync --extra dev")
232
233
  typer.echo(" uv run pytest")
233
- typer.echo(" npm install")
234
- typer.echo(" npm run typecheck")
235
234
  typer.echo(" uv run smpy module verify")
236
- typer.echo(
237
- "\nThe pages ship sample API types (pages/api.generated.ts). Once the host serves "
238
- "the module, refresh them after any endpoint change:\n"
239
- f" uv run smpy openapi gen-types --module {package}"
240
- )
235
+ typer.echo(
236
+ "\nThe pages ship sample API types (pages/api.generated.ts). Once the host serves "
237
+ "the module, refresh them after any endpoint change:\n"
238
+ f" uv run smpy openapi gen-types --module {package}"
239
+ )
241
240
 
242
241
 
243
242
  discover_and_mount(app)
@@ -0,0 +1,174 @@
1
+ """Run the API and Vite together; every child has an owned process group."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import signal
8
+ import socket
9
+ import subprocess
10
+ import sys
11
+ import time
12
+ from contextlib import suppress
13
+ from pathlib import Path
14
+ from typing import Annotated
15
+
16
+ import typer
17
+
18
+ from simple_module_cli._migration_support import resolve_project_root
19
+ from simple_module_cli.gen_cmd import client_app_dir, run_generation
20
+
21
+
22
+ def check_port(port: int) -> None:
23
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
24
+ sock.bind(("127.0.0.1", port))
25
+
26
+
27
+ def choose_vite_port(requested: int | None, *, api_port: int) -> int:
28
+ if requested == api_port:
29
+ raise ValueError("Vite and API ports must differ")
30
+ if requested is not None:
31
+ try:
32
+ check_port(requested)
33
+ except OSError as exc:
34
+ raise ValueError(f"Vite port {requested} is unavailable: {exc}") from exc
35
+ return requested
36
+ for port in range(5050, 65536):
37
+ if port == api_port:
38
+ continue
39
+ try:
40
+ check_port(port)
41
+ except OSError:
42
+ continue
43
+ return port
44
+ raise ValueError("No free Vite port found")
45
+
46
+
47
+ def stop_children(children: list[subprocess.Popen]) -> None:
48
+ for child in children:
49
+ with suppress(OSError):
50
+ if os.name == "nt":
51
+ child.send_signal(signal.CTRL_BREAK_EVENT)
52
+ else:
53
+ os.killpg(child.pid, signal.SIGTERM)
54
+ deadline = time.monotonic() + 5
55
+ for child in children:
56
+ with suppress(OSError, subprocess.TimeoutExpired):
57
+ child.wait(timeout=max(0, deadline - time.monotonic()))
58
+ for child in children:
59
+ # A reloader or npm may exit before its descendants. Target only the
60
+ # owned group/tree, even when its leader was reaped; never search by port/name.
61
+ try:
62
+ if os.name == "nt":
63
+ try:
64
+ subprocess.run(
65
+ ["taskkill", "/T", "/F", "/PID", str(child.pid)],
66
+ check=True,
67
+ capture_output=True,
68
+ timeout=5,
69
+ )
70
+ except (OSError, subprocess.SubprocessError):
71
+ child.terminate()
72
+ raise
73
+ else:
74
+ with suppress(ProcessLookupError):
75
+ os.killpg(child.pid, signal.SIGKILL)
76
+ except (OSError, subprocess.SubprocessError) as exc:
77
+ typer.echo(f"warning: could not stop process tree {child.pid}: {exc}", err=True)
78
+ try:
79
+ child.wait(timeout=5)
80
+ except (OSError, subprocess.TimeoutExpired) as exc:
81
+ typer.echo(f"warning: could not reap child {child.pid}: {exc}", err=True)
82
+
83
+
84
+ def run_dev(root: Path, *, port: int = 8000, vite_port: int | None = None) -> int:
85
+ from simple_module_core.dotenv import load_dotenv_into_environ
86
+
87
+ root = root.resolve()
88
+ client = client_app_dir(root)
89
+ load_dotenv_into_environ(root / ".env")
90
+ run_generation(root)
91
+ check_port(port)
92
+ selected = choose_vite_port(vite_port, api_port=port)
93
+ env = {
94
+ **os.environ,
95
+ "SM_PROJECT_ROOT": str(root),
96
+ "SM_DEV_SUPERVISED": "1",
97
+ "SM_VITE_DEV_URL": f"http://localhost:{selected}",
98
+ }
99
+ npm = shutil.which("npm")
100
+ if npm is None:
101
+ raise ValueError("npm not found on PATH; install Node.js first")
102
+ workspace = client == root / "host/client_app"
103
+ entry = "host.main:app" if workspace else "main:app"
104
+ api = [
105
+ sys.executable,
106
+ "-m",
107
+ "uvicorn",
108
+ entry,
109
+ "--reload",
110
+ "--port",
111
+ str(port),
112
+ "--reload-dir",
113
+ str(root),
114
+ "--reload-include",
115
+ "*locales/*.json",
116
+ ]
117
+ vite = [npm, "run", "dev", "--", "--host", "127.0.0.1", "--port", str(selected), "--strictPort"]
118
+ typer.echo(f"API: http://localhost:{port} Vite: {env['SM_VITE_DEV_URL']}")
119
+ children: list[subprocess.Popen] = []
120
+ previous = {sig: signal.getsignal(sig) for sig in (signal.SIGINT, signal.SIGTERM)}
121
+
122
+ shutdown = None
123
+
124
+ def stop(signum, _frame):
125
+ nonlocal shutdown
126
+ shutdown = signum
127
+
128
+ process_group = (
129
+ {"creationflags": subprocess.CREATE_NEW_PROCESS_GROUP}
130
+ if os.name == "nt"
131
+ else {"start_new_session": True}
132
+ )
133
+
134
+ try:
135
+ for sig in previous:
136
+ signal.signal(sig, stop)
137
+ for command, cwd in ((api, root), (vite, client)):
138
+ if shutdown is not None:
139
+ return 128 + shutdown
140
+ children.append(subprocess.Popen(command, cwd=cwd, env=env, **process_group))
141
+ while shutdown is None:
142
+ for child in children:
143
+ code = child.poll()
144
+ if shutdown is not None:
145
+ return 128 + shutdown
146
+ if code is not None:
147
+ return code if code >= 0 else 128 - code
148
+ time.sleep(0.1)
149
+ return 128 + shutdown
150
+ finally:
151
+ # A second Ctrl-C must not interrupt cleanup and leave the other group alive.
152
+ for sig in previous:
153
+ signal.signal(sig, signal.SIG_IGN)
154
+ try:
155
+ stop_children(children)
156
+ finally:
157
+ for sig, handler in previous.items():
158
+ signal.signal(sig, handler)
159
+
160
+
161
+ def dev_command(
162
+ port: Annotated[int, typer.Option(min=1, max=65535, help="API port.")] = 8000,
163
+ vite_port: Annotated[
164
+ int | None,
165
+ typer.Option(min=1, max=65535, help="Vite port (default: first free from 5050)."),
166
+ ] = None,
167
+ ) -> None:
168
+ """Generate frontend files, then supervise the API and Vite until either exits."""
169
+ try:
170
+ code = run_dev(resolve_project_root(), port=port, vite_port=vite_port)
171
+ except (ImportError, OSError, ValueError, RuntimeError) as exc:
172
+ typer.echo(f"error: {exc}", err=True)
173
+ raise typer.Exit(1) from None
174
+ raise typer.Exit(code)