Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ All notable changes to this project are documented in this file. The format is b
- A `smpy new` app stays installed under plain uv commands. The workspace root now depends on the host (`<app>-host`, a `{ workspace = true }` source), so `uv sync` at the root installs the app instead of uninstalling it. `smpy add … --path host` inside an app, where the host is a workspace member, syncs the whole workspace from the root (`uv sync --all-packages`, as `make install` does) instead of syncing `host/` alone, which removed the root's dev tools and other modules. `smpy create-module` inside an app prints the app's steps (`smpy add`, `make install`, `make migration`, `make migrate`, `make test`, restart `make dev`) instead of `uv sync --extra dev` in the module, which uninstalled the rest of the app; `--no-install` prints `make install`. An existing app can add `dependencies = ["<app>-host"]` and `[tool.uv.sources] <app>-host = { workspace = true }` to its root `pyproject.toml` (#916).
- A module installed while `make dev` runs is reported as such. The reload keeps the import path the server started with, so its package cannot be imported until a restart; discovery used to log `No module named '<x>.module'` with a traceback, as if the module were broken. It now logs that the entry point is installed but its package cannot be imported in this process, and to restart `make dev` (`strict` discovery still refuses it). A missing third-party import inside a module is still reported with its traceback (#915).
- The SQLite expression-index warning is no longer printed on every migration. The revision hook now re-emits the indexes of new tables first and then names only expression indexes that the database does not have and the revision does not create (SQLite records index names even though it cannot reflect their definitions), so a fresh app's initial schema (which creates `ix_users_user_email_lower`) and an unrelated revision print nothing, while an expression index added to an existing table is still reported. The warning, `SM026` and the `migrate` note point to `make migrations-roundtrip-pg` only where the Makefile has it; elsewhere they say to run `make migrate` and `alembic check` against a PostgreSQL `SM_DATABASE_URL` and link the docs. `smpy new` shows the output of `uv sync`, `npm install` and alembic only when a step fails, stops after a failed initial migration, and prints "Next steps" once, at the end, listing the steps still to run (#917).
- The `Browse`, `Create` and `Edit` pages `smpy create-module` (and `smpy new`'s sample `hello` module) generates now read their text from the module's `locales/en.json` through `t(keys.<module>.…)`, like the bundled modules, so editing the catalog or adding `de.json` takes effect; delete errors use `useApiErrorToast`. The host's `gen-i18n` adds the module to `keys` (`make install` and every dev boot run it); `make build` now runs `gen-pages` and `gen-i18n` first, and the app Dockerfiles run `gen-i18n` before `npm run build`, because a bundle built without the app's keys crashes those pages at runtime. An existing app should add the same `gen-i18n` step to its Dockerfile before switching its pages. A `--standalone` module repo keeps literal English pages, since it has no host to generate keys (#918).

## [0.0.45] — 2026-11-11

Expand Down
4 changes: 3 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ templates `smpy create-module` / `smpy new` use
(`framework/cli/simple_module_cli/templates/module/`). Change a convention there,
once. The `framework_repo` variant is a template overlay
(`_optional/framework_repo/`: workspace-sourced `pyproject.toml` with the
`check_metadata.py` fields, `LICENSE`, `README.md`, i18n-keyed pages).
`check_metadata.py` fields, `LICENSE`, `README.md`). Pages are i18n-keyed
everywhere except `--standalone` module repos (`_optional/standalone/`), which
have no host to generate `keys`.

It generates a CRUD sample (model, DTOs, service, REST + Inertia endpoints,
Browse/Create/Edit pages, `locales/en.json`, tests) whose permissions, page keys
Expand Down
12 changes: 6 additions & 6 deletions docs/guide/first-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def create_order(data: OrderCreate, service: OrderServiceDep) -> OrderOut:
`pages/Browse.tsx` was scaffolded — extend it:

```tsx
import { useT } from "@simple-module-py/i18n";
import { keys, useT } from "@simple-module-py/i18n";
import { PageShell } from "@simple-module-py/ui/components/PageShell";
import {
Table,
Expand All @@ -261,14 +261,14 @@ import type { OrderOut } from "../contracts";
export default function Browse({ orders }: { orders: OrderOut[] }) {
const { t } = useT();
return (
<PageShell title={t("orders.browse.title")}>
<PageShell title={t(keys.orders.browse.title)}>
<Table>
<TableHeader>
<TableRow>
<TableHead>#</TableHead>
<TableHead>{t("orders.fields.customer")}</TableHead>
<TableHead>{t("orders.fields.total")}</TableHead>
<TableHead>{t("orders.fields.status")}</TableHead>
<TableHead>{t(keys.orders.fields.customer)}</TableHead>
<TableHead>{t(keys.orders.fields.total)}</TableHead>
<TableHead>{t(keys.orders.fields.status)}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
Expand All @@ -287,7 +287,7 @@ export default function Browse({ orders }: { orders: OrderOut[] }) {
}
```

Translations (`orders/locales/en.json`):
Translations (`orders/locales/en.json`). `keys.orders.*` is generated from this file by `make gen-i18n`, which `make install`, `make build` and every dev boot run, so a new key needs one of them before `tsc` sees it:

```json
{
Expand Down
3 changes: 2 additions & 1 deletion docs/module-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ survive a real host build (Vite import resolution, Tailwind scanning, the
`gen-pages` CSS emission). `verify` answers that by scaffolding a
throwaway host into `.smpy/verify-host/` (cached, gitignored), installing
your module into it as an editable path dependency, and running the host's
real `gen-pages` + `npm run build`:
real `gen-pages`, `gen-i18n` (so pages that read `keys.<module>` type-check)
and `npm run build`:

```bash
uv run smpy module verify # warm re-runs reuse the cached host
Expand Down
2 changes: 2 additions & 0 deletions framework/cli/simple_module_cli/module_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def run_verify(info: ModuleInfo, *, fresh: bool = False, runner=subprocess.run)
],
host,
),
# Keyed pages read `keys.<module>`, which only the host's gen-i18n adds (GH #918).
("gen-i18n", [uv, "run", "python", "-m", "simple_module_hosting", "gen-i18n"], host),
("frontend build (tsc + vite)", [npm, "run", "build"], client_app),
)
for label, cmd, cwd in steps:
Expand Down
9 changes: 5 additions & 4 deletions framework/cli/simple_module_cli/scaffolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,14 @@ def create_module(
simple_module_python monorepo itself (``make new-module``): it overlays
``_optional/framework_repo/`` (a workspace-sourced ``pyproject.toml`` with
the metadata ``scripts/check_metadata.py`` requires, a LICENSE and README
that pass ``check_readmes.py``, and i18n-keyed pages) and implies no
``.github/``. Wiring into the repo's own pyproject files is
:mod:`simple_module_cli.framework_repo`'s job.
that pass ``check_readmes.py``) and implies no ``.github/``. Wiring into
the repo's own pyproject files is :mod:`simple_module_cli.framework_repo`'s job.

