|
1 |
| -from distutils.core import setup, Extension |
| 1 | +from setuptools import setup, Extension |
2 | 2 | from os import environ, walk
|
3 | 3 | from os.path import dirname, join, exists
|
4 | 4 | import sys
|
5 |
| -import subprocess |
6 | 5 | import platform
|
| 6 | +from distutils.command.build_ext import build_ext |
7 | 7 |
|
8 | 8 | with open(join('pyobjus', '__init__.py')) as fd:
|
9 | 9 | VERSION = [
|
|
20 | 20 | print("Pyobjus platform is {}".format(dev_platform))
|
21 | 21 |
|
22 | 22 | # OSX
|
| 23 | +files = [] |
23 | 24 | if dev_platform == 'darwin':
|
24 |
| - try: |
25 |
| - from Cython.Distutils import build_ext |
26 |
| - except ImportError: |
27 |
| - raise |
28 | 25 | files = ['pyobjus.pyx']
|
29 | 26 | # iOS
|
30 | 27 | elif dev_platform == 'ios':
|
31 |
| - from distutils.command.build_ext import build_ext |
32 | 28 | files = ['pyobjus.c']
|
33 | 29 |
|
34 | 30 |
|
35 | 31 | class PyObjusBuildExt(build_ext, object):
|
36 | 32 |
|
| 33 | + def __new__(cls, *a, **kw): |
| 34 | + # Note how this class is declared as a subclass of distutils |
| 35 | + # build_ext as the Cython version may not be available in the |
| 36 | + # environment it is initially started in. However, if Cython |
| 37 | + # can be used, setuptools will bring Cython into the environment |
| 38 | + # thus its version of build_ext will become available. |
| 39 | + # The reason why this is done as a __new__ rather than through a |
| 40 | + # factory function is because there are distutils functions that check |
| 41 | + # the values provided by cmdclass with issublcass, and so it would |
| 42 | + # result in an exception. |
| 43 | + # The following essentially supply a dynamically generated subclass |
| 44 | + # that mix in the cython version of build_ext so that the |
| 45 | + # functionality provided will also be executed. |
| 46 | + if dev_platform != 'ios': |
| 47 | + from Cython.Distutils import build_ext as cython_build_ext |
| 48 | + build_ext_cls = type( |
| 49 | + 'PyObjusBuildExt', (PyObjusBuildExt, cython_build_ext), {}) |
| 50 | + return super(PyObjusBuildExt, cls).__new__(build_ext_cls) |
| 51 | + else: |
| 52 | + return super(PyObjusBuildExt, cls).__new__(cls) |
| 53 | + |
37 | 54 | def build_extensions(self):
|
38 | 55 | # create a configuration file for pyobjus (export the platform)
|
39 | 56 | config_pxi_fn = join(dirname(__file__), 'pyobjus', 'config.pxi')
|
@@ -69,6 +86,7 @@ def build_extensions(self):
|
69 | 86 | 'ttf', 'obj', 'mtl', 'kv', 'mpg', 'glsl', 'zip', 'h', 'm', 'md',
|
70 | 87 | )
|
71 | 88 |
|
| 89 | + |
72 | 90 | def tree(source, allowed_ext=data_allowed_ext, tree_name='share/pyobjus-'):
|
73 | 91 | found = {}
|
74 | 92 |
|
|
0 commit comments