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:

committed by
Sheeo

parent
25d02259df
commit
becc265c78
@@ -43,7 +43,7 @@ from .repository import Repository
|
|||||||
from .settings import Settings
|
from .settings import Settings
|
||||||
from .submodule import Submodule
|
from .submodule import Submodule
|
||||||
from .utils import to_bytes, to_str
|
from .utils import to_bytes, to_str
|
||||||
from ._utils import __version__
|
from .libgit2_build import __version__
|
||||||
|
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
# Import from pygit2
|
# Import from pygit2
|
||||||
from ._utils import get_ffi
|
try:
|
||||||
|
from ._libgit2 import ffi, lib as C
|
||||||
|
except ImportError:
|
||||||
ffi, C = get_ffi()
|
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():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#
|
import cffi
|
||||||
# Loads the cffi extension
|
|
||||||
#
|
|
||||||
def get_ffi():
|
|
||||||
import cffi
|
|
||||||
|
|
||||||
ffi = cffi.FFI()
|
ffi = cffi.FFI()
|
||||||
|
|
||||||
# Load C definitions
|
# Load C definitions
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
if hasattr(sys, '_MEIPASS'):
|
if hasattr(sys, '_MEIPASS'):
|
||||||
dir_path = sys._MEIPASS
|
dir_path = sys._MEIPASS
|
||||||
else:
|
else:
|
||||||
dir_path = dirname(abspath(sys.executable))
|
dir_path = dirname(abspath(sys.executable))
|
||||||
else:
|
else:
|
||||||
dir_path = dirname(abspath(__file__))
|
dir_path = dirname(abspath(__file__))
|
||||||
|
|
||||||
decl_path = os.path.join(dir_path, 'decl.h')
|
decl_path = os.path.join(dir_path, 'decl.h')
|
||||||
with codecs.open(decl_path, 'r', 'utf-8') as header:
|
with codecs.open(decl_path, 'r', 'utf-8') as header:
|
||||||
ffi.cdef(header.read())
|
C_HEADER_SRC = header.read()
|
||||||
|
|
||||||
# The modulename
|
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
|
||||||
# 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)
|
|
||||||
|
|
||||||
# Load extension module
|
C_KEYWORDS = dict(libraries=['git2'],
|
||||||
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
|
library_dirs=[libgit2_lib],
|
||||||
C = ffi.verify(preamble, modulename=modulename, libraries=["git2"],
|
include_dirs=[libgit2_include])
|
||||||
include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
|
|
||||||
|
|
||||||
# Ok
|
# The modulename
|
||||||
return ffi, C
|
# 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
|
# Import stuff from pygit2/_utils.py without loading the whole pygit2 package
|
||||||
sys.path.insert(0, 'pygit2')
|
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]
|
del sys.path[0]
|
||||||
|
|
||||||
# Python 2 support
|
# Python 2 support
|
||||||
@@ -95,19 +95,42 @@ class TestCommand(Command):
|
|||||||
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
||||||
|
|
||||||
|
|
||||||
class CFFIBuild(build):
|
class sdist_files_from_git(sdist):
|
||||||
"""Hack to combat the chicken and egg problem that we need cffi
|
def get_file_list(self):
|
||||||
to add cffi as an extension.
|
popen = Popen(['git', 'ls-files'], stdout=PIPE, stderr=PIPE)
|
||||||
"""
|
stdoutdata, stderrdata = popen.communicate()
|
||||||
def finalize_options(self):
|
if popen.returncode != 0:
|
||||||
ffi, C = get_ffi()
|
print(stderrdata)
|
||||||
self.distribution.ext_modules.append(ffi.verifier.get_extension())
|
sys.exit()
|
||||||
build.finalize_options(self)
|
|
||||||
|
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):
|
def _get_dlls(self):
|
||||||
# return a list of (FQ-in-name, relative-out-name) tuples.
|
# return a list of (FQ-in-name, relative-out-name) tuples.
|
||||||
ret = []
|
ret = []
|
||||||
@@ -133,45 +156,12 @@ class BuildWithDLLs(CFFIBuild):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
build.run(self)
|
build.run(self)
|
||||||
# On Windows we package up the dlls with the plugin.
|
|
||||||
for s, d in self._get_dlls():
|
for s, d in self._get_dlls():
|
||||||
self.copy_file(s, d)
|
self.copy_file(s, d)
|
||||||
|
|
||||||
|
# On Windows we package up the dlls with the plugin.
|
||||||
class sdist_files_from_git(sdist):
|
if os.name == 'nt':
|
||||||
def get_file_list(self):
|
cmdclass['build'] = BuildWithDLLs
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
setup(name='pygit2',
|
setup(name='pygit2',
|
||||||
description='Python bindings for libgit2.',
|
description='Python bindings for libgit2.',
|
||||||
@@ -185,6 +175,7 @@ setup(name='pygit2',
|
|||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
packages=['pygit2'],
|
packages=['pygit2'],
|
||||||
package_data={'pygit2': ['decl.h']},
|
package_data={'pygit2': ['decl.h']},
|
||||||
|
cffi_modules=['pygit2/libgit2_build.py:ffi'],
|
||||||
setup_requires=['cffi'],
|
setup_requires=['cffi'],
|
||||||
install_requires=['cffi'],
|
install_requires=['cffi'],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
Reference in New Issue
Block a user