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 5.0 kB

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