PyArch-CLI 0.1.2__tar.gz → 0.2.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.2.0/.release-dist/.gitignore +1 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/PKG-INFO +53 -14
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/README.md +51 -12
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/pyproject.toml +4 -2
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/common.py +2 -5
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/common/filesystem.py +40 -4
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/module/layered.py +9 -10
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/project/base.py +34 -15
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/project/layered.py +1 -1
- pyarch_cli-0.2.0/src/pyarch/services/add_integration.py +65 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/services/create_module.py +28 -13
- pyarch_cli-0.2.0/src/pyarch/services/create_project.py +37 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/service.py.j2 +14 -5
- pyarch_cli-0.1.2/src/pyarch/templates/project/base/docker-compose.yml.j2 → pyarch_cli-0.2.0/src/pyarch/templates/project/base/docker-compose.postgres.yml.j2 +53 -55
- pyarch_cli-0.2.0/src/pyarch/templates/project/base/docker-compose.sqlite.yml.j2 +14 -0
- pyarch_cli-0.2.0/tests/integration/test_generated_project.py +58 -0
- pyarch_cli-0.2.0/tests/integration/test_project_generation.py +95 -0
- pyarch_cli-0.2.0/tests/unit/test_filesystem.py +27 -0
- pyarch_cli-0.2.0/tests/unit/test_manifest.py +29 -0
- pyarch_cli-0.2.0/tests/unit/test_module_generator.py +43 -0
- pyarch_cli-0.2.0/tests/unit/test_templates.py +65 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/uv.lock +50 -2
- pyarch_cli-0.1.2/src/pyarch/services/add_integration.py +0 -35
- pyarch_cli-0.1.2/src/pyarch/services/create_project.py +0 -19
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/.gitignore +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/.python-version +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/LICENSE +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/assets/Dockerfile.vhs +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/assets/pyarch-demo.gif +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/assets/pyarch-demo.tape +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/assets/vhs-uv +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/add.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/app.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/generate.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/info.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/cli/init.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/config/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/config/manifest.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/config/models.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/common/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/common/commands.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/common/gitignore.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/common/renderer.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/integration/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/integration/auth.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/module/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/generators/project/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/main.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/services/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/alembic_env.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/config.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/dependencies.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/routes.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/tokens.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/user_model.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/utils.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/config.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/env.example.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/errors.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/models_init.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_router.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_schema.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_service.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_test.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/router.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/session.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/Dockerfile.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/README.md.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/conftest.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/main.py.j2 +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: PyArch-CLI
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -34,7 +34,7 @@ Description-Content-Type: text/markdown
|
|
|
34
34
|

|
|
35
35
|

|
|
36
36
|

|
|
37
|
-

