setup.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # References:
  2. # http://www.swig.org/Doc3.0/SWIGDocumentation.html#Python
  3. # http://www.swig.org/Doc3.0/SWIGDocumentation.html#Introduction_nn4
  4. # https://docs.python.org/2.7/extending/building.html#distributing-your-extension-modules
  5. # https://docs.python.org/2/distutils/setupscript.html#describing-extension-modules
  6. # https://docs.python.org/2/distutils/apiref.html#distutils.core.Extension
  7. # http://pythonhosted.org/setuptools/setuptools.html
  8. from setuptools import setup, Extension
  9. from setuptools.command.install import install
  10. from distutils.command.build import build
  11. # By default, distutils/setuptools build Python before the extensions.
  12. # Unfortunately a Python file is generated when building the SWIG extension.
  13. # That means that the generated file is not going to be installed since the
  14. # Python build has already happened!
  15. # As a workaround, we need to use a custom build and install class that run the
  16. # SWIG extension first.
  17. # References:
  18. # https://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
  19. # https://stackoverflow.com/questions/17666018/using-distutils-where-swig-interface-file-is-in-src-folder
  20. class BuildSwig(build):
  21. def run(self):
  22. self.run_command('build_ext')
  23. build.run(self)
  24. class InstallSwig(install):
  25. def run(self):
  26. self.run_command('build_ext')
  27. install.run(self)
  28. swig = Extension(
  29. 'swagga.extensions._example',
  30. ['swagga/extensions/example.i', 'native/code/example.c'],
  31. include_dirs=['native/include'],
  32. define_macros=None,
  33. undef_macros=None,
  34. library_dirs=None,
  35. libraries=None,
  36. runtime_library_dirs=None,
  37. extra_objects=None,
  38. extra_compile_args=None,
  39. extra_link_args=None,
  40. export_symbols=None,
  41. swig_opts=None,
  42. depends=None,
  43. language=None
  44. )
  45. setup(
  46. cmdclass={'build': BuildSwig, 'install': InstallSwig},
  47. name='swagga.extensions',
  48. packages=['swagga.extensions'],
  49. namespace_packages=['swagga'],
  50. install_requires=['setuptools'],
  51. version='0.1.dev1',
  52. ext_modules=[swig],
  53. )