Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to use cffi 1.0 compilation mechanism
Create two ffi's for the module in ffi_build, one for the cairo library, importing the ffi from xcffib (if it can be imported) and adding the relevant cdefs, and another ffi for the gdk_pixbuf cdefs. Now, to run cairocffi from source will require running `python cairocffi/ffi_build.py` to compile the ffi objects, these are handled automatically when installing.
- Loading branch information
1 parent
138b63f
commit 31a5a0c
Showing
8 changed files
with
120 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.pyc | ||
__pycache__ | ||
cairocffi/_ffi*.py | ||
*.egg-info | ||
/dist | ||
/.tox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ python: | |
install: | ||
- "pip install xcffib" | ||
- "pip install ." | ||
- "python cairocffi/ffi_build.py" | ||
script: "py.test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include README.rst CHANGES LICENSE tox.ini .coveragerc | ||
recursive-include docs * | ||
prune docs/_build | ||
exclude cairocffi/_ffi*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# coding: utf8 | ||
""" | ||
cairocffi.ffi_build | ||
~~~~~~~~~~~~~~~~~~~ | ||
Build the cffi bindings | ||
:copyright: Copyright 2013 by Simon Sapin | ||
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
import os | ||
import sys | ||
from cffi import FFI | ||
|
||
# Path hack to import constants when this file is exec'd by setuptools | ||
this_file = os.path.abspath(__file__) | ||
this_dir = os.path.split(this_file)[0] | ||
sys.path.append(this_dir) | ||
|
||
import constants | ||
|
||
|
||
# Primary cffi definitions | ||
ffi = FFI() | ||
ffi.set_source('cairocffi._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 | ||
ffi.include(xcb_ffi) | ||
ffi.cdef(constants._CAIRO_XCB_HEADERS) | ||
except ImportError: | ||
pass | ||
|
||
# gdk pixbuf cffi definitions | ||
ffi_pixbuf = FFI() | ||
ffi_pixbuf.set_source('cairocffi._ffi_pixbuf', None) | ||
ffi_pixbuf.include(ffi) | ||
ffi_pixbuf.cdef(''' | ||
typedef unsigned long gsize; | ||
typedef unsigned int guint32; | ||
typedef unsigned int guint; | ||
typedef unsigned char guchar; | ||
typedef char gchar; | ||
typedef int gint; | ||
typedef gint gboolean; | ||
typedef guint32 GQuark; | ||
typedef void* gpointer; | ||
typedef ... GdkPixbufLoader; | ||
typedef ... GdkPixbufFormat; | ||
typedef ... GdkPixbuf; | ||
typedef struct { | ||
GQuark domain; | ||
gint code; | ||
gchar *message; | ||
} GError; | ||
typedef enum { | ||
GDK_COLORSPACE_RGB | ||
} GdkColorspace; | ||
GdkPixbufLoader * gdk_pixbuf_loader_new (void); | ||
GdkPixbufFormat * gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader); | ||
GdkPixbuf * gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader); | ||
gboolean gdk_pixbuf_loader_write ( | ||
GdkPixbufLoader *loader, const guchar *buf, gsize count, | ||
GError **error); | ||
gboolean gdk_pixbuf_loader_close ( | ||
GdkPixbufLoader *loader, GError **error); | ||
gchar * gdk_pixbuf_format_get_name (GdkPixbufFormat *format); | ||
GdkColorspace gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf); | ||
int gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf); | ||
gboolean gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf); | ||
int gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf); | ||
int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf); | ||
int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf); | ||
int gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf); | ||
guchar * gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf); | ||
gsize gdk_pixbuf_get_byte_length (const GdkPixbuf *pixbuf); | ||
gboolean gdk_pixbuf_save_to_buffer ( | ||
GdkPixbuf *pixbuf, gchar **buffer, gsize *buffer_size, | ||
const char *type, GError **error, ...); | ||
void gdk_cairo_set_source_pixbuf ( | ||
cairo_t *cr, const GdkPixbuf *pixbuf, | ||
double pixbuf_x, double pixbuf_y); | ||
void g_object_ref (gpointer object); | ||
void g_object_unref (gpointer object); | ||
void g_error_free (GError *error); | ||
void g_type_init (void); | ||
''') | ||
|
||
|
||
if __name__ == '__main__': | ||
ffi.compile() | ||
ffi_pixbuf.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters