PyArch-CLI 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/.gitignore +1 -1
  2. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/PKG-INFO +17 -23
  3. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/README.md +14 -22
  4. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/pyproject.toml +3 -1
  5. pyarch_cli-0.1.2/src/pyarch/__init__.py +1 -0
  6. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/add.py +3 -2
  7. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/app.py +4 -8
  8. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/common.py +0 -1
  9. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/generate.py +1 -3
  10. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/info.py +1 -4
  11. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/init.py +2 -6
  12. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/config/manifest.py +8 -4
  13. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/common/gitignore.py +3 -2
  14. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/common/renderer.py +0 -1
  15. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/integration/auth.py +4 -5
  16. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/module/layered.py +39 -38
  17. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/project/base.py +24 -10
  18. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/project/layered.py +8 -4
  19. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/services/add_integration.py +1 -3
  20. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/services/create_module.py +1 -3
  21. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/services/create_project.py +18 -19
  22. pyarch_cli-0.1.2/src/pyarch/templates/layered/env.example.j2 +16 -0
  23. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/errors.py.j2 +1 -0
  24. pyarch_cli-0.1.2/src/pyarch/templates/project/base/Dockerfile.j2 +16 -0
  25. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/project/base/README.md.j2 +3 -10
  26. pyarch_cli-0.1.2/src/pyarch/templates/project/base/docker-compose.yml.j2 +55 -0
  27. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/uv.lock +188 -0
  28. pyarch_cli-0.1.1/script_base.py +0 -355
  29. pyarch_cli-0.1.1/src/pyarch/__init__.py +0 -1
  30. pyarch_cli-0.1.1/src/pyarch/templates/layered/env.example.j2 +0 -7
  31. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/.python-version +0 -0
  32. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/LICENSE +0 -0
  33. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/assets/Dockerfile.vhs +0 -0
  34. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/assets/pyarch-demo.gif +0 -0
  35. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/assets/pyarch-demo.tape +0 -0
  36. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/assets/vhs-uv +0 -0
  37. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/cli/__init__.py +0 -0
  38. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/config/__init__.py +0 -0
  39. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/config/models.py +0 -0
  40. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/__init__.py +0 -0
  41. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/common/__init__.py +0 -0
  42. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/common/commands.py +0 -0
  43. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/common/filesystem.py +0 -0
  44. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/integration/__init__.py +0 -0
  45. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/module/__init__.py +0 -0
  46. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/generators/project/__init__.py +0 -0
  47. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/main.py +0 -0
  48. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/services/__init__.py +0 -0
  49. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/alembic_env.py.j2 +0 -0
  50. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/config.py.j2 +0 -0
  51. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/dependencies.py.j2 +0 -0
  52. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
  53. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/routes.py.j2 +0 -0
  54. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
  55. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/service.py.j2 +0 -0
  56. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
  57. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
  58. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/tokens.py.j2 +0 -0
  59. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/user_model.py.j2 +0 -0
  60. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/auth/utils.py.j2 +0 -0
  61. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/config.py.j2 +0 -0
  62. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
  63. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/models_init.py.j2 +0 -0
  64. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
  65. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
  66. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_router.py.j2 +0 -0
  67. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +0 -0
  68. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_schema.py.j2 +0 -0
  69. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_service.py.j2 +0 -0
  70. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_test.py.j2 +0 -0
  71. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +0 -0
  72. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
  73. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/router.py.j2 +0 -0
  74. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/layered/session.py.j2 +0 -0
  75. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/project/base/conftest.py.j2 +0 -0
  76. {pyarch_cli-0.1.1 → pyarch_cli-0.1.2}/src/pyarch/templates/project/base/main.py.j2 +0 -0
@@ -5,7 +5,7 @@ build/
5
5
  dist/
6
6
  wheels/
7
7
  *.egg-info
8
+ *_cache
8
9
 
9
10
  # Virtual environments
10
11
  .venv
11
- after_script.txt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyArch-CLI
3
- Version: 0.1.1
3
+ Version: 0.1.2
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
@@ -19,7 +19,9 @@ Classifier: Topic :: Software Development :: Code Generators
19
19
  Requires-Python: >=3.13
20
20
  Requires-Dist: cryptography>=46.0.3