``standalone=True`` additionally overlays ``_optional/standalone/`` (npm
devDependencies + a tsconfig that resolves ``@simple-module-py/ui`` from the
repo's own ``node_modules``) so the module type-checks outside a workspace.
repo's own ``node_modules``) so the module type-checks outside a workspace,
and pages with literal English: the base pages use ``t(keys.<package>.…)``
(GH #918), and a module repo has no host whose ``gen-i18n`` adds its keys.
"""
dest = Path(dest)
existed_before = dest.exists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ RUN --mount=type=cache,target=/root/.cache/uv \
# Flat mode keeps the frontend's own package.json under client_app/.
RUN cd client_app && if [ -f package-lock.json ]; then npm ci; else npm install; fi

# Page manifest + generated module imports, then the production bundle.
# Page manifest + generated module imports, the app's i18n keys (module pages
# read `keys.<module>`, which the published @simple-module-py/i18n lacks), then
# the production bundle.
RUN uv run python -m simple_module_hosting gen-pages --host-dir=client_app
RUN uv run python -m simple_module_hosting gen-i18n
RUN cd client_app && npm run build

# node_modules never ships in the runtime image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --all-packages --no-dev

# Page manifest + generated module imports, then the production bundle.
# Page manifest + generated module imports, the app's i18n keys (module pages
# read `keys.<module>`, which the published @simple-module-py/i18n lacks), then
# the production bundle.
RUN cd host && uv run python -m simple_module_hosting gen-pages --host-dir=client_app
RUN cd host && uv run python -m simple_module_hosting gen-i18n
RUN npm run build

# Re-sync so hatch force-include picks up freshly built module static/dist.
Expand Down
4 changes: 3 additions & 1 deletion framework/cli/simple_module_cli/templates/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ dev-api:
dev-ui:
cd client_app && npm run dev

build:
# Module pages read `keys.<module>` (gen-i18n); a bundle built without them
# crashes those pages at runtime, and tsc does not catch it.
build: gen-pages gen-i18n
cd client_app && npm run build

# Testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ uv run pytest

## Frontend assets (optional)

The pages read their text from `{{PACKAGE_NAME}}/locales/en.json`. Inside an
app they use `t(keys.{{PACKAGE_NAME}}.…)`; the host's `make gen-i18n` (also run
by `make install`, `make build` and each dev boot) adds this module to `keys`.
A standalone module repo has no host to generate them, so its scaffolded pages
use literal English: once the module is installed in an app, switch a string
to `t(keys.{{PACKAGE_NAME}}.browse.title)` and the like.

If this module ships TSX pages:

1. Drop them in `{{PACKAGE_NAME}}/pages/` (the scaffold created the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
import { Head, Link, router } from '@inertiajs/react';
import { keys, useT } from '@simple-module-py/i18n';
import { PageShell } from '@simple-module-py/ui/components/PageShell';
import { useApiErrorToast } from '@simple-module-py/ui/hooks/use-api-error-toast';
import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout';
import { apiResult } from '@simple-module-py/ui/lib/api';
import { useState } from 'react';
import { api } from './api';
import type { components } from './api.generated';

/** The API's DTO, generated from `{{SINGULAR_CLASS}}Out` — the view sends the same shape. */
type Item = components['schemas']['{{SINGULAR_CLASS}}Out'];

export default function Browse({ items }: { items: Item[] }) {
const [error, setError] = useState<string | null>(null);
const { t } = useT();
const showError = useApiErrorToast(keys.{{PACKAGE_NAME}}.browse.delete_failed);
const editLabel = t(keys.{{PACKAGE_NAME}}.browse.edit_link);

async function remove(item: Item) {
setError(null);
const result = await apiResult(
api.DELETE('/api/{{MODULE_SLUG}}/{item_id}', { params: { path: { item_id: item.id } } }),
);
if (!result.ok) {
setError(result.detail ?? 'Could not delete');
return;
}
router.reload({ only: ['items'] });
showError(result);
if (result.ok) router.reload({ only: ['items'] });
}

return (
<PageShell title="{{MODULE_NAME}}" description="Manage your {{PACKAGE_NAME}}">
<Head title="{{MODULE_NAME}}" />
<PageShell
title={t(keys.{{PACKAGE_NAME}}.browse.title)}
description={t(keys.{{PACKAGE_NAME}}.browse.description)}
>
<Head title={t(keys.{{PACKAGE_NAME}}.browse.title)} />
<div className="mb-4 flex justify-end">
<Link
href="/{{MODULE_SLUG}}/create"
className="rounded bg-primary px-3 py-1.5 text-primary-foreground"
>
New {{SINGULAR_CLASS}}
{t(keys.{{PACKAGE_NAME}}.browse.new_button)}
</Link>
</div>
{error && <p className="mb-4 text-sm text-destructive">{error}</p>}
{items.length === 0 ? (
<p className="py-12 text-center text-sm text-muted-foreground">No {{PACKAGE_NAME}} yet.</p>
<div className="py-12 text-center">
<h2 className="text-lg font-medium">{t(keys.{{PACKAGE_NAME}}.browse.empty_title)}</h2>
<p className="mt-1 text-sm text-muted-foreground">
{t(keys.{{PACKAGE_NAME}}.browse.empty_description)}
</p>
</div>
) : (
<ul className="divide-y">
{items.map((item) => (
<li key={item.id} className="flex justify-between gap-4 py-2">
<span>{item.name}</span>
<span className="flex gap-3">
<Link href={`/{{MODULE_SLUG}}/${item.id}/edit`}>Edit</Link>
<Link href={`/{{MODULE_SLUG}}/${item.id}/edit`}>{editLabel}</Link>
<button type="button" onClick={() => remove(item)}>
Delete
{t(keys.{{PACKAGE_NAME}}.browse.delete_button)}
</button>
</span>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Head, useForm } from '@inertiajs/react';
import { keys, useT } from '@simple-module-py/i18n';
import { PageShell } from '@simple-module-py/ui/components/PageShell';
import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout';

export default function Create() {
const { t } = useT();
const form = useForm({ name: '', description: '' });
return (
<PageShell title="New {{SINGULAR_CLASS}}">
<Head title="New {{SINGULAR_CLASS}}" />
<PageShell title={t(keys.{{PACKAGE_NAME}}.create.title)}>
<Head title={t(keys.{{PACKAGE_NAME}}.create.title)} />
<form
className="max-w-xl space-y-3"
onSubmit={(e) => {
Expand All @@ -15,7 +17,7 @@ export default function Create() {
}}
>
<label className="block">
<span className="block text-sm">Name</span>
<span className="block text-sm">{t(keys.{{PACKAGE_NAME}}.form.name_label)}</span>
<input
required
value={form.data.name}
Expand All @@ -24,7 +26,7 @@ export default function Create() {
/>
</label>
<label className="block">
<span className="block text-sm">Description</span>
<span className="block text-sm">{t(keys.{{PACKAGE_NAME}}.form.description_label)}</span>
<textarea
value={form.data.description}
onChange={(e) => form.setData('description', e.target.value)}
Expand All @@ -36,7 +38,7 @@ export default function Create() {
disabled={form.processing}
className="rounded bg-primary px-3 py-1.5 text-primary-foreground"
>
Create
{t(keys.{{PACKAGE_NAME}}.create.submit_button)}
</button>
</form>
</PageShell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Head, useForm } from '@inertiajs/react';
import { keys, useT } from '@simple-module-py/i18n';
import { PageShell } from '@simple-module-py/ui/components/PageShell';
import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout';
import type { components } from './api.generated';

type Item = components['schemas']['{{SINGULAR_CLASS}}Out'];

export default function Edit({ item }: { item: Item }) {
const { t } = useT();
const form = useForm({ name: item.name, description: item.description ?? '' });
return (
<PageShell title="Edit {{SINGULAR_CLASS}}">
<Head title="Edit {{SINGULAR_CLASS}}" />
<PageShell title={t(keys.{{PACKAGE_NAME}}.edit.title)}>
<Head title={t(keys.{{PACKAGE_NAME}}.edit.title)} />
<form
className="max-w-xl space-y-3"
onSubmit={(e) => {
Expand All @@ -18,7 +20,7 @@ export default function Edit({ item }: { item: Item }) {
}}
>
<label className="block">
<span className="block text-sm">Name</span>
<span className="block text-sm">{t(keys.{{PACKAGE_NAME}}.form.name_label)}</span>
<input
required
value={form.data.name}
Expand All @@ -27,7 +29,7 @@ export default function Edit({ item }: { item: Item }) {
/>
</label>
<label className="block">
<span className="block text-sm">Description</span>
<span className="block text-sm">{t(keys.{{PACKAGE_NAME}}.form.description_label)}</span>
<textarea
value={form.data.description}
onChange={(e) => form.setData('description', e.target.value)}
Expand All @@ -39,7 +41,7 @@ export default function Edit({ item }: { item: Item }) {
disabled={form.processing}
className="rounded bg-primary px-3 py-1.5 text-primary-foreground"
>
Save
{t(keys.{{PACKAGE_NAME}}.edit.submit_button)}
</button>
</form>
</PageShell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
import { Head, Link, router } from '@inertiajs/react';
import { keys, useT } from '@simple-module-py/i18n';
import { PageShell } from '@simple-module-py/ui/components/PageShell';
import { useApiErrorToast } from '@simple-module-py/ui/hooks/use-api-error-toast';
import { AuthenticatedLayout } from '@simple-module-py/ui/layouts/AuthenticatedLayout';
import { apiResult } from '@simple-module-py/ui/lib/api';
import { useState } from 'react';
import { api } from './api';
import type { components } from './api.generated';

/** The API's DTO, generated from `{{SINGULAR_CLASS}}Out` — the view sends the same shape. */
type Item = components['schemas']['{{SINGULAR_CLASS}}Out'];

export default function Browse({ items }: { items: Item[] }) {
const { t } = useT();
const showError = useApiErrorToast(keys.{{PACKAGE_NAME}}.browse.delete_failed);
const editLabel = t(keys.{{PACKAGE_NAME}}.browse.edit_link);
const [error, setError] = useState<string | null>(null);

async function remove(item: Item) {
setError(null);
const result = await apiResult(
api.DELETE('/api/{{MODULE_SLUG}}/{item_id}', { params: { path: { item_id: item.id } } }),
);
showError(result);
if (result.ok) router.reload({ only: ['items'] });
if (!result.ok) {
setError(result.detail ?? 'Could not delete');
return;
}
router.reload({ only: ['items'] });
}

return (
<PageShell
title={t(keys.{{PACKAGE_NAME}}.browse.title)}
description={t(keys.{{PACKAGE_NAME}}.browse.description)}
>
<Head title={t(keys.{{PACKAGE_NAME}}.browse.title)} />
<PageShell title="{{MODULE_NAME}}" description="Manage your {{PACKAGE_NAME}}">
<Head title="{{MODULE_NAME}}" />
<div className="mb-4 flex justify-end">
<Link
href="/{{MODULE_SLUG}}/create"
className="rounded bg-primary px-3 py-1.5 text-primary-foreground"
>
{t(keys.{{PACKAGE_NAME}}.browse.new_button)}
New {{SINGULAR_CLASS}}
</Link>
</div>
{error && <p className="mb-4 text-sm text-destructive">{error}</p>}
{items.length === 0 ? (
<div className="py-12 text-center">
<h2 className="text-lg font-medium">{t(keys.{{PACKAGE_NAME}}.browse.empty_title)}</h2>
<p className="mt-1 text-sm text-muted-foreground">
{t(keys.{{PACKAGE_NAME}}.browse.empty_description)}
</p>
</div>
<p className="py-12 text-center text-sm text-muted-foreground">No {{PACKAGE_NAME}} yet.</p>
) : (
<ul className="divide-y">
{items.map((item) => (
<li key={item.id} className="flex justify-between gap-4 py-2">
<span>{item.name}</span>
<span className="flex gap-3">
<Link href={`/{{MODULE_SLUG}}/${item.id}/edit`}>{editLabel}</Link>
<Link href={`/{{MODULE_SLUG}}/${item.id}/edit`}>Edit</Link>
<button type="button" onClick={() => remove(item)}>
{t(keys.{{PACKAGE_NAME}}.browse.delete_button)}
Delete
</button>
</span>
</li>
Expand Down
Loading
Loading