Skip to content

Pep 518 via uv #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions .github/workflows/ci.yml → .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
name: CI
name: Run Matrix Tests on MacOS
on: [push, pull_request, workflow_dispatch]
jobs:
tests:
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
name: "Python ${{ matrix.python-version }} on MacOs"
runs-on: "macos-latest"
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "pypy-3.9"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.9", "3.10", "3.11", "pypy-3.9"]
steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"

- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@main

- name: Setup Cairo
run: |
brew install cairo pkg-config

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}

- name: "Cache for wikipedia flags"
uses: actions/cache@v3
env:
Expand All @@ -31,14 +44,5 @@ jobs:
with:
path: "tests/samples/W3C_SVG_12_TinyTestSuite"
key: "w3c-svg12-tinytestsuite-${{ matrix.python-version }}-${{ matrix.os }}"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -VV
python -m site
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade virtualenv tox tox-gh-actions
- name: "Run tox targets for ${{ matrix.python-version }}"
run: "python -m tox"
- name: "Run tests for ${{ matrix.python-version }}"
run: uv run --python ${{ matrix.python-version }} pytest
45 changes: 45 additions & 0 deletions .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run Matrix Tests on Ubuntu
on: [push, pull_request, workflow_dispatch]
jobs:
tests:
name: "Python ${{ matrix.python-version }} on Ubuntu"
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "pypy-3.9"]
steps:
- uses: "actions/checkout@v4"

- name: Setup Cairo
run: |
sudo apt-get update && \
sudo apt-get install -y libcairo2-dev libffi-dev pkg-config

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}

- name: "Cache for wikipedia flags"
uses: actions/cache@v3
env:
cache-name: "cache-wikipedia-flags"
with:
path: "tests/samples/wikipedia/flags"
key: "wikipedia-flags-${{ matrix.python-version }}-${{ matrix.os }}"
- name: "Cache for wikipedia symbols"
uses: actions/cache@v3
env:
cache-name: "cache-wikipedia-symbols"
with:
path: "tests/samples/wikipedia/symbols"
key: "wikipedia-symbols-${{ matrix.python-version }}-${{ matrix.os }}"
- name: "Cache for w3c svg12 tinytestsuite"
uses: actions/cache@v3
env:
cache-name: "cache-w3c-svg12-tinytestsuite"
with:
path: "tests/samples/W3C_SVG_12_TinyTestSuite"
key: "w3c-svg12-tinytestsuite-${{ matrix.python-version }}-${{ matrix.os }}"
- name: "Run tests for ${{ matrix.python-version }}"
run: uv run --python ${{ matrix.python-version }} pytest
55 changes: 55 additions & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Run Matrix Tests on Windows
on: [push, pull_request, workflow_dispatch]
jobs:
tests:
name: "Python Tests for Windows"
runs-on: "windows-latest"
# strategy:
# matrix:
# python-version: ["3.9", "3.10", "3.11", "pypy-3.9"]
steps:
- uses: "actions/checkout@v4"


- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install gvsbuild
run: uv tool install gvsbuild

- name: Install gtk3 (includes Cairo)
run: gvsbuild build gtk3

- name: "Cache for wikipedia flags"
uses: actions/cache@v3
env:
cache-name: "cache-wikipedia-flags"
with:
path: "tests/samples/wikipedia/flags"
key: "wikipedia-flags-" # just use single cache for windows
- name: "Cache for wikipedia symbols"
uses: actions/cache@v3
env:
cache-name: "cache-wikipedia-symbols"
with:
path: "tests/samples/wikipedia/symbols"
key: "wikipedia-symbols-"
- name: "Cache for w3c svg12 tinytestsuite"
uses: actions/cache@v3
env:
cache-name: "cache-w3c-svg12-tinytestsuite"
with:
path: "tests/samples/W3C_SVG_12_TinyTestSuite"
key: "w3c-svg12-tinytestsuite-"
- name: "Run tests for 3.9"
run: uv run --python 3.9 pytest
- name: "Run tests for 3.10"
run: uv run --python 3.10 pytest
- name: "Run tests for 3.11"
run: uv run --python 3.11 pytest
- name: "Run tests for 3.13"
run: uv run --python 3.13 pytest
- name: "Run tests for pypy-3.9"
run: uv run --python pypy-3.9 pytest
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: After Prepare
run: python3 -m pip install --upgrade --user flake8
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is the (preliminary) list of contributors in no particular order:
- Sebastian Wehrmann
- Robin Becker
- Tom Turner
- Danny Elfanbaum

