Skip to content

Commit ec23762

Browse files
committed
Add support for cffi-pre-1.0
1 parent 29a8dbc commit ec23762

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

pygit2/ffi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
try:
3333
from ._libgit2 import ffi, lib as C
3434
except ImportError:
35-
from .libgit2_build import ffi, C_HEADER_SRC, C_KEYWORDS
36-
C = ffi.verify(C_HEADER_SRC, **C_KEYWORDS)
35+
from .libgit2_build import ffi, preamble, C_KEYWORDS
36+
C = ffi.verify(preamble, **C_KEYWORDS)

setup.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,16 @@
4545
import sys
4646
import unittest
4747

48+
# Get cffi major version
49+
import cffi
50+
cffi_major_version = cffi.__version_info__[0]
51+
4852
# Import stuff from pygit2/_utils.py without loading the whole pygit2 package
4953
sys.path.insert(0, 'pygit2')
5054
from libgit2_build import __version__, get_libgit2_paths
55+
if cffi_major_version == 0:
56+
from libgit2_build import ffi, preamble, C_KEYWORDS
57+
ffi.verify(preamble, **C_KEYWORDS)
5158
del sys.path[0]
5259

5360
# Python 2 support
@@ -163,6 +170,21 @@ def run(self):
163170
if os.name == 'nt':
164171
cmdclass['build'] = BuildWithDLLs
165172

173+
extra_args = {
174+
'ext_modules': [
175+
Extension('_pygit2', pygit2_exts, libraries=['git2'],
176+
include_dirs=[libgit2_include],
177+
library_dirs=[libgit2_lib]),
178+
# FFI is added in the build step
179+
],
180+
}
181+
182+
if cffi_major_version == 0:
183+
extra_args['ext_modules'].append(ffi.verifier.get_extension())
184+
else:
185+
extra_args['cffi_modules']=['pygit2/libgit2_build.py:ffi']
186+
187+
166188
setup(name='pygit2',
167189
description='Python bindings for libgit2.',
168190
keywords='git',
@@ -175,14 +197,8 @@ def run(self):
175197
long_description=long_description,
176198
packages=['pygit2'],
177199
package_data={'pygit2': ['decl.h']},
178-
cffi_modules=['pygit2/libgit2_build.py:ffi'],
179200
setup_requires=['cffi'],
180201
install_requires=['cffi'],
181202
zip_safe=False,
182-
ext_modules=[
183-
Extension('_pygit2', pygit2_exts, libraries=['git2'],
184-
include_dirs=[libgit2_include],
185-
library_dirs=[libgit2_lib]),
186-
# FFI is added in the build step
187-
],
188-
cmdclass=cmdclass)
203+
cmdclass=cmdclass,
204+
**extra_args)

0 commit comments

Comments
 (0)