From 4056ebf53bdf68e61b3a34628d26cc6495497339 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Thu, 21 Aug 2014 15:48:25 +0200 Subject: [PATCH 1/3] Fixed the chicked-and-egg problem with CFFI in setup. This still needs some work in order to fix the problem under windows. I have no windows machine here to test it. --- setup.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 27733f4..2e885d1 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -155,15 +156,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 +165,31 @@ 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() + +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 + + self.distribution.ext_modules.append(ffi.verifier.get_extension()) + build.finalize_options(self) + + +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.', @@ -191,11 +204,12 @@ setup(name='pygit2', packages=['pygit2'], package_data={'pygit2': ['decl.h']}, 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) From a459712fde84dd3c002a53a41e7257768ba9093d Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Thu, 21 Aug 2014 16:00:40 +0200 Subject: [PATCH 2/3] Forgot the `setup_requires` argument. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 2e885d1..477f575 100644 --- a/setup.py +++ b/setup.py @@ -203,6 +203,7 @@ 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=[ From acca2726dfd463f027152870f7e2d7527bf15631 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Thu, 21 Aug 2014 18:42:27 +0200 Subject: [PATCH 3/3] BuildWithDLLs now inherits from CFFIBuild to *theoretically* fix windows. --- setup.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 477f575..f53a84a 100644 --- a/setup.py +++ b/setup.py @@ -102,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): @@ -166,19 +178,6 @@ with codecs.open('README.rst', 'r', 'utf-8') as readme: long_description = readme.read() -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 - - self.distribution.ext_modules.append(ffi.verifier.get_extension()) - build.finalize_options(self) - - cmdclass = { 'test': TestCommand, 'sdist': sdist_files_from_git}