Skip to content

Commit 1dce658

Browse files
committed
Expanded many docstrings, sanitized pyproject.toml
1 parent 4c69f45 commit 1dce658

File tree

14 files changed

+1038
-220
lines changed

14 files changed

+1038
-220
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
ChangeLog
44
=========
55

6+
1.6.0 (2025-09-25)
7+
------------------
8+
- Replace setup.py with pyproject.toml, rework GitHub workflows (#405).
9+
- Drop support for Python 3.8.
10+
- Modernize codebase, added type annotations, expanded docstrings, etc.
11+
- Add a Makefile.
12+
- Add publishing workflows.
13+
- Remove dunder constants and use importlib.metadata to get the version number.
14+
615
1.5.1 (2023-01-07)
716
------------------
817
- Final fix to conversion from shorthand quadratic to cubic bézier (#372).

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ hooks: ## Run all pre-commit hooks.
3838
uv run pre-commit run --all-files
3939

4040
.PHONY: all
41-
all: install lint hooks test ## Run all checks (install, lint, test).
41+
all: lint typecheck hooks test ## Run all checks (lint, typecheck, hookstest).
4242

4343
.PHONY: dist
4444
dist: ## Build the package for distribution.

README.rst

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ the system command-line. Here is the output from ``svg2pdf -h``::
149149
issues/pull requests:
150150
https://github.com/deeplook/svglib
151151

152-
Copyleft by Dinu Gherman, 2008-2021 (LGPL 3):
153-
http://www.gnu.org/copyleft/gpl.html
154-
155152

156153
Dependencies
157154
------------
@@ -235,19 +232,20 @@ in the ``tests`` directory. There, in ``tests/README.rst``, you can
235232
also read more about testing. You can run the testsuite e.g. like
236233
shown in the following lines on the command-line::
237234

238-
$ tar xfz svglib-<version>.tar.gz
239-
$ cd svglib-<version>
240-
$ PYTHONPATH=. py.test
241-
======================== test session starts =========================
242-
platform darwin -- Python 3.7.3, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
243-
rootdir: /Users/dinu/repos/github/deeplook/svglib, inifile:
244-
plugins: cov-2.4.0
245-
collected 36 items
235+
$ make test
236+
========================= test session starts =========================
237+
platform darwin -- Python 3.9.6, pytest-8.4.2, pluggy-1.6.0
238+
rootdir: /Users/dinu/dev/svglib
239+
configfile: pyproject.toml
240+
plugins: cov-7.0.0
241+
collected 115 items
246242

247-
tests/test_basic.py ............................
248-
tests/test_samples.py .s.s.s.s
243+
tests/test_basic.py ............................................ [ 43%]
244+
.................. [ 53%]
245+
tests/test_fonts.py ............s.....................s..... [ 88%]
246+
tests/test_samples.py .s.s.s.s..... [100%]
249247

250-
=============== 32 passed, 4 skipped in 49.18 seconds ================
248+
============== 109 passed, 6 skipped, 1 warning in 33.32s =============
251249

252250

253251
Bug reports

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ name = "svglib"
33
version = "1.6.0"
44
description = "A pure-Python library for reading and converting SVG"
55
readme = "README.rst"
6-
authors = [
7-
{ name = "Dinu Gherman", email = "gherman@darwin.in-berlin.de" },
8-
]
6+
authors = [{ name = "Dinu Gherman" }]
97
keywords = [
108
"SVG",
119
"PDF",
@@ -62,12 +60,13 @@ build-backend = "hatchling.build"
6260

6361
[project.optional-dependencies]
6462
dev = [
63+
"mypy>=1.18.1",
6564
"pre-commit>=4.3.0",
6665
"pytest>=8.3.5",
6766
"pytest-cov>=7.0.0",
6867
"pytest-runner>=6.0.1",
6968
"ruff>=0.13.0",
70-
"tox>=4.0.0",
69+
"tox>=4.30.2",
7170
]
7271

7372
[tool.ruff]
@@ -82,9 +81,3 @@ select = [
8281

8382
[tool.ruff.format]
8483
quote-style = "double"
85-
86-
[dependency-groups]
87-
dev = [
88-
"mypy>=1.18.1",
89-
"tox>=4.30.2",
90-
]

src/svglib/__init__.py

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,76 @@
1-
"""A simple converter from SVG to PDF.
1+
"""A tool for converting SVG to PDF.
22
3-
For further information please check the file README.txt!
3+
This module provides a high-level function for converting SVG files to PDF format
4+
using the ReportLab graphics library. It also serves as the main entry point for
5+
the svglib package.
6+
7+
The module includes:
8+
- svg2pdf(): Convert SVG files to PDF programmatically.
9+
- main(): Command-line interface for SVG to PDF conversion.
10+
- Automatic file path handling and output generation.
411
"""
512

613
import argparse
714
import sys
815
import textwrap
916
from datetime import datetime
17+
from importlib.metadata import PackageNotFoundError, version
1018
from os.path import basename, dirname, exists, splitext
1119
from typing import Optional
1220

1321
from reportlab.graphics import renderPDF
1422

1523
from svglib import svglib
1624

25+
try:
26+
__version__ = version("svglib")
27+
except PackageNotFoundError:
28+
__version__ = "unknown"
29+
1730

1831
def svg2pdf(path: str, outputPat: Optional[str] = None) -> None:
19-
"Convert an SVG file to a PDF one."
32+
"""Convert an SVG file to PDF format.
33+
34+
High-level function that loads an SVG file, converts it to a ReportLab drawing,
35+
and saves it as a PDF file. Supports both .svg and .svgz (compressed SVG) files.
36+
37+
Args:
38+
path: Path to the input SVG file (.svg or .svgz extension).
39+
outputPat: Optional output path pattern. Supports placeholders:
40+
- %(dirname)s: Directory of input file
41+
- %(basename)s: Full filename with extension
42+
- %(base)s: Filename without extension
43+
- %(ext)s: File extension
44+
- %(now)s: Current datetime object
45+
- %(format)s: Output format (always "pdf")
46+
Also supports {name} format strings.
47+
48+
Returns:
49+
None. The PDF file is written to disk.
50+
51+
Raises:
52+
FileNotFoundError: If the input SVG file does not exist.
53+
Exception: If SVG parsing or PDF generation fails.
54+
OSError: If the output directory is not writable.
55+
56+
Examples:
57+
Basic conversion:
58+
>>> svg2pdf("input.svg") # Creates "input.pdf"
59+
60+
Custom output location:
61+
>>> svg2pdf("input.svg", "output.pdf")
62+
63+
Using placeholders:
64+
>>> svg2pdf("path/file.svg", "%(dirname)s/converted/%(base)s.pdf")
65+
# Creates "path/converted/file.pdf"
66+
67+
Timestamped output:
68+
>>> svg2pdf("file.svg", "backup/%(now.year)s-%(now.month)s-%(base)s.pdf")
69+
70+
Note:
71+
The function will overwrite existing PDF files without warning.
72+
For compressed SVG files (.svgz), the file is automatically decompressed.
73+
"""
2074

2175
# derive output filename from output pattern
2276
file_info = {
@@ -52,10 +106,7 @@ def main() -> None:
52106
ext_caps = ext.upper()
53107
format_args = dict(
54108
prog=basename(sys.argv[0]),
55-
version=svglib.__version__,
56-
author=svglib.__author__,
57-
license=svglib.__license__,
58-
copyleft_year=str(datetime.now().year),
109+
version=__version__,
59110
ts_pattern="{{dirname}}/out-"
60111
"{{now.hour}}-{{now.minute}}-{{now.second}}-"
61112
"%(base)s",
@@ -87,9 +138,7 @@ def main() -> None:
87138
88139
issues/pull requests:
89140
https://github.com/deeplook/svglib
90-
91-
Copyleft by {author}, 2008-{copyleft_year} ({license}):
92-
https://www.gnu.org/licenses/lgpl-3.0.html""".format(**format_args)
141+
""".format(**format_args)
93142
)
94143
p = argparse.ArgumentParser(
95144
description=desc,
@@ -119,7 +168,7 @@ def main() -> None:
119168
args = p.parse_args()
120169

121170
if args.version:
122-
print(svglib.__version__)
171+
print(__version__)
123172
sys.exit()
124173

125174
if not args.input:

0 commit comments

Comments
 (0)