21
21
  Requires-Dist: jinja2>=3.1.6
22
+ Requires-Dist: mypy>=2.3.0
22
23
  Requires-Dist: rich>=15.0.0
24
+ Requires-Dist: ruff>=0.16.1
23
25
  Requires-Dist: tomlkit>=0.15.0
24
26
  Requires-Dist: typer>=0.24.2
25
27
  Description-Content-Type: text/markdown
@@ -79,18 +81,10 @@ pyarch init my_project --database postgres
79
81
  cd my_project
80
82
  ```
81
83
 
82
- Copy `.env.example` to `.env` and set the database connection values. For
83
- PostgreSQL or SQLite, create the first migration:
84
+ Copy `.env.example` to `.env` and set the database connection values. Start the services with Docker Compose:
84
85
 
85
86
  ```bash
86
- uv run alembic revision --autogenerate -m "initial"
87
- uv run alembic upgrade head
88
- ```
89
-
90
- Run the API:
91
-
92
- ```bash
93
- uv run uvicorn app.main:app --reload
87
+ docker compose up -d
94
88
  ```
95
89
 
96
90
  Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
@@ -139,24 +133,24 @@ Each generated CRUD module adds:
139
133
 
140
134
  ## Commands
141
135
 
142
- | Command | Description |
143
- | --- | --- |
144
- | `pyarch init <name>` | Create a Layered FastAPI project |
145
- | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
146
- | `pyarch generate module <name>` | Add a CRUD module to the current project |
147
- | `pyarch add integration auth` | Add JWT authentication and user management |
136
+ | Command | Description |
137
+ | ------------------------------------------- | ------------------------------------------------ |
138
+ | `pyarch init <name>` | Create a Layered FastAPI project |
139
+ | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
140
+ | `pyarch generate module <name>` | Add a CRUD module to the current project |
141
+ | `pyarch add integration auth` | Add JWT authentication and user management |
148
142
  | `pyarch generate module <name> --protected` | Generate CRUD routes that require authentication |
149
- | `pyarch info` | Show the current project configuration |
150
- | `pyarch --help` | Show CLI help |
143
+ | `pyarch info` | Show the current project configuration |
144
+ | `pyarch --help` | Show CLI help |
151
145
 
152
146
  Generation commands must be run inside a project created by PyArch.
153
147
 
154
148
  ## Databases and Current Limitations
155
149
 
156
- | Database | CRUD modules | Alembic | Auth integration | Protected modules |
157
- | --- | --- | --- | --- | --- |
158
- | PostgreSQL | Yes | Yes | Yes | Yes |
159
- | SQLite | Yes | Yes | Yes | Yes |
150
+ | Database | CRUD modules | Alembic | Auth integration | Protected modules |
151
+ | ---------- | ------------ | ------- | ---------------- | ----------------- |
152
+ | PostgreSQL | Yes | Yes | Yes | Yes |
153
+ | SQLite | Yes | Yes | Yes | Yes |
160
154
 
161
155
  Current limitations:
162
156
 
@@ -53,18 +53,10 @@ pyarch init my_project --database postgres
53
53
  cd my_project
54
54
  ```
55
55
 
56
- Copy `.env.example` to `.env` and set the database connection values. For
57
- PostgreSQL or SQLite, create the first migration:
56
+ Copy `.env.example` to `.env` and set the database connection values. Start the services with Docker Compose:
58
57
 
59
58
  ```bash
60
- uv run alembic revision --autogenerate -m "initial"
61
- uv run alembic upgrade head
62
- ```
63
-
64
- Run the API:
65
-
66
- ```bash
67
- uv run uvicorn app.main:app --reload
59
+ docker compose up -d
68
60
  ```
69
61
 
70
62
  Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
@@ -113,24 +105,24 @@ Each generated CRUD module adds:
113
105
 
114
106
  ## Commands
115
107
 
