Don't use the deprecated cffi.verify by default
Instead this does what is recommend in the CFFI docs here: https://cffi.readthedocs.org/en/latest/cdef.html?highlight=verify#out-of-line-api This also means building the cffi extension is neatly handled by cffi's setuptools integration itself, so we can delete the code in setup.py that used to do this.
This commit is contained in:
parent
25d02259df
commit
becc265c78
@ -43,7 +43,7 @@ from .repository import Repository
|
||||
from .settings import Settings
|
||||
from .submodule import Submodule
|
||||
from .utils import to_bytes, to_str
|
||||
from ._utils import __version__
|
||||
from .libgit2_build import __version__
|
||||
|
||||
|
||||
# Features
|
||||
|
@ -29,7 +29,8 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import from pygit2
|
||||
from ._utils import get_ffi
|
||||
|
||||
|
||||
ffi, C = get_ffi()
|
||||
try:
|
||||
from ._libgit2 import ffi, lib as C
|
||||
except ImportError:
|
||||
from .libgit2_build import ffi, C_HEADER_SRC, C_KEYWORDS
|
||||
C = ffi.verify(C_HEADER_SRC, **C_KEYWORDS)
|
||||
|
@ -69,42 +69,37 @@ def get_libgit2_paths():
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Loads the cffi extension
|
||||
#
|
||||
def get_ffi():
|
||||
import cffi
|
||||
import cffi
|
||||
|
||||
ffi = cffi.FFI()
|
||||
ffi = cffi.FFI()
|
||||
|
||||
# Load C definitions
|
||||
if getattr(sys, 'frozen', False):
|
||||
if hasattr(sys, '_MEIPASS'):
|
||||
dir_path = sys._MEIPASS
|
||||
else:
|
||||
dir_path = dirname(abspath(sys.executable))
|
||||
# Load C definitions
|
||||
if getattr(sys, 'frozen', False):
|
||||
if hasattr(sys, '_MEIPASS'):
|
||||
dir_path = sys._MEIPASS
|
||||
else:
|
||||
dir_path = dirname(abspath(__file__))
|
||||
dir_path = dirname(abspath(sys.executable))
|
||||
else:
|
||||
dir_path = dirname(abspath(__file__))
|
||||
|
||||
decl_path = os.path.join(dir_path, 'decl.h')
|
||||
with codecs.open(decl_path, 'r', 'utf-8') as header:
|
||||
ffi.cdef(header.read())
|
||||
decl_path = os.path.join(dir_path, 'decl.h')
|
||||
with codecs.open(decl_path, 'r', 'utf-8') as header:
|
||||
C_HEADER_SRC = header.read()
|
||||
|
||||
# The modulename
|
||||
# Simplified version of what cffi does: remove kwargs and vengine
|
||||
preamble = "#include <git2.h>"
|
||||
key = [sys.version[:3], cffi.__version__, preamble] + ffi._cdefsources
|
||||
key = '\x00'.join(key)
|
||||
if sys.version_info >= (3,):
|
||||
key = key.encode('utf-8')
|
||||
k1 = hex(crc32(key[0::2]) & 0xffffffff).lstrip('0x').rstrip('L')
|
||||
k2 = hex(crc32(key[1::2]) & 0xffffffff).lstrip('0').rstrip('L')
|
||||
modulename = 'pygit2_cffi_%s%s' % (k1, k2)
|
||||
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
|
||||
|
||||
# Load extension module
|
||||
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
|
||||
C = ffi.verify(preamble, modulename=modulename, libraries=["git2"],
|
||||
include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
|
||||
C_KEYWORDS = dict(libraries=['git2'],
|
||||
library_dirs=[libgit2_lib],
|
||||
include_dirs=[libgit2_include])
|
||||
|
||||
# Ok
|
||||
return ffi, C
|
||||
# The modulename
|
||||
# Simplified version of what cffi does: remove kwargs and vengine
|
||||
preamble = "#include <git2.h>"
|
||||
|
||||
if hasattr(ffi, 'set_source'):
|
||||
ffi.set_source("pygit2._libgit2", preamble, **C_KEYWORDS)
|
||||
|
||||
ffi.cdef(C_HEADER_SRC)
|
||||
|
||||
if __name__ == '__main__':
|
||||
ffi.compile()
|
85
setup.py
85
setup.py
@ -47,7 +47,7 @@ import unittest
|
||||
|
||||
# Import stuff from pygit2/_utils.py without loading the whole pygit2 package
|
||||
sys.path.insert(0, 'pygit2')
|
||||
from _utils import __version__, get_libgit2_paths, get_ffi
|
||||
from libgit2_build import __version__, get_libgit2_paths
|
||||
del sys.path[0]
|
||||
|
||||
# Python 2 support
|
||||
@ -95,19 +95,42 @@ class TestCommand(Command):
|
||||
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
||||
|
||||
|
||||
class CFFIBuild(build):
|
||||
"""Hack to combat the chicken and egg problem that we need cffi
|
||||
to add cffi as an extension.
|
||||
"""
|
||||
def finalize_options(self):
|
||||
ffi, C = get_ffi()
|
||||
self.distribution.ext_modules.append(ffi.verifier.get_extension())
|
||||
build.finalize_options(self)
|
||||
class sdist_files_from_git(sdist):
|
||||
def get_file_list(self):
|
||||
popen = Popen(['git', 'ls-files'], stdout=PIPE, stderr=PIPE)
|
||||
stdoutdata, stderrdata = popen.communicate()
|
||||
if popen.returncode != 0:
|
||||
print(stderrdata)
|
||||
sys.exit()
|
||||
|
||||
for line in stdoutdata.splitlines():
|
||||
# Skip hidden files at the root
|
||||
if line[0] == '.':
|
||||
continue
|
||||
self.filelist.append(line)
|
||||
|
||||
# Ok
|
||||
self.filelist.sort()
|
||||
self.filelist.remove_duplicates()
|
||||
self.write_manifest()
|
||||
|
||||
|
||||
class BuildWithDLLs(CFFIBuild):
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Version Control"]
|
||||
|
||||
# On Windows, we install the git2.dll too.
|
||||
with codecs.open('README.rst', 'r', 'utf-8') as readme:
|
||||
long_description = readme.read()
|
||||
|
||||
cmdclass = {
|
||||
'test': TestCommand,
|
||||
'sdist': sdist_files_from_git,
|
||||
}
|
||||
|
||||
|
||||
# On Windows, we install the git2.dll too.
|
||||
class BuildWithDLLs(build):
|
||||
def _get_dlls(self):
|
||||
# return a list of (FQ-in-name, relative-out-name) tuples.
|
||||
ret = []
|
||||
@ -133,45 +156,12 @@ class BuildWithDLLs(CFFIBuild):
|
||||
|
||||
def run(self):
|
||||
build.run(self)
|
||||
# On Windows we package up the dlls with the plugin.
|
||||
for s, d in self._get_dlls():
|
||||
self.copy_file(s, d)
|
||||
|
||||
|
||||
class sdist_files_from_git(sdist):
|
||||
def get_file_list(self):
|
||||
popen = Popen(['git', 'ls-files'], stdout=PIPE, stderr=PIPE)
|
||||
stdoutdata, stderrdata = popen.communicate()
|
||||
if popen.returncode != 0:
|
||||
print(stderrdata)
|
||||
sys.exit()
|
||||
|
||||
for line in stdoutdata.splitlines():
|
||||
# Skip hidden files at the root
|
||||
if line[0] == '.':
|
||||
continue
|
||||
self.filelist.append(line)
|
||||
|
||||
# Ok
|
||||
self.filelist.sort()
|
||||
self.filelist.remove_duplicates()
|
||||
self.write_manifest()
|
||||
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Version Control"]
|
||||
|
||||
|
||||
with codecs.open('README.rst', 'r', 'utf-8') as readme:
|
||||
long_description = readme.read()
|
||||
|
||||
|
||||
cmdclass = {
|
||||
'build': BuildWithDLLs if os.name == 'nt' else CFFIBuild,
|
||||
'test': TestCommand,
|
||||
'sdist': sdist_files_from_git,
|
||||
}
|
||||
# On Windows we package up the dlls with the plugin.
|
||||
if os.name == 'nt':
|
||||
cmdclass['build'] = BuildWithDLLs
|
||||
|
||||
setup(name='pygit2',
|
||||
description='Python bindings for libgit2.',
|
||||
@ -185,6 +175,7 @@ setup(name='pygit2',
|
||||
long_description=long_description,
|
||||
packages=['pygit2'],
|
||||
package_data={'pygit2': ['decl.h']},
|
||||
cffi_modules=['pygit2/libgit2_build.py:ffi'],
|
||||
setup_requires=['cffi'],
|
||||
install_requires=['cffi'],
|
||||
zip_safe=False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user