setup.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. import numpy
  3. import os
  4. from os.path import dirname, join, splitext
  5. from setuptools import Extension, setup
  6. try:
  7. from Cython.Build import cythonize
  8. except ImportError:
  9. cythonize = None
  10. # https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules
  11. def no_cythonize(extensions, **_ignore):
  12. for extension in extensions:
  13. sources = []
  14. for sfile in extension.sources:
  15. path, ext = splitext(sfile)
  16. if ext in (".pyx", ".py"):
  17. if extension.language == "c++":
  18. ext = ".cpp"
  19. else:
  20. ext = ".c"
  21. sfile = path + ext
  22. sources.append(sfile)
  23. extension.sources[:] = sources
  24. return extensions
  25. EXT_NAME = "yaflpy"
  26. SETUP_DIR = dirname(__file__)
  27. SRC_DIR = join(SETUP_DIR, "src")
  28. EXT_DIR = join(SRC_DIR, EXT_NAME)
  29. extensions = [
  30. Extension(EXT_NAME, [join(EXT_DIR, EXT_NAME + ".pyx")],
  31. include_dirs=[numpy.get_include(), SRC_DIR, EXT_DIR],
  32. define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")])
  33. ]
  34. CYTHONIZE = bool(int(os.getenv("CYTHONIZE", 0))) and cythonize is not None
  35. if CYTHONIZE:
  36. compiler_directives = {"language_level": 3, "embedsignature": True}
  37. extensions = cythonize(extensions, compiler_directives=compiler_directives)
  38. else:
  39. extensions = no_cythonize(extensions)
  40. with open("requirements.txt") as fp:
  41. install_requires = fp.read().strip().split("\n")
  42. with open("requirements-dev.txt") as fp:
  43. dev_requires = fp.read().strip().split("\n")
  44. setup(
  45. ext_modules=extensions,
  46. install_requires=install_requires,
  47. extras_require={
  48. "dev": dev_requires,
  49. "docs": ["sphinx", "sphinx-rtd-theme"]
  50. },
  51. )