116
- | Command | Description |
117
- | --- | --- |
118
- | `pyarch init <name>` | Create a Layered FastAPI project |
119
- | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
120
- | `pyarch generate module <name>` | Add a CRUD module to the current project |
121
- | `pyarch add integration auth` | Add JWT authentication and user management |
108
+ | Command | Description |
109
+ | ------------------------------------------- | ------------------------------------------------ |
110
+ | `pyarch init <name>` | Create a Layered FastAPI project |
111
+ | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
112
+ | `pyarch generate module <name>` | Add a CRUD module to the current project |
113
+ | `pyarch add integration auth` | Add JWT authentication and user management |
122
114
  | `pyarch generate module <name> --protected` | Generate CRUD routes that require authentication |
123
- | `pyarch info` | Show the current project configuration |
124
- | `pyarch --help` | Show CLI help |
115
+ | `pyarch info` | Show the current project configuration |
116
+ | `pyarch --help` | Show CLI help |
125
117
 
126
118
  Generation commands must be run inside a project created by PyArch.
127
119
 
128
120
  ## Databases and Current Limitations
129
121
 
130
- | Database | CRUD modules | Alembic | Auth integration | Protected modules |
131
- | --- | --- | --- | --- | --- |
132
- | PostgreSQL | Yes | Yes | Yes | Yes |
133
- | SQLite | Yes | Yes | Yes | Yes |
122
+ | Database | CRUD modules | Alembic | Auth integration | Protected modules |
123
+ | ---------- | ------------ | ------- | ---------------- | ----------------- |
124
+ | PostgreSQL | Yes | Yes | Yes | Yes |
125
+ | SQLite | Yes | Yes | Yes | Yes |
134
126
 
135
127
  Current limitations:
136
128
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyArch-CLI"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "Stateful CLI generator for Layered FastAPI projects"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -20,7 +20,9 @@ classifiers = [
20
20
  dependencies = [
21
21
  "cryptography>=46.0.3",
22
22
  "jinja2>=3.1.6",
23
+ "mypy>=2.3.0",
23
24
  "rich>=15.0.0",
25
+ "ruff>=0.16.1",
24
26
  "tomlkit>=0.15.0",
25
27
  "typer>=0.24.2",
26
28
  ]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.2"
@@ -5,7 +5,6 @@ import typer
5
5
  from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.services.add_integration import add_integration
7
7
 
8
-
9
8
  app = typer.Typer(no_args_is_help=True)
10
9
 
11
10
 
@@ -18,7 +17,9 @@ def add_integration_command(
18
17
  ) -> None:
19
18
  """Add a supported integration to the current project."""
20
19
 
