diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b31c0a1..9186c4a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 2b8e14e..bc5e4c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ __pycache__ cairocffi/_ffi*.py -cairocffi/_generated *.egg *.egg-info /build diff --git a/cairocffi/__init__.py b/cairocffi/__init__.py index 1852bb3..c687cba 100644 --- a/cairocffi/__init__.py +++ b/cairocffi/__init__.py @@ -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: diff --git a/cairocffi/ffi_build.py b/cairocffi/ffi.py similarity index 83% rename from cairocffi/ffi_build.py rename to cairocffi/ffi.py index 77e5729..104c7ea 100644 --- a/cairocffi/ffi_build.py +++ b/cairocffi/ffi.py @@ -1,6 +1,6 @@ """ - cairocffi.ffi_build - ~~~~~~~~~~~~~~~~~~~ + cairocffi.ffi + ~~~~~~~~~~~~~ Build the cffi bindings @@ -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: @@ -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; @@ -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() diff --git a/cairocffi/pixbuf.py b/cairocffi/pixbuf.py index 1ed208b..2a24cb2 100644 --- a/cairocffi/pixbuf.py +++ b/cairocffi/pixbuf.py @@ -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'] diff --git a/pyproject.toml b/pyproject.toml index c54e6b2..8bf3af6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/utils/build.py b/utils/build.py deleted file mode 100644 index 8d04e3e..0000000 --- a/utils/build.py +++ /dev/null @@ -1,32 +0,0 @@ -import importlib.util -import subprocess -import sys -from pathlib import Path - -from setuptools import build_meta -from setuptools.build_meta import * # noqa - -folder = Path(__file__).parent.parent / 'cairocffi' - - -def build_sdist(*args, **kwargs): - (folder / '_generated' / 'ffi.py').unlink(missing_ok=True) - (folder / '_generated' / 'ffi_pixbuf.py').unlink(missing_ok=True) - return build_meta.build_sdist(*args, **kwargs) - - -def build_wheel(*args, **kwargs): - # Try to install xcffib for XCB support - try: - pip = Path(sys.executable).parent / 'pip' - subprocess.run([str(pip), 'install', 'xcffib']) - except Exception: - pass - - spec = importlib.util.spec_from_file_location( - 'ffi_build', folder / 'ffi_build.py') - module = importlib.util.module_from_spec(spec) - sys.modules['ffi_build'] = module - spec.loader.exec_module(module) - module.compile() - return build_meta.build_wheel(*args, **kwargs)