Skip to content

Commit 22e807a

Browse files
authored
Merge pull request #27 from pythonnz/danny-pydantic
Use pydantic models for configuration
2 parents 55ed6ef + f31954b commit 22e807a

File tree

28 files changed

+1447
-1088
lines changed

28 files changed

+1447
-1088
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ repos:
4343
rev: v3.3.4
4444
hooks:
4545
- id: pylint
46-
args:
47-
- --rcfile=.pylintrc
4846
additional_dependencies:
4947
- "cairosvg"
5048
- "click"
5149
- "jinja2"
50+
- "pydantic"
5251
- "pypdf"
5352
- "pytest"
54-
- "pyyaml"
53+
- "ruamel.yaml"

.pylintrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/custom_locations/other_pages/custom_page.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
title: "Custom Location Example"
22
description: "This page uses custom directory structure"
33
template:
4-
# If you just wrote this directly it would be relative to the templates directory
5-
# We want it to be relative to the config file, so use path:
64
path: "../other_templates/custom_page.svg.j2"
75
detailed_description:
86
"This example demonstrates custom file locations in pdfbaker. The template file is in

examples/custom_processing/bake.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import urllib.request
66
from datetime import datetime
77

8-
from pdfbaker.document import PDFBakerDocument
8+
from pdfbaker.document import Document
99
from pdfbaker.errors import PDFBakerError
1010
from pdfbaker.processing import wordwrap
1111

1212

13-
def process_document(document: PDFBakerDocument) -> None:
13+
def process_document(document: Document) -> None:
1414
"""Process document with live XKCD comic."""
1515
try:
1616
# Fetch latest XKCD
@@ -29,7 +29,7 @@ def process_document(document: PDFBakerDocument) -> None:
2929
wrapped_alt_text = wordwrap(data["alt"], max_chars=60)
3030

3131
# Update config/template context with XKCD info
32-
document.config["xkcd"] = {
32+
document.config.xkcd = {
3333
"title": data["title"],
3434
"alt_text": data["alt"],
3535
"alt_text_lines": wrapped_alt_text,

examples/examples.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ documents:
22
- minimal
33
- regular
44
- variants
5-
- ./custom_locations/your_directory
5+
- path: ./custom_locations/your_directory
6+
name: custom_locations
67
- custom_processing
8+
9+
custom_stuff:
10+
- year: 2025
11+
- nested:
12+
- anything: really

examples/variants/config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ variants:
55
- name: Basic
66
style:
77
color: "#3498db"
8-
features:
9-
- "Single page layout"
10-
- "Basic styling"
8+
features:
9+
- "Single page layout"
10+
- "Basic styling"
1111
- name: Premium
1212
style:
1313
color: "#2ecc71"
14-
features:
15-
- "Single page layout"
16-
- "Premium styling"
17-
- "Custom colors"
14+
features:
15+
- "Single page layout"
16+
- "Premium styling"
17+
- "Custom colors"
1818
- name: Enterprise
1919
style:
2020
color: "#e74c3c"
21-
features:
22-
- "Single page layout"
23-
- "Enterprise styling"
24-
- "Custom colors"
25-
- "Priority support"
21+
features:
22+
- "Single page layout"
23+
- "Enterprise styling"
24+
- "Custom colors"
25+
- "Priority support"

examples/variants/templates/main.svg.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Features -->
1010
<text x="20" y="90" font-family="Arial" font-size="10" font-weight="bold" fill="#333">Features:</text>
11-
{% for feature in variant.style.features %}
11+
{% for feature in variant.features %}
1212
<text x="30" y="{{ 110 + loop.index0 * 16 }}" font-family="Arial" font-size="9" fill="#333">• {{ feature }}</text>
1313
{% endfor %}
1414
</svg>

pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ dependencies = [
99
"cairosvg",
1010
"click",
1111
"jinja2",
12+
"pydantic",
1213
"pypdf",
13-
"pyyaml",
14+
"ruamel.yaml",
1415
]
1516
readme = "README.md"
1617
requires-python = ">= 3.11"
@@ -42,3 +43,17 @@ addopts = "-v --cov=pdfbaker --cov-report=term-missing"
4243

4344
[tool.coverage.run]
4445
source = ["pdfbaker"]
46+
47+
[tool.pylint.main]
48+
py-version = "3.11"
49+
ignore-paths = ["tests/"]
50+
init-hook = "import sys; sys.path.insert(0, 'src')"
51+
52+
[tool.pylint.messages_control]
53+
disable = ["W0511"] # Disable TODO/FIXME warnings
54+
55+
[tool.pylint.reports]
56+
msg-template = "{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
57+
output-format = "colorized"
58+
reports = "no"
59+
score = "no"

src/pdfbaker/__main__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import click
88

99
from pdfbaker import __version__
10-
from pdfbaker.baker import PDFBaker, PDFBakerOptions
10+
from pdfbaker.baker import Baker, BakerOptions
1111
from pdfbaker.errors import DocumentNotFoundError, PDFBakerError
1212

1313
logger = logging.getLogger(__name__)
@@ -54,20 +54,20 @@ def bake(
5454
keep_build = True
5555

5656
try:
57-
options = PDFBakerOptions(
57+
options = BakerOptions(
5858
quiet=quiet,
5959
verbose=verbose,
6060
trace=trace,
6161
keep_build=keep_build,
6262
)
63-
baker = PDFBaker(config_file, options=options)
63+
baker = Baker(config_file, options=options)
6464
success = baker.bake(document_names=documents if documents else None)
6565
sys.exit(0 if success else 1)
6666
except DocumentNotFoundError as exc:
67-
logger.error(str(exc))
67+
logger.error("❌ %s", str(exc))
6868
sys.exit(2)
6969
except PDFBakerError as exc:
70-
logger.error(str(exc))
70+
logger.error("❌ %s", str(exc))
7171
sys.exit(1)
7272

7373

0 commit comments

Comments
 (0)