21
- project_root, created_files = execute_or_exit(lambda: add_integration(integration_name))
20
+ project_root, created_files = execute_or_exit(
21
+ lambda: add_integration(integration_name)
22
+ )
22
23
  console.print(
23
24
  f"[green]Added integration[/green] [bold]{integration_name}[/bold]"
24
25
  f" in {project_root}"
@@ -1,12 +1,10 @@
1
-
2
1
  import typer
3
2
 
4
- from pyarch.cli.info import show_info
5
3
  from pyarch.cli.add import app as add_app
6
4
  from pyarch.cli.generate import app as generate_app
5
+ from pyarch.cli.info import show_info
7
6
  from pyarch.cli.init import init_project
8
7
 
9
-
10
8
  app = typer.Typer(
11
9
  name="pyarch",
12
10
  help="Generate and extend Layered FastAPI projects.",
@@ -14,7 +12,9 @@ app = typer.Typer(
14
12
  )
15
13
 
16
14
  app.command("init", help="Create a new Layered FastAPI project.")(init_project)
17
- app.command("info", help="Show information from the current project's manifest.")(show_info)
15
+ app.command("info", help="Show information from the current project's manifest.")(
16
+ show_info
17
+ )
18
18
 
19
19
  app.add_typer(
20
20
  generate_app,
@@ -27,7 +27,3 @@ app.add_typer(
27
27
  name="add",
28
28
  help="Add project integrations.",
29
29
  )
30
-
31
-
32
-
33
-
@@ -5,7 +5,6 @@ from typing import Never, TypeVar
5
5
  import typer
6
6
  from rich.console import Console
7
7
 
8
-
9
8
  console = Console()
10
9
  ResultT = TypeVar("ResultT")
11
10
 
@@ -5,7 +5,6 @@ import typer
5
5
  from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.services.create_module import create_module
7
7
 
8
-
9
8
  app = typer.Typer(no_args_is_help=True)
10
9
 
11
10
 
@@ -27,8 +26,7 @@ def generate_module(
27
26
  )
28
27
 
29
28
  console.print(
30
- f"[green]Created module[/green] [bold]{module_name}[/bold] "
31
- f"in {project_root}"
29
+ f"[green]Created module[/green] [bold]{module_name}[/bold] in {project_root}"
32
30
  )
33
31
  for file_path in created_files:
34
32
  console.print(f" [dim]{file_path.relative_to(project_root)}[/dim]")
@@ -1,10 +1,9 @@
1
1
  import typer
2
-
3
2
  from rich.table import Table
3
+
4
4
  from pyarch.cli.common import console, execute_or_exit
5
5
  from pyarch.config.manifest import load_current_manifest
6
6
 
7
-
8
7
  app = typer.Typer(no_args_is_help=True)
9
8
 
10
9
 
@@ -28,5 +27,3 @@ def show_info() -> None:
28
27
  ", ".join(manifest.state.integrations) or "none",
29
28
  )
30
29
  console.print(table)
31
-
32
-
@@ -6,7 +6,6 @@ from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.config.models import DatabaseEngine
7
7
  from pyarch.services.create_project import create_project
8
8
 
9
-
10
9
  app = typer.Typer(no_args_is_help=True)
11
10
 
12
11
 
@@ -29,10 +28,7 @@ def init_project(
29
28
  """Create a new Layered FastAPI project."""
30
29
 
31
30
  console.print(
32
- f"Creating [bold]{project_name}[/bold] "
33
- f"with [cyan]{database.value}[/cyan]..."
34
- )
35
- project_dir = execute_or_exit(
36
- lambda: create_project(project_name, database)
31
+ f"Creating [bold]{project_name}[/bold] with [cyan]{database.value}[/cyan]..."
37
32
  )
33
+ project_dir = execute_or_exit(lambda: create_project(project_name, database))
38
34
  console.print(f"[bold green]Project created:[/bold green] {project_dir}")
@@ -15,7 +15,6 @@ from pyarch.config.models import (
15
15
  ProjectState,
16
16
  )
17
17
 
18
-
19
18
  MANIFEST_NAME = "pyarch.toml"
20
19
  SCHEMA_VERSION = 1
21
20
 
@@ -23,10 +22,12 @@ SCHEMA_VERSION = 1
23
22
  class ManifestError(ValueError):
24
23
  pass
25
24
 
25
+
26
26
  def load_current_manifest():
27
27
  project_root = find_project_root()
28
28
  return project_root, load_manifest(project_root)
29
29
 
30
+
30
31
  def create_manifest(
31
32
  project_dir: Path,
32
33
  project_name: str,
@@ -44,7 +45,9 @@ def create_manifest(
44
45
 
45
46
 
46
47
  def find_project_root(start: Path | None = None) -> Path:
48
+
47
49
  current = (start or Path.cwd()).resolve()
50
+
48
51
  if current.is_file():
49
52
  current = current.parent
50
53
 
@@ -58,7 +61,9 @@ def find_project_root(start: Path | None = None) -> Path:
58
61
 
59
62
 
60
63
  def load_manifest(project_dir: Path) -> ProjectManifest:
64
+
61
65
  manifest_path = project_dir / MANIFEST_NAME
66
+
62
67
  if not manifest_path.is_file():
63
68
  raise FileNotFoundError(f"Manifest does not exist: {manifest_path}")
64
69
 
@@ -109,6 +114,7 @@ def load_manifest(project_dir: Path) -> ProjectManifest:
109
114
 
110
115
 
111
116
  def save_manifest(project_dir: Path, manifest: ProjectManifest) -> Path:
117
+
112
118
  manifest_path = project_dir / MANIFEST_NAME
113
119
  temporary_path = manifest_path.with_suffix(".toml.tmp")
114
120
 
@@ -153,8 +159,6 @@ def require_table(raw: dict[str, Any], key: str) -> dict[str, Any]:
153
159
 
154
160
  def require_string_list(data: dict[str, Any], key: str) -> list[str]:
155
161
  value = data[key]
156
- if not isinstance(value, list) or not all(
157
- isinstance(item, str) for item in value
158
- ):
162
+ if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
159
163
  raise ManifestError(f"{key!r} must be an array of strings")
160
164
  return list(value)
@@ -1,6 +1,5 @@
1
1
  from pathlib import Path
2
2
 
3
-
4
3
  BASE_GITIGNORE_ENTRIES = (
5
4
  ".env",
6
5
  ".env.*",
@@ -32,7 +31,9 @@ def ensure_gitignore_entries(
32
31
  entries: tuple[str, ...],
33
32
  ) -> Path:
34
33
  gitignore_path = project_dir / ".gitignore"
35
- content = gitignore_path.read_text(encoding="utf-8") if gitignore_path.exists() else ""
34
+ content = (
35
+ gitignore_path.read_text(encoding="utf-8") if gitignore_path.exists() else ""
36
+ )
36
37
  lines = content.splitlines()
37
38
  existing_entries = {line.strip() for line in lines}
38
39
 
@@ -2,7 +2,6 @@ from pathlib import Path
2
2
 
3
3
  from jinja2 import Environment, FileSystemLoader, StrictUndefined
4
4
 
5
-
6
5
  TEMPLATES_DIR = Path(__file__).resolve().parents[2] / "templates"
7
6
 
8
7
  environment = Environment(
@@ -18,7 +18,6 @@ from pyarch.generators.common.gitignore import (
18
18
  from pyarch.generators.common.renderer import create_file_from_template
19
19
  from pyarch.generators.module.layered import ensure_layered_project, register_model
20
20
 
21
-
22
21
  AUTH_INTEGRATION_NAME = "auth"
23
22
  AUTH_ENV_MARKER = "# PyArch auth integration"
24
23
  AUTH_ENV_BLOCK = f"""
@@ -41,10 +40,10 @@ AUTH_RUNTIME_DEPENDENCIES = (
41
40
  def create_auth_integration(
42
41
  project_dir: Path,
43
42
  database: DatabaseEngine | str,
44
- ) -> tuple[Path, ...]:
45
- database = DatabaseEngine(database)
46
-
47
- app_path = project_dir / "app"
43
+ ) -> tuple[Path, ...]:
44
+ database = DatabaseEngine(database)
45
+
46
+ app_path = project_dir / "app"
48
47
  auth_path = app_path / "auth"
49
48
  models_init = app_path / "models" / "__init__.py"
50
49
  main_router = app_path / "api" / "v1" / "router.py"
@@ -16,9 +16,10 @@ def create_layered_module(
16
16
  database: DatabaseEngine | str = DatabaseEngine.POSTGRES,
17
17
  *,
18
18
  protected: bool = False,
19
- ) -> tuple[Path, ...]:
20
- database = DatabaseEngine(database)
21
-
19
+ ) -> tuple[Path, ...]:
20
+
21
+ database = DatabaseEngine(database)
22
+
22
23
  module_name = normalize_module_name(module_name)
23
24
  model_name = to_pascal_case(module_name)
24
25
  resource_name = pluralize_identifier(module_name)
@@ -29,7 +30,7 @@ def create_layered_module(
29
30
 
30
31
  ensure_layered_project(models_init, main_router)
31
32
 
32
- targets = (
33
+ targets = (
33
34
  (
34
35
  "layered/module/module_model.py.j2",
35
36
  app_path / "models" / f"{module_name}.py",
@@ -46,23 +47,23 @@ def create_layered_module(
46
47
  "layered/module/module_service.py.j2",
47
48
  app_path / "services" / f"{module_name}.py",
48
49
  ),
49
- (
50
- (
51
- "layered/module/module_router_protected.py.j2"
52
- if protected
53
- else "layered/module/module_router.py.j2"
54
- ),
55
- app_path / "api" / "v1" / f"{module_name}.py",
56
- ),
57
- (
58
- (
59
- "layered/module/module_test_protected.py.j2"
60
- if protected
61
- else "layered/module/module_test.py.j2"
62
- ),
63
- project_dir / "tests" / f"test_{module_name}.py",
64
- ),
65
- )
50
+ (
51
+ (
52
+ "layered/module/module_router_protected.py.j2"
53
+ if protected
54
+ else "layered/module/module_router.py.j2"
55
+ ),
56
+ app_path / "api" / "v1" / f"{module_name}.py",
57
+ ),
58
+ (
59
+ (
60
+ "layered/module/module_test_protected.py.j2"
61
+ if protected
62
+ else "layered/module/module_test.py.j2"
63
+ ),
64
+ project_dir / "tests" / f"test_{module_name}.py",
65
+ ),
66
+ )
66
67
  existing_targets = [path for _, path in targets if path.exists()]
67
68
  if existing_targets:
68
69
  existing = ", ".join(str(path) for path in existing_targets)
@@ -73,7 +74,7 @@ def create_layered_module(
73
74
  "model_name": model_name,
74
75
  "resource_name": resource_name,
75
76
  "table_name": resource_name,
76
- "id_type": "int",
77
+ "id_type": "int",
77
78
  }
78
79
 
79
80
  created_files = tuple(
@@ -82,8 +83,8 @@ def create_layered_module(
82
83
  )
83
84
 
84
85
  register_model(models_init, module_name, model_name)
85
- register_router(main_router, module_name, resource_name)
86
- return created_files
86
+ register_router(main_router, module_name, resource_name)
87
+ return created_files
87
88
 
88
89
 
89
90
  def normalize_module_name(module_name: str) -> str:
@@ -151,17 +152,17 @@ def register_model(
151
152
  )
152
153
 
153
154
 
154
- def register_router(main_router: Path, module_name: str, resource_name: str) -> None:
155
- insert_line_before_marker(
156
- main_router,
157
- "# pyarch:router-imports",
158
- f"from app.api.v1 import {module_name}",
159
- )
160
- insert_line_before_marker(
161
- main_router,
162
- "# pyarch:router-includes",
163
- (
164
- f'v1_router.include_router({module_name}.router, '
165
- f'prefix="/{resource_name}", tags=["{resource_name}"])'
166
- ),
167
- )
155
+ def register_router(main_router: Path, module_name: str, resource_name: str) -> None:
156
+ insert_line_before_marker(
157
+ main_router,
158
+ "# pyarch:router-imports",
159
+ f"from app.api.v1 import {module_name}",
160
+ )
161
+ insert_line_before_marker(
162
+ main_router,
163
+ "# pyarch:router-includes",
164
+ (
165
+ f"v1_router.include_router({module_name}.router, "
166
+ f'prefix="/{resource_name}", tags=["{resource_name}"])'
167
+ ),
168
+ )
@@ -1,3 +1,7 @@
1
+ """
2
+ Create a base for any project.
3
+ """
4
+
1
5
  from pathlib import Path
2
6
 
3
7
  from pyarch.generators.common.commands import run_command
@@ -10,30 +14,40 @@ from pyarch.generators.common.renderer import create_file_from_template
10
14
 
11
15
 
12
16
  def create_base_dir(project_name: str) -> Path:
13
- """
14
- create base dir with all README.md, gitignore, ,env.example and etc files
15
- """
16
17
 
17
18
  project_dir = Path.cwd() / project_name
18
19
 
19
20
  # creating base uv app
20
21
  run_command("uv", "init", project_name)
22
+
23
+ # .gitignote
21
24
  ensure_gitignore_entries(project_dir, "base", BASE_GITIGNORE_ENTRIES)
22
25
 
23
- # files shared by all supported architectures
24
- create_empty_file(project_dir / "Dockerfile")
25
- create_empty_file(project_dir / "docker-compose.yml")
26
+ # docker
27
+ create_dockerfile(project_dir)
28
+ create_docker_compose(project_dir)
26
29
 
30
+ # docs
27
31
  create_docs_dir(project_dir)
28
32
 
29
33
  return project_dir
30
34
 
31
35
 
32
- def create_docs_dir(project_dir: Path) -> None:
33
- """
34
- creating files where you can describe your project, rbac roles etc.
35
- """
36
+ def create_dockerfile(project_dir: Path) -> None:
37
+ create_file_from_template(
38
+ template_name="project/base/Dockerfile.j2",
39
+ output_path=project_dir / "Dockerfile"
40
+ )
36
41
 
42
+
43
+ def create_docker_compose(project_dir: Path) -> None:
44
+ create_file_from_template(
45
+ template_name="project/base/docker-compose.yml.j2",
46
+ output_path=project_dir / "docker-compose.yml"
47
+ )
48
+
49
+
50
+ def create_docs_dir(project_dir: Path) -> None:
37
51
  docs_dir = create_empty_dir(project_dir / "docs")
38
52
  create_empty_file(docs_dir / "RBAC.md")
39
53
  create_empty_file(docs_dir / "ARCHITECTURE.md")
@@ -5,7 +5,6 @@ from pyarch.generators.common.commands import run_command
5
5
  from pyarch.generators.common.filesystem import create_module_path
6
6
  from pyarch.generators.common.renderer import create_file_from_template
7
7
 
8
-
9
8
  COMMON_RUNTIME_DEPENDENCIES = (
10
9
  "fastapi",
11
10
  "uvicorn",
@@ -55,17 +54,17 @@ def install_dependencies(
55
54
  project_dir: Path,
56
55
  database: DatabaseEngine,
57
56
  ) -> None:
57
+
58
58
  runtime_dependencies = list(COMMON_RUNTIME_DEPENDENCIES)
59
-
60
59
  runtime_dependencies.extend(SQL_RUNTIME_DEPENDENCIES)
61
-
62
60
  runtime_dependencies.extend(DATABASE_RUNTIME_DEPENDENCIES[database])
63
- run_command("uv", "add", *runtime_dependencies, cwd=project_dir)
64
61
 
62
+ run_command("uv", "add", *runtime_dependencies, cwd=project_dir)
65
63
  run_command("uv", "add", "--dev", *COMMON_DEV_DEPENDENCIES, cwd=project_dir)
66
64
 
67
65
 
68
66
  def create_layered_arch(app_path: Path) -> None:
67
+
69
68
  """Create packages and shared files for a Layered application."""
70
69
 
71
70
  create_file_from_template(
@@ -83,6 +82,7 @@ def create_layered_arch(app_path: Path) -> None:
83
82
  "repositories",
84
83
  "dependencies",
85
84
  )
85
+
86
86
  for layer in base_layers:
87
87
  create_module_path(app_path / layer)
88
88
 
@@ -119,6 +119,7 @@ def create_database_setup(
119
119
  app_path: Path,
120
120
  database: DatabaseEngine,
121
121
  ) -> None:
122
+
122
123
  create_file_from_template(
123
124
  template_name="layered/config.py.j2",
124
125
  output_path=app_path / "core" / "config.py",
@@ -139,6 +140,7 @@ def create_test_setup(
139
140
  project_dir: Path,
140
141
  database: DatabaseEngine,
141
142
  ) -> None:
143
+
142
144
  create_module_path(project_dir / "tests")
143
145
 
144
146
  create_file_from_template(
@@ -148,7 +150,9 @@ def create_test_setup(
148
150
 
149
151
 
150
152
  def initialize_alembic(project_dir: Path) -> None:
153
+
151
154
  run_command("uv", "run", "alembic", "init", "alembic", cwd=project_dir)
155
+
152
156
  create_file_from_template(
153
157
  template_name="layered/alembic_env.py.j2",
154
158
  output_path=project_dir / "alembic" / "env.py",
@@ -19,9 +19,7 @@ def add_integration(
19
19
  raise ValueError("Integration name cannot be empty")
20
20
 
21
21
  if normalized_name in manifest.state.integrations:
22
- raise FileExistsError(
23
- f"Integration {normalized_name!r} is already registered"
24
- )
22
+ raise FileExistsError(f"Integration {normalized_name!r} is already registered")
25
23
 
26
24
  if normalized_name != AUTH_INTEGRATION_NAME:
27
25
  raise NotImplementedError(
@@ -19,9 +19,7 @@ def create_module(
19
19
  normalized_name = normalize_module_name(module_name)
20
20
 
21
21
  if normalized_name in manifest.state.modules:
22
- raise FileExistsError(
23
- f"Module {normalized_name!r} is already registered"
24
- )
22
+ raise FileExistsError(f"Module {normalized_name!r} is already registered")
25
23
 
26
24
  if manifest.project.architecture is not Architecture.LAYERED:
27
25
  raise ValueError(