Skip to content

Commit bd6e326

Browse files
authored
Add plugins system (#69)
1 parent c5f9991 commit bd6e326

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

copier.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ project_type:
1111
- "mcp-server"
1212
- "agent"
1313

14+
plugins:
15+
type: str
16+
help: Which plugins would you like to enable?
17+
multiselect: true
18+
default: |
19+
{% if project_type in ["api-monolith", "api-microservice", "agent"] %}
20+
- "sqladmin"
21+
{% else %}
22+
[]
23+
{% endif %}
24+
choices: |
25+
{% if project_type in ["api-monolith", "api-microservice", "agent"] %}
26+
SQLAdmin [interface for database management]: sqladmin
27+
{% else %}
28+
{}
29+
{% endif %}
30+
when: "{{ project_type in ['api-monolith', 'api-microservice', 'agent'] }}"
31+
1432
project_name:
1533
type: str
1634
help: What is your project name?
@@ -64,7 +82,6 @@ _exclude:
6482
- "{{ '*/app/database.py' if project_type not in ['api-monolith', 'api-microservice', 'agent'] else '' }}"
6583
- "{{ '*/app/mappings.py' if project_type not in ['api-monolith', 'api-microservice', 'agent'] else '' }}"
6684
- "{{ '*/app/utils/mappings_meta.py' if project_type not in ['api-monolith', 'api-microservice', 'agent'] else '' }}"
67-
- "{{ '*/app/integrations/sqladmin' if project_type not in ['api-monolith', 'api-microservice', 'agent'] else '' }}"
6885

6986
- "{{ '*/README_api.md' if project_type not in ['api-monolith', 'api-microservice'] else '' }}"
7087
- "{{ 'Dockerfile' if project_type not in ['api-monolith', 'api-microservice'] else '' }}"
@@ -75,13 +92,13 @@ _exclude:
7592
- "{{ '*/app/repositories.py' if project_type != 'api-monolith' else '' }}"
7693
- "{{ '*/app/services.py' if project_type != 'api-monolith' else '' }}"
7794

78-
- "{{ '*/app/models' if project_type != 'api-microservice' else '' }}"
7995
- "{{ '*/app/schemas/user.py' if project_type != 'api-microservice' else '' }}"
8096
- "{{ '*/app/services' if project_type != 'api-microservice' else '' }}"
8197
- "{{ '*/app/repositories' if project_type != 'api-microservice' else '' }}"
8298
- "{{ '*/app/api/routes/v1/user.py' if project_type != 'api-microservice' else '' }}"
8399

84100
- "{{ '*/app/api' if project_type not in ['api-microservice', 'agent'] else '' }}"
101+
- "{{ '*/app/models' if project_type not in ['api-microservice', 'agent'] else '' }}"
85102
- "{{ '*/app/schemas' if project_type not in ['api-microservice', 'agent'] else '' }}"
86103

87104
- "{{ '*/examples' if project_type != 'agent' else '' }}"
@@ -94,6 +111,8 @@ _exclude:
94111
- "{{ '*/README_mcp-server.md' if project_type != 'mcp-server' else '' }}"
95112
- "{{ '*/app/mcp' if project_type != 'mcp-server' else '' }}"
96113

114+
- "{{ '*/app/integrations/sqladmin' if 'sqladmin' not in plugins else '' }}"
115+
97116
_tasks:
98117
- command: uvx python -c "import shutil; shutil.move('{{project_name}}/README_{{project_type}}.md', '{{project_name}}/README.md')"
99118
when: "{{ project_type in ['agent', 'mcp-server'] }}"

{{project_name}}/app/integrations/sqladmin/views/user.py renamed to {{project_name}}/app/integrations/sqladmin/views/user.py.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from app.integrations.sqladmin.base_view import BaseAdminView
2+
{% if project_type == "api-monolith" %}
23
from app.user.models import User
34
from app.user.schemas import UserCreate, UserUpdate
5+
{% else %}
6+
from app.models.user import User
7+
from app.schemas.user import UserCreate, UserUpdate
8+
{% endif %}
49

510

611
class UserAdminView(

{{project_name}}/app/main.py.jinja

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,37 @@ from logging import INFO, basicConfig
33
{% if project_type in ["api-monolith", "api-microservice"] %}
44
from fastapi import FastAPI, Request
55
from fastapi.exceptions import RequestValidationError
6-
from sqladmin import Admin
76
{% elif project_type == "agent" %}
87
from fastapi import FastAPI
98
{% elif project_type == "mcp-server" %}
109
from fastmcp import FastMCP
1110
{% endif %}
11+
{% if "sqladmin" in plugins %}
12+
from sqladmin import Admin
13+
{% endif %}
1214

1315
from app.config import settings
1416
{% if project_type in ["api-monolith", "api-microservice"] %}
1517
from app.utils.exceptions import handle_exception
16-
from app.database import engine
17-
from app.integrations.sqladmin.views import add_admin_views
1818
{% endif %}
1919
{% if project_type in ["api-monolith", "api-microservice", "agent"] %}
2020
from app.api import head_router
2121
{% elif project_type == "mcp-server" %}
2222
from app.mcp import mcp_router
2323
{% endif %}
24+
{% if "sqladmin" in plugins %}
25+
from app.database import engine
26+
from app.integrations.sqladmin.views import add_admin_views
27+
{% endif %}
2428

2529
basicConfig(level=INFO, format="[%(asctime)s - %(name)s] (%(levelname)s) %(message)s")
2630

2731
{% if project_type in ["api-monolith", "api-microservice", "agent"] %}
2832
api = FastAPI(title=settings.api_name)
33+
{% if "sqladmin" in plugins %}
2934
admin = Admin(app=api, engine=engine)
3035
add_admin_views(admin)
36+
{% endif %}
3137

3238

3339
@api.get("/")

{{project_name}}/app/schemas/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class UserRead(BaseModel):
2323
class UserUpdate(BaseModel):
2424
username: str | None = None
2525
email: EmailStr | None = None
26-
updated_at: datetime | None = Field(default_factory=lambda: datetime.now(timezone.utc), init=False)
26+
updated_at: datetime | None = Field(default_factory=lambda: datetime.now(timezone.utc))

{{project_name}}/pyproject.toml.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies = [
2222
{% if project_type in ["api-monolith", "api-microservice", "agent"] %}
2323
"fastapi>=0.116.1",
2424
"fastapi-cli>=0.0.8",
25+
{% endif %}
26+
{% if "sqladmin" in plugins %}
2527
"sqladmin[full]>=0.21.0",
2628
{% endif %}
2729
]

0 commit comments

Comments
 (0)