ohmyapi 0.2.7__py3-none-any.whl → 0.3.0__py3-none-any.whl
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.
- ohmyapi/__init__.py +1 -1
- ohmyapi/cli.py +7 -0
- ohmyapi/core/scaffolding.py +22 -0
- ohmyapi/core/templates/docker/Dockerfile +30 -0
- ohmyapi/core/templates/docker/docker-compose.yml +7 -0
- ohmyapi/core/templates/project/pyproject.toml.j2 +1 -1
- ohmyapi/db/model/model.py +17 -0
- {ohmyapi-0.2.7.dist-info → ohmyapi-0.3.0.dist-info}/METADATA +1 -1
- {ohmyapi-0.2.7.dist-info → ohmyapi-0.3.0.dist-info}/RECORD +11 -9
- {ohmyapi-0.2.7.dist-info → ohmyapi-0.3.0.dist-info}/WHEEL +0 -0
- {ohmyapi-0.2.7.dist-info → ohmyapi-0.3.0.dist-info}/entry_points.txt +0 -0
ohmyapi/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__VERSION__ = "0.
|
1
|
+
__VERSION__ = "0.3.0"
|
ohmyapi/cli.py
CHANGED
@@ -27,6 +27,12 @@ def startapp(app_name: str, root: str = "."):
|
|
27
27
|
scaffolding.startapp(app_name, root)
|
28
28
|
|
29
29
|
|
30
|
+
@app.command()
|
31
|
+
def dockerize(root: str = "."):
|
32
|
+
"""Create template Dockerfile and docker-compose.yml."""
|
33
|
+
scaffolding.copy_static("docker", root)
|
34
|
+
|
35
|
+
|
30
36
|
@app.command()
|
31
37
|
def serve(root: str = ".", host="127.0.0.1", port=8000):
|
32
38
|
"""
|
@@ -41,6 +47,7 @@ def serve(root: str = ".", host="127.0.0.1", port=8000):
|
|
41
47
|
|
42
48
|
@app.command()
|
43
49
|
def shell(root: str = "."):
|
50
|
+
"""An interactive shell with your loaded project runtime."""
|
44
51
|
project_path = Path(root).resolve()
|
45
52
|
project = runtime.Project(project_path)
|
46
53
|
|
ohmyapi/core/scaffolding.py
CHANGED
@@ -2,6 +2,8 @@ from pathlib import Path
|
|
2
2
|
|
3
3
|
from jinja2 import Environment, FileSystemLoader
|
4
4
|
|
5
|
+
import shutil
|
6
|
+
|
5
7
|
# Base templates directory
|
6
8
|
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
7
9
|
env = Environment(loader=FileSystemLoader(str(TEMPLATE_DIR)))
|
@@ -53,6 +55,26 @@ def render_template_dir(
|
|
53
55
|
render_template_file(template_dir / template_rel_path, context, output_path)
|
54
56
|
|
55
57
|
|
58
|
+
def copy_static(dir_name: str, target_dir: Path):
|
59
|
+
"""Statically copy all files from {TEMPLATE_DIR}/{dir_name} to target_dir."""
|
60
|
+
template_dir = TEMPLATE_DIR / dir_name
|
61
|
+
target_dir = Path(target_dir)
|
62
|
+
if not template_dir.exists():
|
63
|
+
print(f"no templates found under: {dir_name}")
|
64
|
+
return
|
65
|
+
|
66
|
+
for root, _, files in template_dir.walk():
|
67
|
+
root_path = Path(root)
|
68
|
+
for file in files:
|
69
|
+
src = root_path / file
|
70
|
+
dst = target_dir / file
|
71
|
+
if dst.exists():
|
72
|
+
print(f"⛔ File exists, skipping: {dst}")
|
73
|
+
continue
|
74
|
+
shutil.copy(src, ".")
|
75
|
+
print(f"✅ Templates created successfully.")
|
76
|
+
print(f"🔧 Next, run `docker compose up -d --build`")
|
77
|
+
|
56
78
|
def startproject(name: str):
|
57
79
|
"""Create a new project: flat structure, all project templates go into <name>/"""
|
58
80
|
target_dir = Path(name).resolve()
|
@@ -0,0 +1,30 @@
|
|
1
|
+
FROM python:3.13-alpine
|
2
|
+
|
3
|
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
4
|
+
PYTHONUNBUFFERED=1 \
|
5
|
+
POETRY_HOME="/opt/poetry" \
|
6
|
+
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
7
|
+
POETRY_NO_INTERACTION=1
|
8
|
+
|
9
|
+
RUN apk add --no-cache \
|
10
|
+
build-base \
|
11
|
+
curl \
|
12
|
+
git \
|
13
|
+
bash \
|
14
|
+
libffi-dev \
|
15
|
+
openssl-dev \
|
16
|
+
python3-dev \
|
17
|
+
musl-dev
|
18
|
+
|
19
|
+
RUN curl -sSL https://install.python-poetry.org | python3 -
|
20
|
+
ENV PATH="$POETRY_HOME/bin:$PATH"
|
21
|
+
|
22
|
+
WORKDIR /app
|
23
|
+
COPY pyproject.toml poetry.lock* /app/
|
24
|
+
RUN poetry lock
|
25
|
+
RUN poetry install
|
26
|
+
COPY . /app
|
27
|
+
|
28
|
+
EXPOSE 8000
|
29
|
+
|
30
|
+
CMD ["poetry", "run", "ohmyapi", "serve", "--host", "0.0.0.0"]
|
ohmyapi/db/model/model.py
CHANGED
@@ -34,6 +34,23 @@ class ModelMeta(type(TortoiseModel)):
|
|
34
34
|
# Grab the Schema class for further processing.
|
35
35
|
schema_opts = attrs.get("Schema", None)
|
36
36
|
|
37
|
+
# Create or get the inner Meta class
|
38
|
+
meta = attrs.get("Meta", type("Meta", (), {}))
|
39
|
+
|
40
|
+
# Infer app name from module if not explicitly set
|
41
|
+
if not hasattr(meta, "app"):
|
42
|
+
module = attrs.get("__module__", "")
|
43
|
+
module_parts = module.split(".")
|
44
|
+
if module_parts[-1] == "models":
|
45
|
+
inferred_app = module_parts[-2]
|
46
|
+
else:
|
47
|
+
inferred_app = module_parts[-1]
|
48
|
+
meta.app = inferred_app
|
49
|
+
|
50
|
+
# Prefix table name if not explicitly set
|
51
|
+
if not hasattr(meta, "table"):
|
52
|
+
meta.table = f"{meta.app}_{name.lower()}"
|
53
|
+
|
37
54
|
# Let Tortoise's Metaclass do it's thing.
|
38
55
|
new_cls = super().__new__(mcls, name, bases, attrs)
|
39
56
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ohmyapi
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0
|
4
4
|
Summary: Django-flavored scaffolding and management layer around FastAPI, Pydantic, TortoiseORM and Aerich migrations
|
5
5
|
License-Expression: MIT
|
6
6
|
Keywords: fastapi,tortoise,orm,pydantic,async,web-framework
|
@@ -1,4 +1,4 @@
|
|
1
|
-
ohmyapi/__init__.py,sha256=
|
1
|
+
ohmyapi/__init__.py,sha256=xUikczf2zVhNudbYPv2C7Skuyh3Dmj8U4zwP6o06PkA,22
|
2
2
|
ohmyapi/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
|
3
3
|
ohmyapi/builtin/auth/__init__.py,sha256=vOVCSJX8BALzs8h5ZW9507bjoscP37bncMjdMmBXcMM,42
|
4
4
|
ohmyapi/builtin/auth/models.py,sha256=8az4TKdC6PUha3_HyslKinDT2-yAN-aBoYUQcjxm7Js,1728
|
@@ -7,22 +7,24 @@ ohmyapi/builtin/auth/routes.py,sha256=r887BWea20vinX88QBuxGzQc9BrIi-LqyStM0V1cl1
|
|
7
7
|
ohmyapi/builtin/demo/__init__.py,sha256=44Yo3mYmlKSKEwVp6O9urr-C_3qDQzCYLMn6B9i6wew,29
|
8
8
|
ohmyapi/builtin/demo/models.py,sha256=r06rfuhPJaI2fYsQ24L1JCOd67f2GQNfGnkgKAptOX8,1404
|
9
9
|
ohmyapi/builtin/demo/routes.py,sha256=1VTlEttrez6Qnhrz_9sTA-emtfXem0s0BkPVcLvg3k0,1801
|
10
|
-
ohmyapi/cli.py,sha256=
|
10
|
+
ohmyapi/cli.py,sha256=gHiPWN3pkrrIJ69WFBHt0BTRNVI-YSJD7VhtqQRwKuc,4447
|
11
11
|
ohmyapi/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
12
|
ohmyapi/core/runtime.py,sha256=pNfFRk7sFX8FePX6cnb4H7kLh5CauNnA_gmc0rsWIh8,12287
|
13
|
-
ohmyapi/core/scaffolding.py,sha256=
|
13
|
+
ohmyapi/core/scaffolding.py,sha256=1KF67aBvd08xjDhIXhI-nDhClJAw2TB3tYVLiMmeYOk,3426
|
14
14
|
ohmyapi/core/templates/app/__init__.py.j2,sha256=QwVIQVUGZVhdH1d4NrvL7NTsK4-T4cihzYs8UVX2dt4,43
|
15
15
|
ohmyapi/core/templates/app/models.py.j2,sha256=_3w-vFJ5fgsmncsCv34k_wyCMF78jufbSSglns4gbb0,119
|
16
16
|
ohmyapi/core/templates/app/routes.py.j2,sha256=SxLz_wvakusj5txbXToZyNq6ZmcamSwNjVrI0MNPRl0,1037
|
17
|
+
ohmyapi/core/templates/docker/Dockerfile,sha256=4-QgqK6h9sR7hYKGUvRife6GpLTm7EOzYupr54B3qUY,596
|
18
|
+
ohmyapi/core/templates/docker/docker-compose.yml,sha256=Jr344DALp28_w9d9O-HIuQgwaacIHabyFyvBuOQ-PeQ,102
|
17
19
|
ohmyapi/core/templates/project/README.md.j2,sha256=SjR4JIrg-8XRE-UntUDwiw8jDpYitD_UjwoKkYJ7GLw,22
|
18
|
-
ohmyapi/core/templates/project/pyproject.toml.j2,sha256=
|
20
|
+
ohmyapi/core/templates/project/pyproject.toml.j2,sha256=D3d5yv2317owH3tFYN6klMavt74gTqqhDsHe0jhqUeA,521
|
19
21
|
ohmyapi/core/templates/project/settings.py.j2,sha256=So6w1OiL_jU-FyeT8IHueDjGNuEoSkYhabhHpne2fUU,140
|
20
22
|
ohmyapi/db/__init__.py,sha256=5QKUycxnN83DOUD_Etoee9tEOYjnZ74deqrSOOx_MiQ,204
|
21
23
|
ohmyapi/db/exceptions.py,sha256=vb4IIUoeYAY6sK42zRtjMy-39IFVi_Qb6mWySTY0jYw,34
|
22
24
|
ohmyapi/db/model/__init__.py,sha256=k3StTNuKatpwZo_Z5JBFa-927eJrzibFE8U4SA82asc,32
|
23
|
-
ohmyapi/db/model/model.py,sha256=
|
25
|
+
ohmyapi/db/model/model.py,sha256=ErBXCGqq_cIsZIZVIg38VqeGfJ4heN-NCBBgyhrsVH0,3407
|
24
26
|
ohmyapi/router.py,sha256=5g0U59glu4hxxnIoTSFzb2S2offkOT3eE39aprzVxwo,83
|
25
|
-
ohmyapi-0.
|
26
|
-
ohmyapi-0.
|
27
|
-
ohmyapi-0.
|
28
|
-
ohmyapi-0.
|
27
|
+
ohmyapi-0.3.0.dist-info/METADATA,sha256=mWzPL_t7-qXaU3QqiXD7gaU5VvqCilv8-Dpkg2ApDFw,2575
|
28
|
+
ohmyapi-0.3.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
29
|
+
ohmyapi-0.3.0.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
|
30
|
+
ohmyapi-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|