If you are not listed here, but feel like you should be, please contact
the maintainers. If you create a pull request, feel free to add your
Expand Down
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,16 @@ This will install a Python package named ``svglib`` in the
tool named ``svg2pdf`` in your ``bin`` directory, e.g. in
``/usr/local/bin``.

Development and Testing
-------

To develop ``svglib``, install `uv`_ and run ``uv sync`` to install the
requirements and development dependencies. To run the test suite with
``pytest``, run: ``uv run pytest``.

.. _uv: https://docs.astral.sh/uv/

Testing
Distribution Testing
-------

The ``svglib`` tarball distribution contains a PyTest_ test suite
Expand Down
68 changes: 68 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[project]
name = "svglib"
version = "1.6.0"
description = "A pure-Python library for reading and converting SVG"
readme = "README.rst"
authors = [
{ name = "Dinu Gherman", email = "[email protected]" },
]
keywords = [
"SVG",
"PDF",
"reportlab",
"conversion",
"graphics",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Documentation",
"Topic :: Utilities",
"Topic :: Printing",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup :: XML",
]
license = "LGPL-3.0-or-later"
license-files = [
"LICENSE.txt",
]
requires-python = ">=3.8"
dependencies = [
"cssselect2>=0.2.0",
"lxml>=6.0.0",
"reportlab>=4.4.3",
"rlpycairo>=0.4.0",
"tinycss2>=0.6.0",
]

[project.urls]
Homepage = "https://github.com/deeplook/svglib"

[project.scripts]
svg2pdf = "svglib:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"pytest>=8.3.5",
"pytest-runner>=6.0.1",
]

[tool.flake8]
max-line-length = "99"
63 changes: 0 additions & 63 deletions setup.cfg

This file was deleted.

13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

10 changes: 2 additions & 8 deletions scripts/svg2pdf → src/svglib/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""A simple converter from SVG to PDF.

For further information please check the file README.txt!
Expand Down Expand Up @@ -46,16 +45,15 @@ def svg2pdf(path, outputPat=None):


# command-line usage stuff

def _main():
def main():
ext = 'pdf'
ext_caps = ext.upper()
args = dict(
prog=basename(sys.argv[0]),
version=svglib.__version__,
author=svglib.__author__,
license=svglib.__license__,
copyleft_year=svglib.__date__[:svglib.__date__.find('-')],
copyleft_year=str(datetime.now().year),
ts_pattern="{{dirname}}/out-"\
"{{now.hour}}-{{now.minute}}-{{now.second}}-"\
"%(base)s",
Expand Down Expand Up @@ -123,7 +121,3 @@ def _main():
paths = [a for a in args.input if exists(a)]
for path in paths:
svg2pdf(path, outputPat=args.output)


if __name__ == '__main__':
_main()
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions svglib/svglib.py → src/svglib/svglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import shutil
from io import BytesIO
from collections import defaultdict, namedtuple
from importlib.metadata import version
from PIL import Image as PILImage

from reportlab.pdfbase.pdfmetrics import stringWidth
Expand Down Expand Up @@ -71,10 +72,12 @@ def find_font(font_name, weight='normal', style='normal'):
return _fonts_find_font(font_name, weight, style)


__version__ = '1.5.1'
try:
__version__ = version("svglib")
except ImportError: # pragma: no cover
__version__ = "unknown"
__license__ = 'LGPL 3'
__author__ = 'Dinu Gherman'
__date__ = '2023-01-07'

XML_NS = 'http://www.w3.org/XML/1998/namespace'

Expand Down
File renamed without changes.
Empty file added tests/__init__.py
Empty file.
Loading
Loading