|
11 | 11 | install_requires.append('ordereddict>=1.1') |
12 | 12 |
|
13 | 13 | base_path = os.path.dirname(os.path.abspath(__file__)) |
| 14 | +pyx_path = os.path.join(base_path, 'bencoder.pyx') |
| 15 | +c_path = os.path.join(base_path, 'bencoder.c') |
14 | 16 |
|
15 | | -if sys.argv[-1] == 'test': |
| 17 | +if sys.argv[-1] == 'test' and platform.python_implementation() == 'CPython': |
16 | 18 | from Cython.Compiler.Options import directive_defaults |
17 | 19 |
|
18 | 20 | directive_defaults['linetrace'] = True |
|
21 | 23 | from Cython.Build import cythonize |
22 | 24 | ext_modules = cythonize(Extension( |
23 | 25 | "bencoder", |
24 | | - ["bencoder.pyx"], |
| 26 | + [pyx_path], |
25 | 27 | define_macros=[('CYTHON_TRACE', '1')] |
26 | 28 | )) |
27 | | -else: |
| 29 | +elif os.path.exists(c_path): |
28 | 30 | ext_modules = [Extension( |
29 | 31 | 'bencoder', |
30 | | - [os.path.join(base_path, 'bencoder.c')] |
| 32 | + [c_path] |
31 | 33 | )] |
| 34 | +else: |
| 35 | + from Cython.Build import cythonize |
| 36 | + ext_modules = cythonize(Extension( |
| 37 | + "bencoder", |
| 38 | + [pyx_path] |
| 39 | + )) |
| 40 | + |
| 41 | + |
| 42 | +# patch bdist_wheel |
| 43 | +cmdclass = {} |
| 44 | +try: |
| 45 | + from wheel.bdist_wheel import bdist_wheel |
| 46 | + |
| 47 | + REPLACE = ( |
| 48 | + 'macosx_10_6_intel.' |
| 49 | + 'macosx_10_9_intel.' |
| 50 | + 'macosx_10_9_x86_64.' |
| 51 | + 'macosx_10_10_intel.' |
| 52 | + 'macosx_10_10_x86_64' |
| 53 | + ) |
| 54 | + |
| 55 | + class _bdist_wheel(bdist_wheel): |
| 56 | + def get_tag(self): |
| 57 | + tag = bdist_wheel.get_tag(self) |
| 58 | + if tag[2] == 'macosx_10_6_intel': |
| 59 | + tag = (tag[0], tag[1], REPLACE) |
| 60 | + return tag |
| 61 | + |
| 62 | + cmdclass['bdist_wheel'] = _bdist_wheel |
| 63 | +except ImportError: |
| 64 | + pass |
32 | 65 |
|
33 | 66 |
|
34 | 67 | setup( |
|
44 | 77 | zip_safe=False, |
45 | 78 | include_package_data=True, |
46 | 79 | keywords=['bencoding', 'encode', 'decode', 'bittorrent', 'bencode', 'bencoder', 'cython'], |
| 80 | + cmdclass=cmdclass, |
47 | 81 | classifiers=[ |
48 | 82 | 'Environment :: Other Environment', |
49 | 83 | 'Intended Audience :: Developers', |
|
0 commit comments