Switched to PDM for package management
This commit is contained in:
6
.github/workflows/apidocs.yml
vendored
6
.github/workflows/apidocs.yml
vendored
@@ -29,8 +29,10 @@ jobs:
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.9"
|
||||
- run: pip install -e .
|
||||
- run: spoolman_docs
|
||||
- run: pip install pip setuptools wheel
|
||||
- run: pip install pdm
|
||||
- run: pdm sync
|
||||
- run: pdm run docs
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v3
|
||||
- name: Upload artifact
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -202,3 +202,4 @@ $RECYCLE.BIN/
|
||||
.vscode/
|
||||
|
||||
data/
|
||||
.pdm-python
|
||||
|
||||
21
Dockerfile
21
Dockerfile
@@ -15,22 +15,24 @@ RUN apk add --no-cache g++ python3-dev libpq-dev libstdc++
|
||||
RUN adduser -D 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 --chown=app:app migrations /home/app/spoolman/migrations
|
||||
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 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
|
||||
|
||||
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 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
|
||||
|
||||
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}"
|
||||
|
||||
# Run command
|
||||
|
||||
@@ -1,18 +1,44 @@
|
||||
[project]
|
||||
name = "Spoolman"
|
||||
name = "spoolman"
|
||||
version = "0.7.0"
|
||||
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"
|
||||
readme = "README.md"
|
||||
license = {text = "MIT"}
|
||||
dynamic = ["dependencies"]
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
dependencies = {file = ["requirements.txt"]}
|
||||
[tool.pdm.dev-dependencies]
|
||||
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]
|
||||
where = [""]
|
||||
exclude = ["client"]
|
||||
[build-system]
|
||||
requires = ["pdm-backend"]
|
||||
build-backend = "pdm.backend"
|
||||
|
||||
[tool.pdm.scripts]
|
||||
docs = {call = "spoolman.docs:generate_docs"}
|
||||
|
||||
[tool.ruff]
|
||||
select = ["ALL"]
|
||||
@@ -27,10 +53,3 @@ target-version = "py39"
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
target-version = ['py39']
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=67.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project.scripts]
|
||||
spoolman_docs = "spoolman.docs:generate_docs"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Functions for generating documentation."""
|
||||
|
||||
import json
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
from pathlib import Path
|
||||
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
|
||||
|
||||
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]:
|
||||
"""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:
|
||||
"""Generate documentation for this service in the docs/ directory."""
|
||||
with suppress(FileExistsError):
|
||||
Path("docs").mkdir()
|
||||
target_dir = Path("docs")
|
||||
|
||||
logger.info('Generating documentation to "%s"...', target_dir.resolve())
|
||||
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
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"""
|
||||
<!DOCTYPE html>
|
||||
@@ -64,3 +71,5 @@ def generate_docs() -> None:
|
||||
</body>
|
||||
</html>""",
|
||||
)
|
||||
|
||||
logger.info("Documentation generated successfully.")
|
||||
|
||||
Reference in New Issue
Block a user