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

@@ -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.")