PyArch-CLI 0.3.0__tar.gz → 0.4.0__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.
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/PKG-INFO +84 -32
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/README.md +83 -31
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/pyproject.toml +1 -1
- pyarch_cli-0.4.0/src/pyarch/__init__.py +1 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/add.py +18 -1
- pyarch_cli-0.4.0/src/pyarch/cli/common.py +85 -0
- pyarch_cli-0.4.0/src/pyarch/cli/generate.py +58 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/config/manifest.py +11 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/config/models.py +1 -0
- pyarch_cli-0.4.0/src/pyarch/generators/common/commands.py +30 -0
- pyarch_cli-0.4.0/src/pyarch/generators/common/compose_edit.py +252 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/common/source_edit.py +322 -322
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/integration/auth.py +63 -1
- pyarch_cli-0.4.0/src/pyarch/generators/integration/redis.py +237 -0
- pyarch_cli-0.4.0/src/pyarch/generators/integration/registry.py +22 -0
- pyarch_cli-0.4.0/src/pyarch/generators/integration/spec.py +15 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/module/layered.py +50 -6
- pyarch_cli-0.4.0/src/pyarch/services/add_integration.py +40 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/services/create_module.py +11 -0
- pyarch_cli-0.4.0/src/pyarch/services/dry_run.py +131 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/alembic_env.py.j2 +1 -1
- pyarch_cli-0.4.0/src/pyarch/templates/layered/config.py.j2 +43 -0
- pyarch_cli-0.4.0/src/pyarch/templates/layered/infra/redis/cache.py.j2 +87 -0
- pyarch_cli-0.4.0/src/pyarch/templates/layered/infra/redis/config.py.j2 +8 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_router.py.j2 +37 -6
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +27 -6
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_service.py.j2 +44 -1
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_test.py.j2 +27 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +40 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/session.py.j2 +1 -1
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/docker-compose.postgres.yml.j2 +2 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/integration/test_generated_project.py +22 -2
- pyarch_cli-0.4.0/tests/unit/test_add_integration.py +189 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_auth_integration.py +172 -172
- pyarch_cli-0.4.0/tests/unit/test_compose_edit.py +340 -0
- pyarch_cli-0.4.0/tests/unit/test_dry_run.py +95 -0
- pyarch_cli-0.4.0/tests/unit/test_generate_cli.py +65 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_manifest.py +30 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_module_generator.py +94 -1
- pyarch_cli-0.4.0/tests/unit/test_redis_integration.py +118 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_source_edit.py +558 -558
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_templates.py +83 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/uv.lock +567 -567
- pyarch_cli-0.3.0/src/pyarch/__init__.py +0 -1
- pyarch_cli-0.3.0/src/pyarch/cli/common.py +0 -26
- pyarch_cli-0.3.0/src/pyarch/cli/generate.py +0 -32
- pyarch_cli-0.3.0/src/pyarch/generators/common/commands.py +0 -6
- pyarch_cli-0.3.0/src/pyarch/services/add_integration.py +0 -68
- pyarch_cli-0.3.0/src/pyarch/templates/layered/config.py.j2 +0 -25
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/.github/workflows/ci.yml +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/.gitignore +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/.python-version +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/LICENSE +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/assets/Dockerfile.vhs +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/assets/pyarch-demo.gif +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/assets/pyarch-demo.tape +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/assets/vhs-uv +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/app.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/db.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/info.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/cli/init.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/config/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/common/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/common/filesystem.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/common/gitignore.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/common/renderer.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/integration/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/module/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/project/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/project/base.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/generators/project/layered.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/main.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/services/__init__.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/services/create_project.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/services/database.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/config.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/dependencies.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/routes.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/service.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/tokens.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/user_model.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/auth/utils.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/env.example.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/errors.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/models_init.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/module/module_schema.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/layered/router.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/Dockerfile.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/README.md.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/ci.yml.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/conftest.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/docker-compose.sqlite.yml.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/dockerignore.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/main.py.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/src/pyarch/templates/project/base/ruff.toml.j2 +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/integration/test_project_generation.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_database_cli.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_database_service.py +0 -0
- {pyarch_cli-0.3.0 → pyarch_cli-0.4.0}/tests/unit/test_filesystem.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: PyArch-CLI
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Stateful CLI generator for Layered FastAPI projects
|
|
5
5
|
Project-URL: Homepage, https://github.com/Allcode-1/PyArch
|
|
6
6
|
Project-URL: Repository, https://github.com/Allcode-1/PyArch
|
|
@@ -32,7 +32,7 @@ Description-Content-Type: text/markdown
|
|
|
32
32
|

