Merge remote-tracking branch 'opebeat/cffi-install-fix'

This commit is contained in:
J. David Ibáñez
2014-08-21 19:31:10 +02:00

View File

@@ -31,8 +31,9 @@
from __future__ import print_function
import codecs
from distutils.core import setup, Extension, Command
from setuptools import setup, Extension, Command
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils import log
import os
@@ -101,8 +102,20 @@ class TestCommand(Command):
test_argv = test_argv0 + shlex.split(self.args)
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):
# This ffi is pygit2.ffi due to the path trick used in the beginning
# of the file
from ffi import ffi
class BuildWithDLLs(build):
self.distribution.ext_modules.append(ffi.verifier.get_extension())
build.finalize_options(self)
class BuildWithDLLs(CFFIBuild):
# On Windows, we install the git2.dll too.
def _get_dlls(self):
@@ -155,15 +168,6 @@ class sdist_files_from_git(sdist):
self.filelist.remove_duplicates()
self.write_manifest()
cmdclass = {
'test': TestCommand,
'sdist': sdist_files_from_git}
if os.name == 'nt':
# BuildWithDLLs can copy external DLLs into source directory.
cmdclass['build'] = BuildWithDLLs
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
@@ -173,10 +177,18 @@ classifiers = [
with codecs.open('README.rst', 'r', 'utf-8') as readme:
long_description = readme.read()
# This ffi is pygit2.ffi due to the path trick used in the beginning
# of the file
from ffi import ffi
ffi_ext = ffi.verifier.get_extension()
cmdclass = {
'test': TestCommand,
'sdist': sdist_files_from_git}
if os.name == 'nt':
# BuildWithDLLs can copy external DLLs into source directory.
cmdclass['build'] = BuildWithDLLs
else:
# Build cffi
cmdclass['build'] = CFFIBuild
setup(name='pygit2',
description='Python bindings for libgit2.',
@@ -190,12 +202,14 @@ setup(name='pygit2',
long_description=long_description,
packages=['pygit2'],
package_data={'pygit2': ['decl.h']},
setup_requires=['cffi'],
install_requires=['cffi'],
zip_safe=False,
ext_modules=[
Extension('_pygit2', pygit2_exts,
include_dirs=[libgit2_include, 'include'],
library_dirs=[libgit2_lib],
libraries=['git2']),
ffi_ext,
# FFI is added in the build step
],
cmdclass=cmdclass)