refactor/type-hint-fixes #1
7 changed files with 36 additions and 11 deletions
|
@ -1,10 +1,14 @@
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
static-analysis:
|
static-analysis:
|
||||||
runs-on: runner-latest
|
runs-on: runner-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- uses: https://github.com/astral-sh/setup-uv@v3
|
||||||
- name: Linting
|
- name: Linting
|
||||||
run: pipx run pre-commit run ruff -a
|
run: pipx run pre-commit run ruff -a
|
||||||
- name: Format
|
- name: Format
|
||||||
|
@ -13,6 +17,11 @@ jobs:
|
||||||
run: pipx run pre-commit run check-yaml -a
|
run: pipx run pre-commit run check-yaml -a
|
||||||
- name: Validate shell scripts
|
- name: Validate shell scripts
|
||||||
run: pipx run pre-commit run shellcheck -a
|
run: pipx run pre-commit run shellcheck -a
|
||||||
|
- name: Check types
|
||||||
|
run: |
|
||||||
|
uv venv
|
||||||
|
uv pip install .
|
||||||
|
pipx run pre-commit run pyright -a
|
||||||
export-trace:
|
export-trace:
|
||||||
runs-on: runner-latest
|
runs-on: runner-latest
|
||||||
needs: [static-analysis]
|
needs: [static-analysis]
|
||||||
|
|
|
@ -13,3 +13,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
- repo: https://github.com/RobertCraigie/pyright-python
|
||||||
|
rev: v1.1.389
|
||||||
|
hooks:
|
||||||
|
- id: pyright
|
||||||
|
|
|
@ -13,7 +13,7 @@ def build_site(
|
||||||
*,
|
*,
|
||||||
client: DocumentClient,
|
client: DocumentClient,
|
||||||
renderer: DocumentRenderer,
|
renderer: DocumentRenderer,
|
||||||
destination_path: str | None = None,
|
destination_path: str | pathlib.Path | None = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Build HTML documents from data extracted from the given client, using
|
Build HTML documents from data extracted from the given client, using
|
||||||
|
@ -44,13 +44,15 @@ def build_site(
|
||||||
docs.extend(current_document.children)
|
docs.extend(current_document.children)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
current_path = current_document.path or ""
|
||||||
|
|
||||||
target_path = destination_path.joinpath(
|
target_path = destination_path.joinpath(
|
||||||
pathlib.Path(current_document.path).stem + ".html"
|
pathlib.Path(current_path).stem + ".html"
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(target_path, "w") as out:
|
with open(target_path, "w") as out:
|
||||||
rendered = renderer.render(
|
rendered = renderer.render(
|
||||||
current_metadata["template"],
|
str(current_metadata["template"]),
|
||||||
{
|
{
|
||||||
**current_metadata,
|
**current_metadata,
|
||||||
"site": site_metadata,
|
"site": site_metadata,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pydantic
|
import pydantic
|
||||||
|
|
||||||
|
import typing
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ class Document(pydantic.BaseModel, abc.ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def metadata(self) -> dict[str, str]:
|
def metadata(self) -> dict[str, object]:
|
||||||
"""Metadata associated with the document."""
|
"""Metadata associated with the document."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -47,4 +48,4 @@ class DocumentRenderer(abc.ABC):
|
||||||
"""Renders documents into HTML."""
|
"""Renders documents into HTML."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def render(self, template_path: str, content: dict[str, str]) -> str: ...
|
def render(self, template_path: str, content: dict[str, typing.Any]) -> str: ...
|
||||||
|
|
|
@ -22,7 +22,7 @@ class NextCloudDocument(Document):
|
||||||
type: str
|
type: str
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def _parsed_markdown(self) -> tuple[dict[str, str], str]:
|
def _parsed_markdown(self) -> tuple[dict[str, object], str]:
|
||||||
try:
|
try:
|
||||||
return frontmatter.parse(self.raw)
|
return frontmatter.parse(self.raw)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -30,7 +30,7 @@ class NextCloudDocument(Document):
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metadata(self) -> dict[str, str]:
|
def metadata(self) -> dict[str, object]:
|
||||||
return self._parsed_markdown[0]
|
return self._parsed_markdown[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -68,7 +68,10 @@ class NextCloudClient(DocumentClient, arbitrary_types_allowed=True):
|
||||||
root_document = NextCloudDocument(path=root_path, type="collection")
|
root_document = NextCloudDocument(path=root_path, type="collection")
|
||||||
|
|
||||||
for r in root_properties:
|
for r in root_properties:
|
||||||
doc_path = r.find("{DAV:}href").text
|
doc_path = r.find("{DAV:}href")
|
||||||
|
|
||||||
|
if doc_path is not None:
|
||||||
|
doc_path = doc_path.text
|
||||||
|
|
||||||
if doc_path == root_document.path:
|
if doc_path == root_document.path:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2,6 +2,8 @@ from .models import DocumentRenderer
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class JinjaDocumentRenderer(DocumentRenderer):
|
class JinjaDocumentRenderer(DocumentRenderer):
|
||||||
"""Renders documents using Jinja templates."""
|
"""Renders documents using Jinja templates."""
|
||||||
|
@ -12,7 +14,7 @@ class JinjaDocumentRenderer(DocumentRenderer):
|
||||||
loader=jinja2.FileSystemLoader(searchpath="./templates")
|
loader=jinja2.FileSystemLoader(searchpath="./templates")
|
||||||
)
|
)
|
||||||
|
|
||||||
def render(self, template_path: str, content: dict[str, str]) -> str:
|
def render(self, template_path: str, content: dict[str, typing.Any]) -> str:
|
||||||
t = self._environment.get_template(template_path)
|
t = self._environment.get_template(template_path)
|
||||||
|
|
||||||
return t.render(**content)
|
return t.render(**content)
|
||||||
|
|
|
@ -3,7 +3,7 @@ name = "blogue"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Basic static site generator that powers my blog."
|
description = "Basic static site generator that powers my blog."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"click>=8.1.7",
|
"click>=8.1.7",
|
||||||
"httpx>=0.27.2",
|
"httpx>=0.27.2",
|
||||||
|
@ -24,3 +24,7 @@ dev-dependencies = [
|
||||||
"pre-commit>=4.0.1",
|
"pre-commit>=4.0.1",
|
||||||
"ruff>=0.7.1",
|
"ruff>=0.7.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
venvPath = "."
|
||||||
|
venv = ".venv"
|
||||||
|
|
Loading…
Reference in a new issue