33import sys
44import pyrox .about
55
6- from setuptools import setup , find_packages
7- from distutils .extension import Extension
6+ from setuptools import setup , find_packages , Extension
87
9- try :
10- from Cython .Build import cythonize
11- has_cython = True
12- except ImportError :
13- has_cython = False
8+
9+ # force setuptools not to convert .pyx to .c in the Extension
10+ import setuptools .extension
11+ assert callable (setuptools .extension .have_pyrex ), "Requires setuptools 0.6.26 or later"
12+ setuptools .extension .have_pyrex = lambda : True
13+
14+ # https://bitbucket.org/pypa/setuptools/issues/288/cannot-specify-cython-under-setup_requires
15+ class LateResolvedCommandLookup (dict ):
16+ """
17+ A dictionary of distutils commands with overrides to be resolved late.
18+ Late-resolved commands should be implemented as callable methods on
19+ the class.
20+
21+ This class allows 'build_ext' to be resolve after setup_requires resolves
22+ dependencies such as Cython.
23+ """
24+ def __getitem__ (self , name ):
25+ if getattr (self , name , None ):
26+ return getattr (self , name )()
27+ return super (LateResolvedCommandLookup , self ).__getitem__ (name )
28+
29+ def __contains__ (self , name ):
30+ return hasattr (self , name ) or (
31+ super (LateResolvedCommandLookup , self ).__contains__ (name ))
32+
33+ def build_ext (self ):
34+ Cython = __import__ ('Cython.Distutils.build_ext' )
35+ return Cython .Distutils .build_ext
1436
1537
1638def read (relative ):
@@ -21,17 +43,21 @@ def read(relative):
2143def compile_pyx ():
2244 ext_modules = list ()
2345
24- cparser = cythonize ('pyrox/http/parser.pyx' )[0 ]
25- cparser .sources .insert (0 , 'include/http_el.c' )
26- ext_modules .append (cparser )
46+ e = Extension ('pyrox.http.parser' ,
47+ sources = ['pyrox/http/parser.pyx' ],
48+ include_dirs = ['include/' ])
49+ ext_modules .append (e )
2750
28- ext_modules .extend (cythonize ('pyrox/http/model_util.pyx' ))
51+ e = Extension ('pyrox.http.model_util' ,
52+ sources = ['pyrox/http/model_util.pyx' ],
53+ include_dirs = ['include/' ])
54+ ext_modules .append (e )
2955
3056 return ext_modules
3157
3258
3359# compiler flags
34- CFLAGS = ['-I' , './include' ]
60+ CFLAGS = []
3561DEBUG = os .getenv ('DEBUG' )
3662
3763if DEBUG and DEBUG .lower () == 'true' :
@@ -63,6 +89,7 @@ def compile_pyx():
6389 'Topic :: Utilities'
6490 ],
6591 scripts = ['scripts/pyrox' ],
92+ setup_requires = read ('tools/setup_requires.txt' ),
6693 tests_require = read ('tools/tests_require.txt' ),
6794 install_requires = read ('tools/install_requires.txt' ),
6895 test_suite = 'nose.collector' ,
@@ -72,4 +99,6 @@ def compile_pyx():
7299 },
73100 include_package_data = True ,
74101 packages = find_packages (exclude = ['*.tests' ]),
75- ext_modules = compile_pyx ())
102+ ext_modules = compile_pyx (),
103+ cmdclass = LateResolvedCommandLookup (),
104+ )
0 commit comments