Skip to content

Commit 82b3429

Browse files
committed
Merge remote-tracking branch 'opebeat/cffi-install-fix'
2 parents 99f295e + acca272 commit 82b3429

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

setup.py

+30-16
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
from __future__ import print_function
3232

3333
import codecs
34-
from distutils.core import setup, Extension, Command
34+
from setuptools import setup, Extension, Command
3535
from distutils.command.build import build
36+
3637
from distutils.command.sdist import sdist
3738
from distutils import log
3839
import os
@@ -101,8 +102,20 @@ def run(self):
101102
test_argv = test_argv0 + shlex.split(self.args)
102103
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
103104

105+
class CFFIBuild(build):
106+
"""Hack to combat the chicken and egg problem that we need cffi
107+
to add cffi as an extension.
108+
"""
109+
def finalize_options(self):
110+
# This ffi is pygit2.ffi due to the path trick used in the beginning
111+
# of the file
112+
from ffi import ffi
113+
114+
self.distribution.ext_modules.append(ffi.verifier.get_extension())
115+
build.finalize_options(self)
104116

105-
class BuildWithDLLs(build):
117+
118+
class BuildWithDLLs(CFFIBuild):
106119

107120
# On Windows, we install the git2.dll too.
108121
def _get_dlls(self):
@@ -155,15 +168,6 @@ def get_file_list(self):
155168
self.filelist.remove_duplicates()
156169
self.write_manifest()
157170

158-
159-
cmdclass = {
160-
'test': TestCommand,
161-
'sdist': sdist_files_from_git}
162-
163-
if os.name == 'nt':
164-
# BuildWithDLLs can copy external DLLs into source directory.
165-
cmdclass['build'] = BuildWithDLLs
166-
167171
classifiers = [
168172
"Development Status :: 3 - Alpha",
169173
"Intended Audience :: Developers",
@@ -173,10 +177,18 @@ def get_file_list(self):
173177
with codecs.open('README.rst', 'r', 'utf-8') as readme:
174178
long_description = readme.read()
175179

176-
# This ffi is pygit2.ffi due to the path trick used in the beginning
177-
# of the file
178-
from ffi import ffi
179-
ffi_ext = ffi.verifier.get_extension()
180+
181+
cmdclass = {
182+
'test': TestCommand,
183+
'sdist': sdist_files_from_git}
184+
185+
if os.name == 'nt':
186+
# BuildWithDLLs can copy external DLLs into source directory.
187+
cmdclass['build'] = BuildWithDLLs
188+
else:
189+
# Build cffi
190+
cmdclass['build'] = CFFIBuild
191+
180192

181193
setup(name='pygit2',
182194
description='Python bindings for libgit2.',
@@ -190,12 +202,14 @@ def get_file_list(self):
190202
long_description=long_description,
191203
packages=['pygit2'],
192204
package_data={'pygit2': ['decl.h']},
205+
setup_requires=['cffi'],
193206
install_requires=['cffi'],
207+
zip_safe=False,
194208
ext_modules=[
195209
Extension('_pygit2', pygit2_exts,
196210
include_dirs=[libgit2_include, 'include'],
197211
library_dirs=[libgit2_lib],
198212
libraries=['git2']),
199-
ffi_ext,
213+
# FFI is added in the build step
200214
],
201215
cmdclass=cmdclass)

0 commit comments

Comments
 (0)