31
31
from __future__ import print_function
32
32
33
33
import codecs
34
- from distutils . core import setup , Extension , Command
34
+ from setuptools import setup , Extension , Command
35
35
from distutils .command .build import build
36
+
36
37
from distutils .command .sdist import sdist
37
38
from distutils import log
38
39
import os
@@ -101,8 +102,20 @@ def run(self):
101
102
test_argv = test_argv0 + shlex .split (self .args )
102
103
unittest .main (None , defaultTest = 'test.test_suite' , argv = test_argv )
103
104
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 )
104
116
105
- class BuildWithDLLs (build ):
117
+
118
+ class BuildWithDLLs (CFFIBuild ):
106
119
107
120
# On Windows, we install the git2.dll too.
108
121
def _get_dlls (self ):
@@ -155,15 +168,6 @@ def get_file_list(self):
155
168
self .filelist .remove_duplicates ()
156
169
self .write_manifest ()
157
170
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
-
167
171
classifiers = [
168
172
"Development Status :: 3 - Alpha" ,
169
173
"Intended Audience :: Developers" ,
@@ -173,10 +177,18 @@ def get_file_list(self):
173
177
with codecs .open ('README.rst' , 'r' , 'utf-8' ) as readme :
174
178
long_description = readme .read ()
175
179
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
+
180
192
181
193
setup (name = 'pygit2' ,
182
194
description = 'Python bindings for libgit2.' ,
@@ -190,12 +202,14 @@ def get_file_list(self):
190
202
long_description = long_description ,
191
203
packages = ['pygit2' ],
192
204
package_data = {'pygit2' : ['decl.h' ]},
205
+ setup_requires = ['cffi' ],
193
206
install_requires = ['cffi' ],
207
+ zip_safe = False ,
194
208
ext_modules = [
195
209
Extension ('_pygit2' , pygit2_exts ,
196
210
include_dirs = [libgit2_include , 'include' ],
197
211
library_dirs = [libgit2_lib ],
198
212
libraries = ['git2' ]),
199
- ffi_ext ,
213
+ # FFI is added in the build step
200
214
],
201
215
cmdclass = cmdclass )
0 commit comments