You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

setup.py 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import re
  4. import pathlib
  5. import platform
  6. from distutils.file_util import copy_file
  7. from setuptools import setup, find_packages, Extension
  8. from setuptools.command.build_ext import build_ext as _build_ext
  9. class PrecompiledExtesion(Extension):
  10. def __init__(self, name):
  11. super().__init__(name, sources=[])
  12. class build_ext(_build_ext):
  13. def build_extension(self, ext):
  14. if not isinstance(ext, PrecompiledExtesion):
  15. return super().build_extension(ext)
  16. if not self.inplace:
  17. fullpath = self.get_ext_fullpath(ext.name)
  18. extdir = pathlib.Path(fullpath)
  19. extdir.parent.mkdir(parents=True, exist_ok=True)
  20. modpath = self.get_ext_fullname(ext.name).split('.')
  21. if platform.system() == 'Windows':
  22. modpath[-1] += '.pyd'
  23. else:
  24. modpath[-1] += '.so'
  25. modpath = str(pathlib.Path(*modpath).resolve())
  26. copy_file(modpath, fullpath, verbose=self.verbose, dry_run=self.dry_run)
  27. package_name = 'MegEngine'
  28. v = {}
  29. with open("megengine/version.py") as fp:
  30. exec(fp.read(), v)
  31. __version__ = v['__version__']
  32. email = 'megengine@megvii.com'
  33. # https://www.python.org/dev/peps/pep-0440
  34. # Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
  35. # Local version identifiers: <public version identifier>[+<local version label>]
  36. # PUBLIC_VERSION_POSTFIX use to handle rc or dev info
  37. public_version_postfix = os.environ.get('PUBLIC_VERSION_POSTFIX')
  38. if public_version_postfix:
  39. __version__ = '{}{}'.format(__version__, public_version_postfix)
  40. local_version = []
  41. strip_sdk_info = os.environ.get('STRIP_SDK_INFO', 'False').lower()
  42. sdk_name = os.environ.get('SDK_NAME', 'cpu')
  43. if 'true' == strip_sdk_info:
  44. print('wheel version strip sdk info')
  45. else:
  46. local_version.append(sdk_name)
  47. local_postfix = os.environ.get('LOCAL_VERSION')
  48. if local_postfix:
  49. local_version.append(local_postfix)
  50. if len(local_version):
  51. __version__ = '{}+{}'.format(__version__, '.'.join(local_version))
  52. packages = find_packages(exclude=['test'])
  53. megengine_data = [
  54. str(f.relative_to('megengine'))
  55. for f in pathlib.Path('megengine', 'core', 'include').glob('**/*')
  56. ]
  57. megengine_data += [
  58. str(f.relative_to('megengine'))
  59. for f in pathlib.Path('megengine', 'core', 'lib').glob('**/*')
  60. ]
  61. megenginelite_data = [
  62. str(f.relative_to('megenginelite'))
  63. for f in pathlib.Path('megenginelite').glob('**/*')
  64. ]
  65. if platform.system() == 'Windows':
  66. megenginelite_data.remove('libs\\liblite_shared_whl.pyd')
  67. else:
  68. megenginelite_data.remove('libs/liblite_shared_whl.so')
  69. with open('requires.txt') as f:
  70. requires = f.read().splitlines()
  71. with open('requires-style.txt') as f:
  72. requires_style = f.read().splitlines()
  73. with open('requires-test.txt') as f:
  74. requires_test = f.read().splitlines()
  75. prebuild_modules=[PrecompiledExtesion('megengine.core._imperative_rt')]
  76. prebuild_modules.append(PrecompiledExtesion('megenginelite.libs.liblite_shared_whl'))
  77. setup_kwargs = dict(
  78. name=package_name,
  79. version=__version__,
  80. description='Framework for numerical evaluation with '
  81. 'auto-differentiation',
  82. author='Megvii Engine Team',
  83. author_email=email,
  84. packages=packages,
  85. package_data={
  86. 'megengine': megengine_data,
  87. 'megenginelite': megenginelite_data,
  88. },
  89. ext_modules=prebuild_modules,
  90. install_requires=requires,
  91. extras_require={
  92. 'dev': requires_style + requires_test,
  93. 'ci': requires_test,
  94. },
  95. cmdclass={'build_ext': build_ext},
  96. scripts = ['./megengine/tools/mge'],
  97. )
  98. setup_kwargs.update(dict(
  99. classifiers=[
  100. 'Development Status :: 3 - Alpha',
  101. 'Intended Audience :: Developers',
  102. 'Intended Audience :: Education',
  103. 'Intended Audience :: Science/Research',
  104. 'License :: OSI Approved :: Apache Software License',
  105. 'Programming Language :: C++',
  106. 'Programming Language :: Python :: 3',
  107. 'Programming Language :: Python :: 3.6',
  108. 'Programming Language :: Python :: 3.7',
  109. 'Programming Language :: Python :: 3.8',
  110. 'Programming Language :: Python :: 3.9',
  111. 'Programming Language :: Python :: 3.10',
  112. 'Topic :: Scientific/Engineering',
  113. 'Topic :: Scientific/Engineering :: Mathematics',
  114. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  115. 'Topic :: Software Development',
  116. 'Topic :: Software Development :: Libraries',
  117. 'Topic :: Software Development :: Libraries :: Python Modules',
  118. ],
  119. license='Apache 2.0',
  120. keywords='megengine deep learning',
  121. data_files = [("megengine", [
  122. "../LICENSE",
  123. "../ACKNOWLEDGMENTS",
  124. ])]
  125. ))
  126. setup(**setup_kwargs)