setup.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #! /usr/bin/env python
  2. import sys, os, glob, platform, tempfile, shutil
  3. # workaround segfaults on openbsd and RHEL 3 / CentOS 3 . see
  4. # https://bitbucket.org/ambroff/greenlet/issue/11/segfault-on-openbsd-i386
  5. # https://github.com/python-greenlet/greenlet/issues/4
  6. # https://github.com/python-greenlet/greenlet/issues/94
  7. if ((sys.platform == "openbsd4" and os.uname()[-1] == "i386")
  8. or ("-with-redhat-3." in platform.platform() and platform.machine() == 'i686')
  9. or (sys.platform == "sunos5" and os.uname()[-1] == "sun4v")
  10. or ("SunOS" in platform.platform() and platform.machine() == "sun4v")
  11. or (sys.platform == "linux" and platform.machine() == "ppc")):
  12. os.environ["CFLAGS"] = ("%s %s" % (os.environ.get("CFLAGS", ""), "-Os")).lstrip()
  13. try:
  14. if not (sys.modules.get("setuptools")
  15. or "develop" in sys.argv
  16. or "upload" in sys.argv
  17. or "bdist_egg" in sys.argv
  18. or "bdist_wheel" in sys.argv
  19. or "test" in sys.argv):
  20. raise ImportError()
  21. from setuptools import setup, Extension
  22. setuptools_args = dict(test_suite='tests.test_collector', zip_safe=False)
  23. except ImportError:
  24. from distutils.core import setup, Extension
  25. setuptools_args = dict()
  26. def readfile(filename):
  27. f = open(filename)
  28. try:
  29. return f.read()
  30. finally:
  31. f.close()
  32. def _find_platform_headers():
  33. return glob.glob("platform/switch_*.h")
  34. if hasattr(sys, "pypy_version_info"):
  35. ext_modules = []
  36. headers = []
  37. else:
  38. headers = ['greenlet.h']
  39. if sys.platform == 'win32' and '64 bit' in sys.version:
  40. # this works when building with msvc, not with 64 bit gcc
  41. # switch_x64_masm.obj can be created with setup_switch_x64_masm.cmd
  42. extra_objects = ['platform/switch_x64_masm.obj']
  43. else:
  44. extra_objects = []
  45. if sys.platform == 'win32' and os.environ.get('GREENLET_STATIC_RUNTIME') in ('1', 'yes'):
  46. extra_compile_args = ['/MT']
  47. elif hasattr(os, 'uname') and os.uname()[4] in ['ppc64el', 'ppc64le']:
  48. extra_compile_args = ['-fno-tree-dominator-opts']
  49. else:
  50. extra_compile_args = []
  51. ext_modules = [Extension(
  52. name='greenlet',
  53. sources=['greenlet.c'],
  54. extra_objects=extra_objects,
  55. extra_compile_args=extra_compile_args,
  56. depends=['greenlet.h', 'slp_platformselect.h'] + _find_platform_headers())]
  57. from distutils.core import Command
  58. from my_build_ext import build_ext
  59. setup(
  60. name="greenlet",
  61. version='0.4.15',
  62. description='Lightweight in-process concurrent programming',
  63. long_description=readfile("README.rst"),
  64. maintainer="Alexey Borzenkov",
  65. maintainer_email="snaury@gmail.com",
  66. url="https://github.com/python-greenlet/greenlet",
  67. license="MIT License",
  68. platforms=['any'],
  69. headers=headers,
  70. ext_modules=ext_modules,
  71. cmdclass=dict(build_ext=build_ext),
  72. classifiers=[
  73. 'Intended Audience :: Developers',
  74. 'License :: OSI Approved :: MIT License',
  75. 'Natural Language :: English',
  76. 'Programming Language :: C',
  77. 'Programming Language :: Python',
  78. 'Programming Language :: Python :: 2',
  79. 'Programming Language :: Python :: 2.4',
  80. 'Programming Language :: Python :: 2.5',
  81. 'Programming Language :: Python :: 2.6',
  82. 'Programming Language :: Python :: 2.7',
  83. 'Programming Language :: Python :: 3',
  84. 'Programming Language :: Python :: 3.0',
  85. 'Programming Language :: Python :: 3.1',
  86. 'Programming Language :: Python :: 3.2',
  87. 'Programming Language :: Python :: 3.3',
  88. 'Programming Language :: Python :: 3.4',
  89. 'Programming Language :: Python :: 3.5',
  90. 'Programming Language :: Python :: 3.6',
  91. 'Programming Language :: Python :: 3.7',
  92. 'Operating System :: OS Independent',
  93. 'Topic :: Software Development :: Libraries :: Python Modules'],
  94. **setuptools_args)