|
|
38
38
|
|
|
39
39
|
PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
|
|
40
40
|
the application structure, database, tests and Alembic, then lets you add CRUD
|
|
@@ -62,6 +62,15 @@ ready to change.
|
|
|
62
62
|
- Alembic setup for relational databases
|
|
63
63
|
- Tests and dependency setup through `uv`
|
|
64
64
|
- Project-aware generation through `pyarch.toml`
|
|
65
|
+
- Atomic project creation and rollback for failed extensions
|
|
66
|
+
|
|
67
|
+
## v0.2.0 Highlights
|
|
68
|
+
|
|
69
|
+
- Atomic project creation through a staging directory, with cleanup on failure
|
|
70
|
+
- Rollback for failed module and auth generation
|
|
71
|
+
- Database-specific Docker Compose files for PostgreSQL and SQLite
|
|
72
|
+
- Refresh-token rotation protected against concurrent reuse on PostgreSQL
|
|
73
|
+
- Self-tests for PyArch and an end-to-end generated-project workflow
|
|
65
74
|
|
|
66
75
|
## Quick Start
|
|
67
76
|
|
|
@@ -81,12 +90,31 @@ pyarch init my_project --database postgres
|
|
|
81
90
|
cd my_project
|
|
82
91
|
```
|
|
83
92
|
|
|
84
|
-
Copy `.env.example` to `.env` and set the database connection values.
|
|
93
|
+
Copy `.env.example` to `.env` and set the database connection values. The
|
|
94
|
+
generated Compose file matches the selected database: PostgreSQL projects get
|
|
95
|
+
database services; SQLite projects get only migration and API services.
|
|
96
|
+
|
|
97
|
+
Start the generated application:
|
|
85
98
|
|
|
86
99
|
```bash
|
|
87
100
|
docker compose up -d
|
|
88
101
|
```
|
|
89
102
|
|
|
103
|
+
After adding a generated module or integration that changes the database
|
|
104
|
+
schema, create a revision with
|
|
105
|
+
`uv run alembic revision --autogenerate -m "describe schema change"`. Then
|
|
106
|
+
apply it with `uv run alembic upgrade head`.
|
|
107
|
+
PyArch never autogenerates revisions during container startup: migration files
|
|
108
|
+
are source code and should be reviewed and committed.
|
|
109
|
+
|
|
110
|
+
## Safe Generation
|
|
111
|
+
|
|
112
|
+
`pyarch init` builds the project in a staging directory and publishes it only
|
|
113
|
+
after all generation steps complete. If setup fails, the staging directory is
|
|
114
|
+
removed. `generate module` and `add integration` track every affected file and
|
|
115
|
+
restore the previous state if a generation step fails, including the manifest
|
|
116
|
+
and dependency files.
|
|
117
|
+
|
|
90
118
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
91
119
|
|
|
92
120
|
You can now extend the project:
|
|
@@ -177,7 +205,7 @@ Clone the repository and install the development environment:
|
|
|
177
205
|
```bash
|
|
178
206
|
git clone https://github.com/Allcode-1/PyArch.git
|
|
179
207
|
cd PyArch
|
|
180
|
-
uv sync
|
|
208
|
+
uv sync --group dev
|
|
181
209
|
```
|
|
182
210
|
|
|
183
211
|
Run the CLI from the checkout:
|
|
@@ -192,6 +220,15 @@ Or install the current checkout as an editable CLI tool:
|
|
|
192
220
|
uv tool install --editable .
|
|
193
221
|
```
|
|
194
222
|
|
|
223
|
+
Run the project checks before opening a pull request or releasing a version:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
uv run pytest
|
|
227
|
+
uv run ruff check src tests
|
|
228
|
+
uv run mypy src tests
|
|
229
|
+
uv build
|
|
230
|
+
```
|
|
231
|
+
|
|
195
232
|
## Architecture and Design
|
|
196
233
|
|
|
197
234
|
<details>
|
|
@@ -246,26 +283,28 @@ instead of producing incomplete files.
|
|
|
246
283
|
|
|
247
284
|
## Roadmap
|
|
248
285
|
|
|
249
|
-
### v0.2
|
|
286
|
+
### v0.2.0 (current)
|
|
250
287
|
|
|
251
|
-
-
|
|
252
|
-
- rollback
|
|
253
|
-
-
|
|
288
|
+
- atomic project creation and cleanup on failure;
|
|
289
|
+
- rollback for failed module and auth generation;
|
|
290
|
+
- PostgreSQL- and SQLite-specific Compose templates;
|
|
291
|
+
- self-test suite and generated-project integration coverage.
|
|
254
292
|
|
|
255
293
|
### v0.3
|
|
256
294
|
|
|
257
|
-
- Redis integration;
|
|
258
|
-
-
|
|
295
|
+
- Redis integration foundation;
|
|
296
|
+
- opt-in cache-aside generation for CRUD modules;
|
|
259
297
|
- dry-run mode.
|
|
260
298
|
|
|
261
299
|
### Later
|
|
262
300
|
|
|
301
|
+
- scheduler integration;
|
|
263
302
|
- more architectures;
|
|
264
303
|
- plugin system;
|
|
265
304
|
- asynchronous database access.
|
|
266
305
|
|
|
267
306
|
## Status
|
|
268
307
|
|
|
269
|
-
PyArch is
|
|
270
|
-
templates, generated code and the manifest may still change before a
|
|
271
|
-
release.
|
|
308
|
+
PyArch v0.2.0 is an early alpha release. The main workflow is usable, but
|
|
309
|
+
commands, templates, generated code and the manifest may still change before a
|
|
310
|
+
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
|
|
@@ -34,6 +34,15 @@ ready to change.
|
|
|
34
34
|
- Alembic setup for relational databases
|
|
35
35
|
- Tests and dependency setup through `uv`
|
|
36
36
|
- Project-aware generation through `pyarch.toml`
|
|
37
|
+
- Atomic project creation and rollback for failed extensions
|
|
38
|
+
|
|
39
|
+
## v0.2.0 Highlights
|
|
40
|
+
|
|
41
|
+
- Atomic project creation through a staging directory, with cleanup on failure
|
|
42
|
+
- Rollback for failed module and auth generation
|
|
43
|
+
- Database-specific Docker Compose files for PostgreSQL and SQLite
|
|
44
|
+
- Refresh-token rotation protected against concurrent reuse on PostgreSQL
|
|
45
|
+
- Self-tests for PyArch and an end-to-end generated-project workflow
|
|
37
46
|
|
|
38
47
|
## Quick Start
|
|
39
48
|
|
|
@@ -53,12 +62,31 @@ pyarch init my_project --database postgres
|
|
|
53
62
|
cd my_project
|
|
54
63
|
```
|
|
55
64
|
|
|
56
|
-
Copy `.env.example` to `.env` and set the database connection values.
|
|
65
|
+
Copy `.env.example` to `.env` and set the database connection values. The
|
|
66
|
+
generated Compose file matches the selected database: PostgreSQL projects get
|
|
67
|
+
database services; SQLite projects get only migration and API services.
|
|
68
|
+
|
|
69
|
+
Start the generated application:
|
|
57
70
|
|
|
58
71
|
```bash
|
|
59
72
|
docker compose up -d
|
|
60
73
|
```
|
|
61
74
|
|
|
75
|
+
After adding a generated module or integration that changes the database
|
|
76
|
+
schema, create a revision with
|
|
77
|
+
`uv run alembic revision --autogenerate -m "describe schema change"`. Then
|
|
78
|
+
apply it with `uv run alembic upgrade head`.
|
|
79
|
+
PyArch never autogenerates revisions during container startup: migration files
|
|
80
|
+
are source code and should be reviewed and committed.
|
|
81
|
+
|
|
82
|
+
## Safe Generation
|
|
83
|
+
|
|
84
|
+
`pyarch init` builds the project in a staging directory and publishes it only
|
|
85
|
+
after all generation steps complete. If setup fails, the staging directory is
|
|
86
|
+
removed. `generate module` and `add integration` track every affected file and
|
|
87
|
+
restore the previous state if a generation step fails, including the manifest
|
|
88
|
+
and dependency files.
|
|
89
|
+
|
|
62
90
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
63
91
|
|
|
64
92
|
You can now extend the project:
|
|
@@ -149,7 +177,7 @@ Clone the repository and install the development environment:
|
|
|
149
177
|
```bash
|
|
150
178
|
git clone https://github.com/Allcode-1/PyArch.git
|
|
151
179
|
cd PyArch
|
|
152
|
-
uv sync
|
|
180
|
+
uv sync --group dev
|
|
153
181
|
```
|
|
154
182
|
|
|
155
183
|
Run the CLI from the checkout:
|
|
@@ -164,6 +192,15 @@ Or install the current checkout as an editable CLI tool:
|
|
|
164
192
|
uv tool install --editable .
|
|
165
193
|
```
|
|
166
194
|
|
|
195
|
+
Run the project checks before opening a pull request or releasing a version:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
uv run pytest
|
|
199
|
+
uv run ruff check src tests
|
|
200
|
+
uv run mypy src tests
|
|
201
|
+
uv build
|
|
202
|
+
```
|
|
203
|
+
|
|
167
204
|
## Architecture and Design
|
|
168
205
|
|
|
169
206
|
<details>
|
|
@@ -218,26 +255,28 @@ instead of producing incomplete files.
|
|
|
218
255
|
|
|
219
256
|
## Roadmap
|
|
220
257
|
|
|
221
|
-
### v0.2
|
|
258
|
+
### v0.2.0 (current)
|
|
222
259
|
|
|
223
|
-
-
|
|
224
|
-
- rollback
|
|
225
|
-
-
|
|
260
|
+
- atomic project creation and cleanup on failure;
|
|
261
|
+
- rollback for failed module and auth generation;
|
|
262
|
+
- PostgreSQL- and SQLite-specific Compose templates;
|
|
263
|
+
- self-test suite and generated-project integration coverage.
|
|
226
264
|
|
|
227
265
|
### v0.3
|
|
228
266
|
|
|
229
|
-
- Redis integration;
|
|
230
|
-
-
|
|
267
|
+
- Redis integration foundation;
|
|
268
|
+
- opt-in cache-aside generation for CRUD modules;
|
|
231
269
|
- dry-run mode.
|
|
232
270
|
|
|
233
271
|
### Later
|
|
234
272
|
|
|
273
|
+
- scheduler integration;
|
|
235
274
|
- more architectures;
|
|
236
275
|
- plugin system;
|
|
237
276
|
- asynchronous database access.
|
|
238
277
|
|
|
239
278
|
## Status
|
|
240
279
|
|
|
241
|
-
PyArch is
|
|
242
|
-
templates, generated code and the manifest may still change before a
|
|
243
|
-
release.
|
|
280
|
+
PyArch v0.2.0 is an early alpha release. The main workflow is usable, but
|
|
281
|
+
commands, templates, generated code and the manifest may still change before a
|
|
282
|
+
stable release.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "PyArch-CLI"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Stateful CLI generator for Layered FastAPI projects"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
@@ -43,4 +43,6 @@ build-backend = "hatchling.build"
|
|
|
43
43
|
packages = ["src/pyarch"]
|
|
44
44
|
|
|
45
45
|
[dependency-groups]
|
|
46
|
-
dev = [
|
|
46
|
+
dev = [
|
|
47
|
+
"pytest>=9.1.1",
|
|
48
|
+
]
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import subprocess
|
|
2
2
|
from collections.abc import Callable
|
|
3
|
-
from typing import Never
|
|
3
|
+
from typing import Never
|
|
4
4
|
|
|
5
5
|
import typer
|
|
6
6
|
from rich.console import Console
|
|
7
7
|
|
|
8
8
|
console = Console()
|
|
9
|
-
ResultT
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def execute_or_exit(action: Callable[[], ResultT]) -> ResultT:
|
|
9
|
+
def execute_or_exit[ResultT](action: Callable[[], ResultT]) -> ResultT:
|
|
13
10
|
try:
|
|
14
11
|
return action()
|
|
15
12
|
except (
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from pathlib import Path
|
|
2
4
|
|
|
3
5
|
|
|
4
6
|
def create_empty_dir(directory: Path) -> Path:
|
|
@@ -43,7 +45,7 @@ def insert_line_before_marker(
|
|
|
43
45
|
return True
|
|
44
46
|
|
|
45
47
|
|
|
46
|
-
def append_text_once(file_path: Path, marker: str, text: str) -> bool:
|
|
48
|
+
def append_text_once(file_path: Path, marker: str, text: str) -> bool:
|
|
47
49
|
content = file_path.read_text(encoding="utf-8") if file_path.exists() else ""
|
|
48
50
|
|
|
49
51
|
if marker in content:
|
|
@@ -51,5 +53,39 @@ def append_text_once(file_path: Path, marker: str, text: str) -> bool:
|
|
|
51
53
|
|
|
52
54
|
separator = "" if not content or content.endswith("\n") else "\n"
|
|
53
55
|
file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
54
|
-
file_path.write_text(f"{content}{separator}{text}", encoding="utf-8")
|
|
55
|
-
return True
|
|
56
|
+
file_path.write_text(f"{content}{separator}{text}", encoding="utf-8")
|
|
57
|
+
return True
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@contextmanager
|
|
61
|
+
def rollback_file_changes(
|
|
62
|
+
files: tuple[Path, ...],
|
|
63
|
+
directories: tuple[Path, ...] = (),
|
|
64
|
+
) -> Iterator[None]:
|
|
65
|
+
"""Restore tracked files if a generation step fails."""
|
|
66
|
+
|
|
67
|
+
snapshots = {
|
|
68
|
+
file_path: file_path.read_bytes() if file_path.is_file() else None
|
|
69
|
+
for file_path in files
|
|
70
|
+
}
|
|
71
|
+
created_directories = tuple(
|
|
72
|
+
directory for directory in directories if not directory.exists()
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
yield
|
|
77
|
+
except BaseException:
|
|
78
|
+
for file_path, content in snapshots.items():
|
|
79
|
+
if content is None:
|
|
80
|
+
file_path.unlink(missing_ok=True)
|
|
81
|
+
else:
|
|
82
|
+
file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
83
|
+
file_path.write_bytes(content)
|
|
84
|
+
|
|
85
|
+
for directory in sorted(created_directories, key=lambda path: len(path.parts), reverse=True):
|
|
86
|
+
try:
|
|
87
|
+
directory.rmdir()
|
|
88
|
+
except OSError:
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
raise
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import keyword
|
|
2
|
-
import re
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
from pyarch.config.models import DatabaseEngine
|
|
6
|
-
from pyarch.generators.common.filesystem import insert_line_before_marker
|
|
7
|
-
from pyarch.generators.common.renderer import create_file_from_template
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
MODULE_NAME_PATTERN = re.compile(r"^[a-z][a-z0-9_]*$")
|
|
1
|
+
import keyword
|
|
2
|
+
import re
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from pyarch.config.models import DatabaseEngine
|
|
6
|
+
from pyarch.generators.common.filesystem import insert_line_before_marker
|
|
7
|
+
from pyarch.generators.common.renderer import create_file_from_template
|
|
8
|
+
|
|
9
|
+
MODULE_NAME_PATTERN = re.compile(r"^[a-z][a-z0-9_]*$")
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
def create_layered_module(
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Create a base for any project.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
from pyarch.
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from pyarch.config.models import DatabaseEngine
|
|
8
|
+
from pyarch.generators.common.commands import run_command
|
|
8
9
|
from pyarch.generators.common.filesystem import create_empty_dir, create_empty_file
|
|
9
10
|
from pyarch.generators.common.gitignore import (
|
|
10
11
|
BASE_GITIGNORE_ENTRIES,
|
|
@@ -13,19 +14,31 @@ from pyarch.generators.common.gitignore import (
|
|
|
13
14
|
from pyarch.generators.common.renderer import create_file_from_template
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
def create_base_dir(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
def create_base_dir(
|
|
18
|
+
project_dir: Path,
|
|
19
|
+
project_name: str,
|
|
20
|
+
database: DatabaseEngine,
|
|
21
|
+
) -> Path:
|
|
22
|
+
|
|
23
|
+
project_dir.mkdir(parents=True, exist_ok=False)
|
|
24
|
+
|
|
25
|
+
# creating base uv app
|
|
26
|
+
run_command(
|
|
27
|
+
"uv",
|
|
28
|
+
"init",
|
|
29
|
+
"--name",
|
|
30
|
+
project_name,
|
|
31
|
+
"--no-workspace",
|
|
32
|
+
".",
|
|
33
|
+
cwd=project_dir,
|
|
34
|
+
)
|
|
22
35
|
|
|
23
36
|
# .gitignote
|
|
24
37
|
ensure_gitignore_entries(project_dir, "base", BASE_GITIGNORE_ENTRIES)
|
|
25
38
|
|
|
26
39
|
# docker
|
|
27
40
|
create_dockerfile(project_dir)
|
|
28
|
-
create_docker_compose(project_dir)
|
|
41
|
+
create_docker_compose(project_dir, database)
|
|
29
42
|
|
|
30
43
|
# docs
|
|
31
44
|
create_docs_dir(project_dir)
|
|
@@ -40,11 +53,17 @@ def create_dockerfile(project_dir: Path) -> None:
|
|
|
40
53
|
)
|
|
41
54
|
|
|
42
55
|
|
|
43
|
-
def create_docker_compose(project_dir: Path) -> None:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
def create_docker_compose(project_dir: Path, database: DatabaseEngine) -> None:
|
|
57
|
+
template_name = (
|
|
58
|
+
"project/base/docker-compose.postgres.yml.j2"
|
|
59
|
+
if database is DatabaseEngine.POSTGRES
|
|
60
|
+
else "project/base/docker-compose.sqlite.yml.j2"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
create_file_from_template(
|
|
64
|
+
template_name=template_name,
|
|
65
|
+
output_path=project_dir / "docker-compose.yml",
|
|
66
|
+
)
|
|
48
67
|
|
|
49
68
|
|
|
50
69
|
def create_docs_dir(project_dir: Path) -> None:
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from pyarch.config.manifest import find_project_root, load_manifest, save_manifest
|
|
4
|
+
from pyarch.generators.common.filesystem import rollback_file_changes
|
|
5
|
+
from pyarch.generators.integration.auth import (
|
|
6
|
+
AUTH_INTEGRATION_NAME,
|
|
7
|
+
create_auth_integration,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def add_integration(
|
|
12
|
+
integration_name: str,
|
|
13
|
+
start: Path | None = None,
|
|
14
|
+
) -> tuple[Path, tuple[Path, ...]]:
|
|
15
|
+
project_root = find_project_root(start)
|
|
16
|
+
manifest = load_manifest(project_root)
|
|
17
|
+
normalized_name = integration_name.strip().lower().replace("-", "_")
|
|
18
|
+
|
|
19
|
+
if not normalized_name:
|
|
20
|
+
raise ValueError("Integration name cannot be empty")
|
|
21
|
+
|
|
22
|
+
if normalized_name in manifest.state.integrations:
|
|
23
|
+
raise FileExistsError(f"Integration {normalized_name!r} is already registered")
|
|
24
|
+
|
|
25
|
+
if normalized_name != AUTH_INTEGRATION_NAME:
|
|
26
|
+
raise NotImplementedError(
|
|
27
|
+
f"Integration {normalized_name!r} does not have a generator yet"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
app_path = project_root / manifest.paths.application
|
|
31
|
+
auth_path = app_path / "auth"
|
|
32
|
+
certs_path = project_root / "certs"
|
|
33
|
+
tracked_files = (
|
|
34
|
+
auth_path / "__init__.py",
|
|
35
|
+
auth_path / "dependencies.py",
|
|
36
|
+
auth_path / "routes.py",
|
|
37
|
+
auth_path / "schemas.py",
|
|
38
|
+
auth_path / "service.py",
|
|
39
|
+
auth_path / "tokens.py",
|
|
40
|
+
auth_path / "utils.py",
|
|
41
|
+
app_path / "models" / "user.py",
|
|
42
|
+
app_path / "models" / "refresh_session.py",
|
|
43
|
+
project_root / manifest.paths.tests / "helpers.py",
|
|
44
|
+
project_root / manifest.paths.tests / "test_auth.py",
|
|
45
|
+
app_path / "core" / "config.py",
|
|
46
|
+
certs_path / "private.pem",
|
|
47
|
+
certs_path / "public.pem",
|
|
48
|
+
app_path / "models" / "__init__.py",
|
|
49
|
+
app_path / "api" / "v1" / "router.py",
|
|
50
|
+
project_root / ".env.example",
|
|
51
|
+
project_root / ".gitignore",
|
|
52
|
+
project_root / "pyproject.toml",
|
|
53
|
+
project_root / "uv.lock",
|
|
54
|
+
project_root / "pyarch.toml",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
with rollback_file_changes(tracked_files, (auth_path, certs_path)):
|
|
58
|
+
created_files = create_auth_integration(
|
|
59
|
+
project_root,
|
|
60
|
+
manifest.database.engine,
|
|
61
|
+
)
|
|
62
|
+
manifest.state.integrations.append(normalized_name)
|
|
63
|
+
save_manifest(project_root, manifest)
|
|
64
|
+
|
|
65
|
+
return project_root, created_files
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from pyarch.config.manifest import find_project_root, load_manifest, save_manifest
|
|
4
|
-
from pyarch.config.models import Architecture
|
|
5
|
-
from pyarch.generators.
|
|
3
|
+
from pyarch.config.manifest import find_project_root, load_manifest, save_manifest
|
|
4
|
+
from pyarch.config.models import Architecture
|
|
5
|
+
from pyarch.generators.common.filesystem import rollback_file_changes
|
|
6
|
+
from pyarch.generators.integration.auth import AUTH_INTEGRATION_NAME
|
|
6
7
|
from pyarch.generators.module.layered import (
|
|
7
8
|
create_layered_module,
|
|
8
9
|
normalize_module_name,
|
|
@@ -32,13 +33,27 @@ def create_module(
|
|
|
32
33
|
"Run `pyarch add integration auth` first."
|
|
33
34
|
)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
normalized_name,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
app_path = project_root / manifest.paths.application
|
|
37
|
+
tracked_files = (
|
|
38
|
+
app_path / "models" / f"{normalized_name}.py",
|
|
39
|
+
app_path / "schemas" / f"{normalized_name}.py",
|
|
40
|
+
app_path / "repositories" / f"{normalized_name}.py",
|
|
41
|
+
app_path / "services" / f"{normalized_name}.py",
|
|
42
|
+
app_path / "api" / "v1" / f"{normalized_name}.py",
|
|
43
|
+
project_root / manifest.paths.tests / f"test_{normalized_name}.py",
|
|
44
|
+
app_path / "models" / "__init__.py",
|
|
45
|
+
app_path / "api" / "v1" / "router.py",
|
|
46
|
+
project_root / "pyarch.toml",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
with rollback_file_changes(tracked_files):
|
|
50
|
+
created_files = create_layered_module(
|
|
51
|
+
project_root,
|
|
52
|
+
normalized_name,
|
|
53
|
+
manifest.database.engine,
|
|
54
|
+
protected=protected,
|
|
55
|
+
)
|
|
56
|
+
manifest.state.modules.append(normalized_name)
|
|
57
|
+
save_manifest(project_root, manifest)
|
|
58
|
+
|
|
59
|
+
return project_root, created_files
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from pyarch.config.manifest import create_manifest
|
|
6
|
+
from pyarch.config.models import DatabaseEngine
|
|
7
|
+
from pyarch.generators.common.commands import run_command
|
|
8
|
+
from pyarch.generators.project.base import create_base_dir, create_readme_file
|
|
9
|
+
from pyarch.generators.project.layered import create_layered_project
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_project(
|
|
13
|
+
project_name: str,
|
|
14
|
+
database: DatabaseEngine | str = DatabaseEngine.POSTGRES,
|
|
15
|
+
) -> Path:
|
|
16
|
+
database = DatabaseEngine(database)
|
|
17
|
+
project_dir = (Path.cwd() / project_name).resolve()
|
|
18
|
+
|
|
19
|
+
if project_dir.exists():
|
|
20
|
+
raise FileExistsError(f"Project directory already exists: {project_dir}")
|
|
21
|
+
|
|
22
|
+
staging_dir = project_dir.parent / f".{project_dir.name}.pyarch-{uuid4().hex}"
|
|
23
|
+
published = False
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
create_base_dir(staging_dir, project_dir.name, database)
|
|
27
|
+
create_layered_project(staging_dir, database)
|
|
28
|
+
create_readme_file(staging_dir, project_name, database.value)
|
|
29
|
+
create_manifest(staging_dir, project_name, database)
|
|
30
|
+
staging_dir.rename(project_dir)
|
|
31
|
+
published = True
|
|
32
|
+
run_command("uv", "sync", "--reinstall", cwd=project_dir)
|
|
33
|
+
except BaseException:
|
|
34
|
+
shutil.rmtree(project_dir if published else staging_dir, ignore_errors=True)
|
|
35
|
+
raise
|
|
36
|
+
|
|
37
|
+
return project_dir
|
|
@@ -35,8 +35,17 @@ def decode_refresh_payload(refresh_token: str) -> dict:
|
|
|
35
35
|
return token_payload
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
def get_refresh_session(
|
|
39
|
-
|
|
38
|
+
def get_refresh_session(
|
|
39
|
+
db: Session,
|
|
40
|
+
jti: str,
|
|
41
|
+
*,
|
|
42
|
+
lock: bool = False,
|
|
43
|
+
) -> RefreshSession:
|
|
44
|
+
statement = select(RefreshSession).where(RefreshSession.jti == jti)
|
|
45
|
+
if lock:
|
|
46
|
+
statement = statement.with_for_update()
|
|
47
|
+
|
|
48
|
+
refresh_session = db.scalar(statement)
|
|
40
49
|
|
|
41
50
|
if not refresh_session:
|
|
42
51
|
raise invalid_token_error()
|
|
@@ -131,9 +140,9 @@ def logout_user(refresh_token: str, db: Session) -> dict[str, str]:
|
|
|
131
140
|
return {"message": "Logged out"}
|
|
132
141
|
|
|
133
142
|
|
|
134
|
-
def refresh_tokens(refresh_token: str, db: Session) -> TokenPair:
|
|
135
|
-
token_payload = decode_refresh_payload(refresh_token)
|
|
136
|
-
refresh_session = get_refresh_session(db, token_payload["jti"])
|
|
143
|
+
def refresh_tokens(refresh_token: str, db: Session) -> TokenPair:
|
|
144
|
+
token_payload = decode_refresh_payload(refresh_token)
|
|
145
|
+
refresh_session = get_refresh_session(db, token_payload["jti"], lock=True)
|
|
137
146
|
|
|
138
147
|
if refresh_session.revoked_at is not None:
|
|
139
148
|
raise invalid_token_error()
|