setup.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # coding: utf-8
  2. from __future__ import with_statement, print_function, absolute_import
  3. from setuptools import setup, find_packages, Extension
  4. import setuptools.command.develop
  5. import setuptools.command.build_py
  6. from distutils.version import LooseVersion
  7. import subprocess
  8. import numpy as np
  9. import os
  10. from os.path import join
  11. version = '0.0.1'
  12. sinsy_install_prefix = os.environ.get(
  13. "SINSY_INSTALL_PREFIX", "/usr/local/")
  14. sinsy_include_top = join(sinsy_install_prefix, "include")
  15. sinsy_library_path = join(sinsy_install_prefix, "lib")
  16. lib_candidates = list(filter(lambda l: l.startswith("libsinsy."),
  17. os.listdir(join(sinsy_library_path))))
  18. if len(lib_candidates) == 0:
  19. raise OSError("sinsy library cannot be found")
  20. min_cython_ver = '0.21.0'
  21. try:
  22. import Cython
  23. ver = Cython.__version__
  24. _CYTHON_INSTALLED = ver >= LooseVersion(min_cython_ver)
  25. except ImportError:
  26. _CYTHON_INSTALLED = False
  27. try:
  28. if not _CYTHON_INSTALLED:
  29. raise ImportError('No supported version of Cython installed.')
  30. from Cython.Distutils import build_ext
  31. from Cython.Build import cythonize
  32. cython = True
  33. except ImportError:
  34. cython = False
  35. if cython:
  36. ext = '.pyx'
  37. cmdclass = {'build_ext': build_ext}
  38. else:
  39. ext = '.cpp'
  40. cmdclass = {}
  41. if not os.path.exists(join("pysinsy", "sinsy" + ext)):
  42. raise RuntimeError("Cython is required to generate C++ code")
  43. ext_modules = cythonize(
  44. [Extension(
  45. name="pysinsy.sinsy",
  46. sources=[
  47. join("pysinsy", "sinsy" + ext),
  48. ],
  49. include_dirs=[np.get_include(),
  50. join(sinsy_include_top)],
  51. library_dirs=[sinsy_library_path],
  52. libraries=["sinsy"],
  53. extra_compile_args=[],
  54. extra_link_args=[],
  55. language="c++")],
  56. )
  57. # Adapted from https://github.com/pytorch/pytorch
  58. cwd = os.path.dirname(os.path.abspath(__file__))
  59. if os.getenv('PYSINSY_BUILD_VERSION'):
  60. version = os.getenv('PYSINSY_BUILD_VERSION')
  61. else:
  62. try:
  63. sha = subprocess.check_output(
  64. ['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()
  65. version += '+' + sha[:7]
  66. except subprocess.CalledProcessError:
  67. pass
  68. except IOError: # FileNotFoundError for python 3
  69. pass
  70. class build_py(setuptools.command.build_py.build_py):
  71. def run(self):
  72. self.create_version_file()
  73. setuptools.command.build_py.build_py.run(self)
  74. @staticmethod
  75. def create_version_file():
  76. global version, cwd
  77. print('-- Building version ' + version)
  78. version_path = os.path.join(cwd, 'pysinsy', 'version.py')
  79. with open(version_path, 'w') as f:
  80. f.write("__version__ = '{}'\n".format(version))
  81. class develop(setuptools.command.develop.develop):
  82. def run(self):
  83. build_py.create_version_file()
  84. setuptools.command.develop.develop.run(self)
  85. cmdclass['build_py'] = build_py
  86. cmdclass['develop'] = develop
  87. with open('README.md', 'r') as fd:
  88. long_description = fd.read()
  89. setup(
  90. name='pysinsy',
  91. version=version,
  92. description='A python wrapper for sinsy',
  93. long_description=long_description,
  94. long_description_content_type='text/markdown',
  95. author='Ryuichi Yamamoto',
  96. author_email='zryuichi@gmail.com',
  97. url='https://github.com/r9y9/pysinsy',
  98. license='MIT',
  99. packages=find_packages(),
  100. package_data={'': ['htsvoice/*']},
  101. ext_modules=ext_modules,
  102. cmdclass=cmdclass,
  103. install_requires=[
  104. 'numpy >= 1.8.0',
  105. 'cython >= ' + min_cython_ver,
  106. 'six',
  107. ],
  108. tests_require=['nose', 'coverage'],
  109. extras_require={
  110. 'docs': ['sphinx_rtd_theme'],
  111. 'test': ['nose', 'scipy'],
  112. },
  113. classifiers=[
  114. "Operating System :: POSIX",
  115. "Operating System :: Unix",
  116. "Operating System :: MacOS",
  117. "Programming Language :: Cython",
  118. "Programming Language :: Python",
  119. "Programming Language :: Python :: 3",
  120. "Programming Language :: Python :: 3.5",
  121. "Programming Language :: Python :: 3.6",
  122. "Programming Language :: Python :: 3.7",
  123. "Programming Language :: Python :: 3.8",
  124. "License :: OSI Approved :: MIT License",
  125. "Topic :: Scientific/Engineering",
  126. "Topic :: Software Development",
  127. "Intended Audience :: Science/Research",
  128. "Intended Audience :: Developers",
  129. ],
  130. keywords=["Sinsy", "Research"]
  131. )