Skip to content
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

Use ABI-level in-line CFFI mode #216

Merged
merged 9 commits into from
Jun 12, 2023
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ jobs:
name: ${{ matrix.os }} - ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ['3.11']
include:
- os: ubuntu-latest
python-version: '3.7'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -37,9 +39,7 @@ jobs:
- name: Install tests’ requirements
run: python -m pip install -e .[test]
- name: Launch tests
run: |
python cairocffi/ffi_build.py
python -m pytest
run: python -m pytest
- name: Check coding style
run: python -m flake8
- name: Check imports order
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__pycache__
cairocffi/_ffi*.py
cairocffi/_generated
*.egg
*.egg-info
/build
Expand Down
2 changes: 1 addition & 1 deletion cairocffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ctypes.util import find_library

from . import constants
from ._generated.ffi import ffi
from .ffi import ffi

VERSION = __version__ = '1.5.1'
# supported version of cairo, used to be pycairo version too:
Expand Down
26 changes: 3 additions & 23 deletions cairocffi/ffi_build.py → cairocffi/ffi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
cairocffi.ffi_build
~~~~~~~~~~~~~~~~~~~
cairocffi.ffi
~~~~~~~~~~~~~

Build the cffi bindings

Expand All @@ -21,18 +21,13 @@
constants = module_from_spec(constants_spec)
constants_spec.loader.exec_module(constants)

# Create an empty _generated folder if needed
generated = Path(__file__).parent / '_generated'
generated.mkdir(exist_ok=True)

# Primary cffi definitions
ffi = FFI()
ffi.set_source('cairocffi._generated.ffi', None)
ffi.cdef(constants._CAIRO_HEADERS)

# include xcffib cffi definitions for cairo xcb support
try:
from xcffib.ffi_build import ffi as xcb_ffi
from xcffib.ffi import ffi as xcb_ffi
except ImportError:
pass
else:
Expand All @@ -41,7 +36,6 @@

# gdk pixbuf cffi definitions
ffi_pixbuf = FFI()
ffi_pixbuf.set_source('cairocffi._generated.ffi_pixbuf', None)
ffi_pixbuf.include(ffi)
ffi_pixbuf.cdef('''
typedef unsigned long gsize;
Expand Down Expand Up @@ -102,17 +96,3 @@
void g_error_free (GError *error);
void g_type_init (void);
''')


def compile():
ffi.compile()
ffi_path = generated / 'ffi.py'
ffi_path.write_text('# flake8: noqa\n' + ffi_path.read_text())
ffi_pixbuf.compile()
ffi_pixbuf_path = generated / 'ffi_pixbuf.py'
ffi_pixbuf_path.write_text(
'# flake8: noqa\n' + ffi_pixbuf_path.read_text())


if __name__ == '__main__':
compile()
2 changes: 1 addition & 1 deletion cairocffi/pixbuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from io import BytesIO

from . import Context, ImageSurface, constants, dlopen
from ._generated.ffi_pixbuf import ffi
from .ffi import ffi_pixbuf as ffi

__all__ = ['decode_to_image_surface']

Expand Down
86 changes: 46 additions & 40 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
[build-system]
requires = ["setuptools >= 61.0.0", "cffi >= 1.1.0"]
build-backend = "build"
backend-path = ["utils"]
requires = ['flit_core >=3.2,<4']
build-backend = 'flit_core.buildapi'

[project]
name = "cairocffi"
description = "cffi-based cairo bindings for Python"
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.7"
license = {file = "LICENSE"}
keywords = ["cairo", "cffi", "binding"]
authors = [
{name = "Simon Sapin", email = "contact@courtbouillon.org"}
name = 'cairocffi'
description = 'cffi-based cairo bindings for Python'
keywords = ['cairo', 'cffi', 'binding']
authors = [{name = 'Simon Sapin', email = 'contact@courtbouillon.org'}]
maintainers = [{name = 'CourtBouillon', email = 'contact@courtbouillon.org'}]
requires-python = '>=3.7'
readme = {file = 'README.rst', content-type = 'text/x-rst'}
license = {file = 'LICENSE'}
dependencies = [
'cffi >= 1.1.0',
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Multimedia :: Graphics"
]
dependencies = [
"cffi >= 1.1.0"
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Multimedia :: Graphics',
]
dynamic = ["version"]
dynamic = ['version']

[tool.setuptools.dynamic]
version = {attr = "cairocffi.VERSION"}
version = {attr = 'cairocffi.VERSION'}

[project.urls]
Documentation = "https://cairocffi.readthedocs.io/"
Code = "https://github.com/Kozea/cairocffi/"
Issues = "https://github.com/Kozea/cairocffi/issues"
Donation = "https://opencollective.com/courtbouillon"
Documentation = 'https://cairocffi.readthedocs.io/'
Code = 'https://github.com/Kozea/cairocffi/'
Issues = 'https://github.com/Kozea/cairocffi/issues'
Changelog = 'https://cairocffi.readthedocs.io/en/stable/changelog.html'
Donation = 'https://opencollective.com/courtbouillon'

[project.optional-dependencies]
doc = ["sphinx", "sphinx_rtd_theme"]
test = ["pytest", "flake8", "isort", "numpy", "pikepdf"]
xcb = ["xcffib >= 0.3.2"]
doc = ['sphinx', 'sphinx_rtd_theme']
test = ['pytest', 'flake8', 'isort', 'numpy', 'pikepdf']
xcb = ['xcffib >= 1.4.0']

[tool.flit.sdist]
exclude = ['.*']

[tool.coverage.run]
branch = true
include = ['cairocffi/*']

[tool.pytest.ini_options]
addopts = "--pyargs cairocffi"
norecursedirs = "build dist .cache .eggs .git"
[tool.coverage.report]
exclude_lines = ['pragma: no cover', 'def __repr__', 'raise NotImplementedError']
omit = ['.*']

[tool.isort]
default_section = "FIRSTPARTY"
default_section = 'FIRSTPARTY'
multi_line_output = 4
32 changes: 0 additions & 32 deletions utils/build.py

This file was deleted.