|
|
33
33
|

|
|
34
34
|

|
|
35
|
-

|
|
36
36
|
|
|
37
37
|
PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
|
|
38
38
|
the application structure, database, tests and Alembic, then lets you add CRUD
|
|
@@ -63,25 +63,20 @@ ready to change.
|
|
|
63
63
|
- Project-aware generation through `pyarch.toml`
|
|
64
64
|
- Atomic project creation and rollback for failed extensions
|
|
65
65
|
|
|
66
|
-
## v0.
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
and detects Compose service names automatically
|
|
81
|
-
- Zero manual setup: `.env` is created with working local defaults, host ports
|
|
82
|
-
are configurable via `POSTGRES_PORT` / `API_PORT`, the test database is
|
|
83
|
-
created automatically, and the project is pinned to Python 3.13 to match the
|
|
84
|
-
Docker image and CI
|
|
66
|
+
## v0.4.0 Highlights
|
|
67
|
+
|
|
68
|
+
- Redis integration: `pyarch add integration redis` adds the client, settings,
|
|
69
|
+
cache helpers, a Compose service and a `fakeredis` test fixture
|
|
70
|
+
- Opt-in cache-aside for CRUD modules: `pyarch generate module <name> --cache`
|
|
71
|
+
caches single-item reads and invalidates them after update and delete; Redis
|
|
72
|
+
outages fall back to the database instead of failing requests
|
|
73
|
+
- The generated `core/config.py` is split into settings sections
|
|
74
|
+
(`settings.database.url`, `settings.pagination`, integration sections)
|
|
75
|
+
- Integrations are described by a shared registry used by auth and Redis
|
|
76
|
+
- `--dry-run` and `--diff` for `generate module` and `add integration` preview
|
|
77
|
+
file changes and dependency commands without touching the project
|
|
78
|
+
- Already plural module names are no longer pluralized twice
|
|
79
|
+
(`books` → `/books`, not `/bookses`)
|
|
85
80
|
|
|
86
81
|
## Quick Start
|
|
87
82
|
|
|
@@ -143,6 +138,13 @@ removed. `generate module` and `add integration` track every affected file and
|
|
|
143
138
|
restore the previous state if a generation step fails, including the manifest
|
|
144
139
|
and dependency files.
|
|
145
140
|
|
|
141
|
+
`generate module` and `add integration` accept `--dry-run`: the command runs on
|
|
142
|
+
a temporary copy of the project and prints the files it would create or modify
|
|
143
|
+
plus the dependency commands it would run (`uv add ...`). Nothing is written to
|
|
144
|
+
the project and no commands are executed; validation errors are reported exactly
|
|
145
|
+
as in a real run. Add `--diff` to print the full unified diff. `pyarch init`
|
|
146
|
+
has no dry-run mode: it only creates a new directory.
|
|
147
|
+
|
|
146
148
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
147
149
|
|
|
148
150
|
You can now extend the project:
|
|
@@ -151,12 +153,15 @@ You can now extend the project:
|
|
|
151
153
|
pyarch generate module user
|
|
152
154
|
pyarch add integration auth
|
|
153
155
|
pyarch generate module task --protected
|
|
156
|
+
pyarch add integration redis
|
|
157
|
+
pyarch generate module note --cache
|
|
154
158
|
pyarch info
|
|
155
159
|
```
|
|
156
160
|
|
|
157
|
-
Module names
|
|
158
|
-
route names from them:
|
|
159
|
-
|
|
161
|
+
Module names should be singular identifiers. PyArch derives the plural table and
|
|
162
|
+
route names from them: `user` generates `/users` and the `users` table. Names
|
|
163
|
+
that already look plural (`books`, `people`, `news`) are kept as-is instead of
|
|
164
|
+
being pluralized twice.
|
|
160
165
|
|
|
161
166
|
## What Gets Generated
|
|
162
167
|
|
|
@@ -192,6 +197,46 @@ Each generated CRUD module adds:
|
|
|
192
197
|
- CRUD tests;
|
|
193
198
|
- model and router registration in the existing application.
|
|
194
199
|
|
|
200
|
+
Integrations add their infrastructure under `app/infra/` (for example
|
|
201
|
+
`app/infra/redis/`) only when they are enabled; `app/db/` stays the base
|
|
202
|
+
database layer and auth keeps living in `app/auth/`.
|
|
203
|
+
|
|
204
|
+
## Settings
|
|
205
|
+
|
|
206
|
+
`app/core/config.py` groups settings by section instead of keeping one flat
|
|
207
|
+
class: `settings.database.url`, `settings.pagination.default_limit`,
|
|
208
|
+
`settings.auth_jwt.*`, `settings.redis.*`. The database URL is still read from
|
|
209
|
+
`DATABASE_URL`; integration sections use the nested `__` delimiter, e.g.
|
|
210
|
+
`AUTH_JWT__ALGORITHM` or `REDIS__URL`.
|
|
211
|
+
|
|
212
|
+
## Redis Cache
|
|
213
|
+
|
|
214
|
+
`pyarch add integration redis` installs `redis` (and `fakeredis` as a dev
|
|
215
|
+
dependency), generates `app/infra/redis/{config,cache}.py`, registers
|
|
216
|
+
`RedisSettings` in `Settings`, adds `REDIS__URL` to `.env.example`/`.env` and,
|
|
217
|
+
for PostgreSQL projects, a `redis` service to `docker-compose.yml` with
|
|
218
|
+
`REDIS__URL=redis://redis:6379/0` for the API container. Generated tests replace
|
|
219
|
+
the cache with an in-memory `fakeredis` instance through an autouse fixture.
|
|
220
|
+
|
|
221
|
+
`pyarch generate module <name> --cache` (requires the redis integration,
|
|
222
|
+
combinable with `--protected`) generates a cache-aside service:
|
|
223
|
+
|
|
224
|
+
- `GET /<items>/{id}` reads `<prefix>:<module>:<id>` from Redis and falls back
|
|
225
|
+
to the database on a miss, then stores the response schema as JSON with the
|
|
226
|
+
configured TTL (`REDIS__TTL_SECONDS`, 300 by default);
|
|
227
|
+
- `PATCH` and `DELETE` invalidate the key after a successful commit;
|
|
228
|
+
`404` responses are never cached;
|
|
229
|
+
- an entry that no longer matches the response schema (for example after a
|
|
230
|
+
schema change) is dropped and reloaded from the database;
|
|
231
|
+
- Redis errors never fail a request: reads and writes degrade to a cache miss
|
|
232
|
+
and are logged, failed invalidations are logged as errors.
|
|
233
|
+
|
|
234
|
+
Known limits: list endpoints are not cached; a read that loads a row before a
|
|
235
|
+
concurrent update commits can store the old value after the invalidation, so
|
|
236
|
+
it stays cached until the TTL expires; data changed outside the generated
|
|
237
|
+
service is not invalidated; caching can not yet be enabled for an already
|
|
238
|
+
generated module.
|
|
239
|
+
|
|
195
240
|
## Commands
|
|
196
241
|
|
|
197
242
|
| Command | Description |
|
|
@@ -202,6 +247,10 @@ Each generated CRUD module adds:
|
|
|
202
247
|
| `pyarch generate module <singular-name>` | Add a CRUD module to the current project |
|
|
203
248
|
| `pyarch add integration auth` | Add JWT authentication and user management |
|
|
204
249
|
| `pyarch generate module <singular-name> --protected` | Generate protected CRUD routes |
|
|
250
|
+
| `pyarch add integration redis` | Add Redis client, settings and cache helpers |
|
|
251
|
+
| `pyarch generate module <singular-name> --cache` | Cache single-item reads in Redis |
|
|
252
|
+
| `pyarch generate module <singular-name> --dry-run [--diff]` | Preview module changes without writing |
|
|
253
|
+
| `pyarch add integration <name> --dry-run [--diff]` | Preview integration changes without writing |
|
|
205
254
|
| `pyarch info` | Show the current project configuration |
|
|
206
255
|
| `pyarch --help` | Show CLI help |
|
|
207
256
|
|
|
@@ -322,7 +371,16 @@ instead of producing incomplete files.
|
|
|
322
371
|
|
|
323
372
|
## Roadmap
|
|
324
373
|
|
|
325
|
-
### v0.
|
|
374
|
+
### v0.4.0 (current)
|
|
375
|
+
|
|
376
|
+
- Redis integration foundation (`pyarch add integration redis`);
|
|
377
|
+
- opt-in cache-aside generation for CRUD modules (`--cache`);
|
|
378
|
+
- sectioned settings classes in the generated `core/config.py`;
|
|
379
|
+
- integration registry shared by auth and Redis;
|
|
380
|
+
- dry-run mode for `generate module` and `add integration` (`--dry-run`, `--diff`);
|
|
381
|
+
- no double pluralization of plural module names.
|
|
382
|
+
|
|
383
|
+
### v0.3.0
|
|
326
384
|
|
|
327
385
|
- dev-only linting and type-checking dependencies for the CLI itself;
|
|
328
386
|
- auth settings registration that preserves the core config;
|
|
@@ -345,12 +403,6 @@ instead of producing incomplete files.
|
|
|
345
403
|
- PostgreSQL Compose template and SQLite local setup;
|
|
346
404
|
- self-test suite and generated-project integration coverage.
|
|
347
405
|
|
|
348
|
-
### v0.4
|
|
349
|
-
|
|
350
|
-
- Redis integration foundation;
|
|
351
|
-
- opt-in cache-aside generation for CRUD modules;
|
|
352
|
-
- dry-run mode.
|
|
353
|
-
|
|
354
406
|
### Later
|
|
355
407
|
|
|
356
408
|
- scheduler integration;
|
|
@@ -360,6 +412,6 @@ instead of producing incomplete files.
|
|
|
360
412
|
|
|
361
413
|
## Status
|
|
362
414
|
|
|
363
|
-
PyArch v0.
|
|
415
|
+
PyArch v0.4.0 is an early alpha release. The main workflow is usable, but
|
|
364
416
|
commands, templates, generated code and the manifest may still change before a
|
|
365
417
|
stable release.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
|
|
12
12
|
the application structure, database, tests and Alembic, then lets you add CRUD
|
|
@@ -37,25 +37,20 @@ ready to change.
|
|
|
37
37
|
- Project-aware generation through `pyarch.toml`
|
|
38
38
|
- Atomic project creation and rollback for failed extensions
|
|
39
39
|
|
|
40
|
-
## v0.
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
and detects Compose service names automatically
|
|
55
|
-
- Zero manual setup: `.env` is created with working local defaults, host ports
|
|
56
|
-
are configurable via `POSTGRES_PORT` / `API_PORT`, the test database is
|
|
57
|
-
created automatically, and the project is pinned to Python 3.13 to match the
|
|
58
|
-
Docker image and CI
|
|
40
|
+
## v0.4.0 Highlights
|
|
41
|
+
|
|
42
|
+
- Redis integration: `pyarch add integration redis` adds the client, settings,
|
|
43
|
+
cache helpers, a Compose service and a `fakeredis` test fixture
|
|
44
|
+
- Opt-in cache-aside for CRUD modules: `pyarch generate module <name> --cache`
|
|
45
|
+
caches single-item reads and invalidates them after update and delete; Redis
|
|
46
|
+
outages fall back to the database instead of failing requests
|
|
47
|
+
- The generated `core/config.py` is split into settings sections
|
|
48
|
+
(`settings.database.url`, `settings.pagination`, integration sections)
|
|
49
|
+
- Integrations are described by a shared registry used by auth and Redis
|
|
50
|
+
- `--dry-run` and `--diff` for `generate module` and `add integration` preview
|
|
51
|
+
file changes and dependency commands without touching the project
|
|
52
|
+
- Already plural module names are no longer pluralized twice
|
|
53
|
+
(`books` → `/books`, not `/bookses`)
|
|
59
54
|
|
|
60
55
|
## Quick Start
|
|
61
56
|
|
|
@@ -117,6 +112,13 @@ removed. `generate module` and `add integration` track every affected file and
|
|
|
117
112
|
restore the previous state if a generation step fails, including the manifest
|
|
118
113
|
and dependency files.
|
|
119
114
|
|
|
115
|
+
`generate module` and `add integration` accept `--dry-run`: the command runs on
|
|
116
|
+
a temporary copy of the project and prints the files it would create or modify
|
|
117
|
+
plus the dependency commands it would run (`uv add ...`). Nothing is written to
|
|
118
|
+
the project and no commands are executed; validation errors are reported exactly
|
|
119
|
+
as in a real run. Add `--diff` to print the full unified diff. `pyarch init`
|
|
120
|
+
has no dry-run mode: it only creates a new directory.
|
|
121
|
+
|
|
120
122
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
121
123
|
|
|
122
124
|
You can now extend the project:
|
|
@@ -125,12 +127,15 @@ You can now extend the project:
|
|
|
125
127
|
pyarch generate module user
|
|
126
128
|
pyarch add integration auth
|
|
127
129
|
pyarch generate module task --protected
|
|
130
|
+
pyarch add integration redis
|
|
131
|
+
pyarch generate module note --cache
|
|
128
132
|
pyarch info
|
|
129
133
|
```
|
|
130
134
|
|
|
131
|
-
Module names
|
|
132
|
-
route names from them:
|
|
133
|
-
|
|
135
|
+
Module names should be singular identifiers. PyArch derives the plural table and
|
|
136
|
+
route names from them: `user` generates `/users` and the `users` table. Names
|
|
137
|
+
that already look plural (`books`, `people`, `news`) are kept as-is instead of
|
|
138
|
+
being pluralized twice.
|
|
134
139
|
|
|
135
140
|
## What Gets Generated
|
|
136
141
|
|
|
@@ -166,6 +171,46 @@ Each generated CRUD module adds:
|
|
|
166
171
|
- CRUD tests;
|
|
167
172
|
- model and router registration in the existing application.
|
|
168
173
|
|
|
174
|
+
Integrations add their infrastructure under `app/infra/` (for example
|
|
175
|
+
`app/infra/redis/`) only when they are enabled; `app/db/` stays the base
|
|
176
|
+
database layer and auth keeps living in `app/auth/`.
|
|
177
|
+
|
|
178
|
+
## Settings
|
|
179
|
+
|
|
180
|
+
`app/core/config.py` groups settings by section instead of keeping one flat
|
|
181
|
+
class: `settings.database.url`, `settings.pagination.default_limit`,
|
|
182
|
+
`settings.auth_jwt.*`, `settings.redis.*`. The database URL is still read from
|
|
183
|
+
`DATABASE_URL`; integration sections use the nested `__` delimiter, e.g.
|
|
184
|
+
`AUTH_JWT__ALGORITHM` or `REDIS__URL`.
|
|
185
|
+
|
|
186
|
+
## Redis Cache
|
|
187
|
+
|
|
188
|
+
`pyarch add integration redis` installs `redis` (and `fakeredis` as a dev
|
|
189
|
+
dependency), generates `app/infra/redis/{config,cache}.py`, registers
|
|
190
|
+
`RedisSettings` in `Settings`, adds `REDIS__URL` to `.env.example`/`.env` and,
|
|
191
|
+
for PostgreSQL projects, a `redis` service to `docker-compose.yml` with
|
|
192
|
+
`REDIS__URL=redis://redis:6379/0` for the API container. Generated tests replace
|
|
193
|
+
the cache with an in-memory `fakeredis` instance through an autouse fixture.
|
|
194
|
+
|
|
195
|
+
`pyarch generate module <name> --cache` (requires the redis integration,
|
|
196
|
+
combinable with `--protected`) generates a cache-aside service:
|
|
197
|
+
|
|
198
|
+
- `GET /<items>/{id}` reads `<prefix>:<module>:<id>` from Redis and falls back
|
|
199
|
+
to the database on a miss, then stores the response schema as JSON with the
|
|
200
|
+
configured TTL (`REDIS__TTL_SECONDS`, 300 by default);
|
|
201
|
+
- `PATCH` and `DELETE` invalidate the key after a successful commit;
|
|
202
|
+
`404` responses are never cached;
|
|
203
|
+
- an entry that no longer matches the response schema (for example after a
|
|
204
|
+
schema change) is dropped and reloaded from the database;
|
|
205
|
+
- Redis errors never fail a request: reads and writes degrade to a cache miss
|
|
206
|
+
and are logged, failed invalidations are logged as errors.
|
|
207
|
+
|
|
208
|
+
Known limits: list endpoints are not cached; a read that loads a row before a
|
|
209
|
+
concurrent update commits can store the old value after the invalidation, so
|
|
210
|
+
it stays cached until the TTL expires; data changed outside the generated
|
|
211
|
+
service is not invalidated; caching can not yet be enabled for an already
|
|
212
|
+
generated module.
|
|
213
|
+
|
|
169
214
|
## Commands
|
|
170
215
|
|
|
171
216
|
| Command | Description |
|
|
@@ -176,6 +221,10 @@ Each generated CRUD module adds:
|
|
|
176
221
|
| `pyarch generate module <singular-name>` | Add a CRUD module to the current project |
|
|
177
222
|
| `pyarch add integration auth` | Add JWT authentication and user management |
|
|
178
223
|
| `pyarch generate module <singular-name> --protected` | Generate protected CRUD routes |
|
|
224
|
+
| `pyarch add integration redis` | Add Redis client, settings and cache helpers |
|
|
225
|
+
| `pyarch generate module <singular-name> --cache` | Cache single-item reads in Redis |
|
|
226
|
+
| `pyarch generate module <singular-name> --dry-run [--diff]` | Preview module changes without writing |
|
|
227
|
+
| `pyarch add integration <name> --dry-run [--diff]` | Preview integration changes without writing |
|
|
179
228
|
| `pyarch info` | Show the current project configuration |
|
|
180
229
|
| `pyarch --help` | Show CLI help |
|
|
181
230
|
|
|
@@ -296,7 +345,16 @@ instead of producing incomplete files.
|
|
|
296
345
|
|
|
297
346
|
## Roadmap
|
|
298
347
|
|
|
299
|
-
### v0.
|
|
348
|
+
### v0.4.0 (current)
|
|
349
|
+
|
|
350
|
+
- Redis integration foundation (`pyarch add integration redis`);
|
|
351
|
+
- opt-in cache-aside generation for CRUD modules (`--cache`);
|
|
352
|
+
- sectioned settings classes in the generated `core/config.py`;
|
|
353
|
+
- integration registry shared by auth and Redis;
|
|
354
|
+
- dry-run mode for `generate module` and `add integration` (`--dry-run`, `--diff`);
|
|
355
|
+
- no double pluralization of plural module names.
|
|
356
|
+
|
|
357
|
+
### v0.3.0
|
|
300
358
|
|
|
301
359
|
- dev-only linting and type-checking dependencies for the CLI itself;
|
|
302
360
|
- auth settings registration that preserves the core config;
|
|
@@ -319,12 +377,6 @@ instead of producing incomplete files.
|
|
|
319
377
|
- PostgreSQL Compose template and SQLite local setup;
|
|
320
378
|
- self-test suite and generated-project integration coverage.
|
|
321
379
|
|
|
322
|
-
### v0.4
|
|
323
|
-
|
|
324
|
-
- Redis integration foundation;
|
|
325
|
-
- opt-in cache-aside generation for CRUD modules;
|
|
326
|
-
- dry-run mode.
|
|
327
|
-
|
|
328
380
|
### Later
|
|
329
381
|
|
|
330
382
|
- scheduler integration;
|
|
@@ -334,6 +386,6 @@ instead of producing incomplete files.
|
|
|
334
386
|
|
|
335
387
|
## Status
|
|
336
388
|
|
|
337
|
-
PyArch v0.
|
|
389
|
+
PyArch v0.4.0 is an early alpha release. The main workflow is usable, but
|
|
338
390
|
commands, templates, generated code and the manifest may still change before a
|
|
339
391
|
stable release.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.0"
|
|
@@ -2,7 +2,14 @@ from typing import Annotated
|
|
|
2
2
|
|
|
3
3
|
import typer
|
|
4
4
|
|
|
5
|
-
from pyarch.cli.common import
|
|
5
|
+
from pyarch.cli.common import (
|
|
6
|
+
DiffOption,
|
|
7
|
+
DryRunOption,
|
|
8
|
+
console,
|
|
9
|
+
ensure_diff_with_dry_run,
|
|
10
|
+
execute_or_exit,
|
|
11
|
+
run_dry_or_exit,
|
|
12
|
+
)
|
|
6
13
|
from pyarch.services.add_integration import add_integration
|
|
7
14
|
|
|
8
15
|
app = typer.Typer(no_args_is_help=True)
|
|
@@ -14,9 +21,19 @@ def add_integration_command(
|
|
|
14
21
|
str,
|
|
15
22
|
typer.Argument(help="Integration name."),
|
|
16
23
|
],
|
|
24
|
+
dry_run: DryRunOption = False,
|
|
25
|
+
show_diff: DiffOption = False,
|
|
17
26
|
) -> None:
|
|
18
27
|
"""Add a supported integration to the current project."""
|
|
19
28
|
|
|
29
|
+
ensure_diff_with_dry_run(show_diff, dry_run)
|
|
30
|
+
if dry_run:
|
|
31
|
+
run_dry_or_exit(
|
|
32
|
+
lambda root: add_integration(integration_name, start=root),
|
|
33
|
+
show_diff=show_diff,
|
|
34
|
+
)
|
|
35
|
+
return
|
|
36
|
+
|
|
20
37
|
project_root, created_files = execute_or_exit(
|
|
21
38
|
lambda: add_integration(integration_name)
|
|
22
39
|
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
import subprocess
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Annotated, Never
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
|
|
10
|
+
from pyarch.services.dry_run import ChangeKind, DryRunReport, dry_run
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
DryRunOption = Annotated[
|
|
15
|
+
bool,
|
|
16
|
+
typer.Option(
|
|
17
|
+
"--dry-run",
|
|
18
|
+
help="Show the files that would change without writing anything.",
|
|
19
|
+
),
|
|
20
|
+
]
|
|
21
|
+
DiffOption = Annotated[
|
|
22
|
+
bool,
|
|
23
|
+
typer.Option("--diff", help="With --dry-run, also print the full diff."),
|
|
24
|
+
]
|
|
25
|
+
CHANGE_STYLES = {
|
|
26
|
+
ChangeKind.CREATE: "green",
|
|
27
|
+
ChangeKind.MODIFY: "yellow",
|
|
28
|
+
ChangeKind.DELETE: "red",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_dry_or_exit(action: Callable[[Path], object], *, show_diff: bool) -> None:
|
|
33
|
+
report = execute_or_exit(lambda: dry_run(action))
|
|
34
|
+
print_dry_run_report(report, show_diff=show_diff)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def print_dry_run_report(report: DryRunReport, *, show_diff: bool) -> None:
|
|
38
|
+
console.print(
|
|
39
|
+
f"[bold]Dry run:[/bold] no changes were made to {report.project_root}"
|
|
40
|
+
)
|
|
41
|
+
for change in report.changes:
|
|
42
|
+
style = CHANGE_STYLES[change.kind]
|
|
43
|
+
console.print(
|
|
44
|
+
f" [{style}]{change.kind.value:<6}[/{style}] {change.path.as_posix()}",
|
|
45
|
+
highlight=False,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if report.commands:
|
|
49
|
+
console.print("[bold]Would run:[/bold]")
|
|
50
|
+
for command in report.commands:
|
|
51
|
+
console.print(f" {shlex.join(command)}", markup=False, highlight=False)
|
|
52
|
+
|
|
53
|
+
if not show_diff:
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
for change in report.changes:
|
|
57
|
+
diff = change.unified_diff()
|
|
58
|
+
console.print()
|
|
59
|
+
if diff is None:
|
|
60
|
+
console.print(f"Binary file {change.path.as_posix()} differs", markup=False)
|
|
61
|
+
else:
|
|
62
|
+
console.print(diff, end="", markup=False, highlight=False)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def ensure_diff_with_dry_run(show_diff: bool, dry_run_enabled: bool) -> None:
|
|
66
|
+
if show_diff and not dry_run_enabled:
|
|
67
|
+
abort("`--diff` requires `--dry-run`.")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def execute_or_exit[ResultT](action: Callable[[], ResultT]) -> ResultT:
|
|
71
|
+
try:
|
|
72
|
+
return action()
|
|
73
|
+
except (
|
|
74
|
+
FileExistsError,
|
|
75
|
+
FileNotFoundError,
|
|
76
|
+
NotImplementedError,
|
|
77
|
+
subprocess.CalledProcessError,
|
|
78
|
+
ValueError,
|
|
79
|
+
) as error:
|
|
80
|
+
abort(str(error))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def abort(message: str) -> Never:
|
|
84
|
+
console.print(f"[bold red]Error:[/bold red] {message}")
|
|
85
|
+
raise typer.Exit(code=1)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from pyarch.cli.common import (
|
|
6
|
+
DiffOption,
|
|
7
|
+
DryRunOption,
|
|
8
|
+
console,
|
|
9
|
+
ensure_diff_with_dry_run,
|
|
10
|
+
execute_or_exit,
|
|
11
|
+
run_dry_or_exit,
|
|
12
|
+
)
|
|
13
|
+
from pyarch.services.create_module import create_module
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(no_args_is_help=True)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.command("module")
|
|
19
|
+
def generate_module(
|
|
20
|
+
module_name: Annotated[str, typer.Argument(help="Module name.")],
|
|
21
|
+
protected: Annotated[
|
|
22
|
+
bool,
|
|
23
|
+
typer.Option(
|
|
24
|
+
"--protected",
|
|
25
|
+
help="Protect generated routes with the auth integration.",
|
|
26
|
+
),
|
|
27
|
+
] = False,
|
|
28
|
+
cached: Annotated[
|
|
29
|
+
bool,
|
|
30
|
+
typer.Option(
|
|
31
|
+
"--cache",
|
|
32
|
+
help="Cache single-item reads in Redis (requires the redis integration).",
|
|
33
|
+
),
|
|
34
|
+
] = False,
|
|
35
|
+
dry_run: DryRunOption = False,
|
|
36
|
+
show_diff: DiffOption = False,
|
|
37
|
+
) -> None:
|
|
38
|
+
"""Generate a CRUD module using the project's manifest."""
|
|
39
|
+
|
|
40
|
+
ensure_diff_with_dry_run(show_diff, dry_run)
|
|
41
|
+
if dry_run:
|
|
42
|
+
run_dry_or_exit(
|
|
43
|
+
lambda root: create_module(
|
|
44
|
+
module_name, start=root, protected=protected, cached=cached
|
|
45
|
+
),
|
|
46
|
+
show_diff=show_diff,
|
|
47
|
+
)
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
project_root, created_files = execute_or_exit(
|
|
51
|
+
lambda: create_module(module_name, protected=protected, cached=cached)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
console.print(
|
|
55
|
+
f"[green]Created module[/green] [bold]{module_name}[/bold] in {project_root}"
|
|
56
|
+
)
|
|
57
|
+
for file_path in created_files:
|
|
58
|
+
console.print(f" [dim]{file_path.relative_to(project_root)}[/dim]")
|
|
@@ -109,6 +109,7 @@ def load_manifest(project_dir: Path) -> ProjectManifest:
|
|
|
109
109
|
state=ProjectState(
|
|
110
110
|
modules=require_string_list(state_data, "modules"),
|
|
111
111
|
integrations=require_string_list(state_data, "integrations"),
|
|
112
|
+
cached_modules=optional_string_list(state_data, "cached_modules"),
|
|
112
113
|
),
|
|
113
114
|
)
|
|
114
115
|
except (KeyError, TypeError, ValueError) as error:
|
|
@@ -154,6 +155,7 @@ def save_manifest(project_dir: Path, manifest: ProjectManifest) -> Path:
|
|
|
154
155
|
state = table()
|
|
155
156
|
state.add("modules", manifest.state.modules)
|
|
156
157
|
state.add("integrations", manifest.state.integrations)
|
|
158
|
+
state.add("cached_modules", manifest.state.cached_modules)
|
|
157
159
|
doc.add("state", state)
|
|
158
160
|
|
|
159
161
|
temporary_path.write_text(dumps(doc), encoding="utf-8")
|
|
@@ -188,3 +190,12 @@ def require_string_list(data: dict[str, Any], key: str) -> list[str]:
|
|
|
188
190
|
if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
|
|
189
191
|
raise ManifestError(f"{key!r} must be an array of strings")
|
|
190
192
|
return list(value)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def optional_string_list(data: dict[str, Any], key: str) -> list[str]:
|
|
196
|
+
value = data.get(key)
|
|
197
|
+
if value is None:
|
|
198
|
+
return []
|
|
199
|
+
if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
|
|
200
|
+
raise ManifestError(f"{key!r} must be an array of strings")
|
|
201
|
+
return list(value)
|
|
@@ -80,6 +80,7 @@ def _validate_relative_dir(name: str, value: str) -> None:
|
|
|
80
80
|
class ProjectState:
|
|
81
81
|
modules: list[str] = field(default_factory=list)
|
|
82
82
|
integrations: list[str] = field(default_factory=list)
|
|
83
|
+
cached_modules: list[str] = field(default_factory=list)
|
|
83
84
|
|
|
84
85
|
|
|
85
86
|
@dataclass(slots=True)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
from collections.abc import Iterator
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from contextvars import ContextVar
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
_recorded_commands: ContextVar[list[tuple[str, ...]] | None] = ContextVar(
|
|
8
|
+
"recorded_commands", default=None
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run_command(*command: str, cwd: Path | None = None) -> None:
|
|
13
|
+
recorded = _recorded_commands.get()
|
|
14
|
+
if recorded is not None:
|
|
15
|
+
recorded.append(command)
|
|
16
|
+
return
|
|
17
|
+
|
|
18
|
+
subprocess.run(command, cwd=cwd or Path.cwd(), check=True)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@contextmanager
|
|
22
|
+
def record_commands() -> Iterator[list[tuple[str, ...]]]:
|
|
23
|
+
"""Collect external commands instead of executing them."""
|
|
24
|
+
|
|
25
|
+
recorded: list[tuple[str, ...]] = []
|
|
26
|
+
token = _recorded_commands.set(recorded)
|
|
27
|
+
try:
|
|
28
|
+
yield recorded
|
|
29
|
+
finally:
|
|
30
|
+
_recorded_commands.reset(token)
|