Switched to PDM for package management

This commit is contained in:
Donkie
2023-07-10 01:13:40 +02:00
parent 5c9b0c3fac
commit a6ac5982cc
6 changed files with 1123 additions and 32 deletions

View File

@@ -29,8 +29,10 @@ jobs:
- uses: actions/setup-python@v4 - uses: actions/setup-python@v4
with: with:
python-version: "3.9" python-version: "3.9"
- run: pip install -e . - run: pip install pip setuptools wheel
- run: spoolman_docs - run: pip install pdm
- run: pdm sync
- run: pdm run docs
- name: Setup Pages - name: Setup Pages
uses: actions/configure-pages@v3 uses: actions/configure-pages@v3
- name: Upload artifact - name: Upload artifact

1
.gitignore vendored
View File

@@ -202,3 +202,4 @@ $RECYCLE.BIN/
.vscode/ .vscode/
data/ data/
.pdm-python

View File

@@ -15,22 +15,24 @@ RUN apk add --no-cache g++ python3-dev libpq-dev libstdc++
RUN adduser -D app RUN adduser -D app
USER app USER app
RUN python -m venv /home/app/.venv ENV PATH="/home/app/.local/bin:${PATH}"
ENV PATH="/home/app/.venv/bin:${PATH}" # Install PDM
RUN pip install pip setuptools wheel\
&& pip install pdm
# Copy and install dependencies
COPY --chown=app:app pyproject.toml /home/app/spoolman/
COPY --chown=app:app pdm.lock /home/app/spoolman/
WORKDIR /home/app/spoolman
RUN pdm sync --prod
# Copy and install app # Copy and install app
COPY --chown=app:app migrations /home/app/spoolman/migrations COPY --chown=app:app migrations /home/app/spoolman/migrations
COPY --chown=app:app spoolman /home/app/spoolman/spoolman COPY --chown=app:app spoolman /home/app/spoolman/spoolman
COPY --chown=app:app pyproject.toml /home/app/spoolman/
COPY --chown=app:app requirements.txt /home/app/spoolman/
COPY --chown=app:app alembic.ini /home/app/spoolman/ COPY --chown=app:app alembic.ini /home/app/spoolman/
COPY --chown=app:app README.md /home/app/spoolman/ COPY --chown=app:app README.md /home/app/spoolman/
WORKDIR /home/app/spoolman
RUN --mount=target=/home/app/.cache,type=cache,sharing=locked,uid=1000,gid=1000 \
pip install -e .
FROM python:3.11-alpine as python-runner FROM python:3.11-alpine as python-runner
LABEL org.opencontainers.image.source=https://github.com/Donkie/Spoolman LABEL org.opencontainers.image.source=https://github.com/Donkie/Spoolman
@@ -47,12 +49,11 @@ USER app
COPY --chown=app:app --from=client-builder /client/dist /home/app/spoolman/client/dist COPY --chown=app:app --from=client-builder /client/dist /home/app/spoolman/client/dist
# Copy built app # Copy built app
COPY --chown=app:app --from=python-builder /home/app/.venv /home/app/.venv
COPY --chown=app:app --from=python-builder /home/app/spoolman /home/app/spoolman COPY --chown=app:app --from=python-builder /home/app/spoolman /home/app/spoolman
WORKDIR /home/app/spoolman WORKDIR /home/app/spoolman
ENV PATH="/home/app/.venv/bin:${PATH}" ENV PATH="/home/app/spoolman/.venv/bin:${PATH}"
ENV PYTHONPATH="/home/app/spoolman:${PYTHONPATH}" ENV PYTHONPATH="/home/app/spoolman:${PYTHONPATH}"
# Run command # Run command

1059
pdm.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,44 @@
[project] [project]
name = "Spoolman" name = "spoolman"
version = "0.7.0"
description = "A web service that keeps track of 3D printing spools." description = "A web service that keeps track of 3D printing spools."
version = "0.1.0" authors = [
{name = "Donkie", email = "daniel.cf.hultgren@gmail.com"},
]
dependencies = [
"uvicorn~=0.22.0",
"httptools>=0.5.0; platform_machine != \"armv7l\"",
"uvloop!=0.15.0,!=0.15.1,>=0.14.0; platform_machine != \"armv7l\" and sys_platform != \"win32\" and (sys_platform != \"cygwin\" and platform_python_implementation != \"PyPy\")",
"fastapi~=0.99",
"SQLAlchemy[aiomysql,aiosqlite,asyncio,postgresql_asyncpg]~=2.0",
"pydantic~=1.10",
"platformdirs~=3.8",
"alembic~=1.11",
"scheduler~=0.8",
"sqlalchemy-cockroachdb~=2.0",
"asyncpg~=0.27",
"psycopg2-binary~=2.9",
"setuptools~=68.0",
]
requires-python = ">=3.9" requires-python = ">=3.9"
readme = "README.md"
license = {text = "MIT"} license = {text = "MIT"}
dynamic = ["dependencies"]
[tool.setuptools.dynamic] [tool.pdm.dev-dependencies]
dependencies = {file = ["requirements.txt"]} dev = [
"ruff==0.0.277",
"black~=23.3",
"pre-commit~=3.3",
"pytest~=7.3",
"pytest-asyncio~=0.21",
"httpx~=0.24",
]
[tool.setuptools.packages.find] [build-system]
where = [""] requires = ["pdm-backend"]
exclude = ["client"] build-backend = "pdm.backend"
[tool.pdm.scripts]
docs = {call = "spoolman.docs:generate_docs"}
[tool.ruff] [tool.ruff]
select = ["ALL"] select = ["ALL"]
@@ -27,10 +53,3 @@ target-version = "py39"
[tool.black] [tool.black]
line-length = 120 line-length = 120
target-version = ['py39'] target-version = ['py39']
[build-system]
requires = ["setuptools>=67.0"]
build-backend = "setuptools.build_meta"
[project.scripts]
spoolman_docs = "spoolman.docs:generate_docs"

View File

@@ -1,7 +1,7 @@
"""Functions for generating documentation.""" """Functions for generating documentation."""
import json import json
from contextlib import suppress import logging
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
@@ -10,6 +10,10 @@ from fastapi.openapi.utils import get_openapi
from spoolman.api.v1.router import app as v1_app from spoolman.api.v1.router import app as v1_app
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler()) # Print all log messages to stdout
def generate_openapi(app: FastAPI) -> dict[str, Any]: def generate_openapi(app: FastAPI) -> dict[str, Any]:
"""Generate the OpenAPI document for a specific FastAPI app. """Generate the OpenAPI document for a specific FastAPI app.
@@ -36,12 +40,15 @@ def generate_openapi(app: FastAPI) -> dict[str, Any]:
def generate_docs() -> None: def generate_docs() -> None:
"""Generate documentation for this service in the docs/ directory.""" """Generate documentation for this service in the docs/ directory."""
with suppress(FileExistsError): target_dir = Path("docs")
Path("docs").mkdir()
logger.info('Generating documentation to "%s"...', target_dir.resolve())
target_dir.mkdir(parents=True, exist_ok=True)
spec = json.dumps(generate_openapi(v1_app)) spec = json.dumps(generate_openapi(v1_app))
with Path("docs", "index.html").open("w") as f: with target_dir.joinpath("index.html").open("w") as f:
f.write( f.write(
f""" f"""
<!DOCTYPE html> <!DOCTYPE html>
@@ -64,3 +71,5 @@ def generate_docs() -> None:
</body> </body>
</html>""", </html>""",
) )
logger.info("Documentation generated successfully.")