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

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env python3
  2. # encoding: utf-8
  3. # Copyright 2020 Huawei Technologies Co., Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # ============================================================================
  17. """setup package."""
  18. import os
  19. import stat
  20. import platform
  21. from setuptools import setup, find_packages
  22. from setuptools.command.egg_info import egg_info
  23. from setuptools.command.build_py import build_py
  24. version = '1.2.0'
  25. backend_policy = os.getenv('BACKEND_POLICY')
  26. device_target = os.getenv('BACKEND_TARGET')
  27. commit_id = os.getenv('COMMIT_ID').replace("\n", "")
  28. package_name = os.getenv('MS_PACKAGE_NAME').replace("\n", "")
  29. pwd = os.path.dirname(os.path.realpath(__file__))
  30. pkg_dir = os.path.join(pwd, 'build/package')
  31. def _read_file(filename):
  32. with open(os.path.join(pwd, filename), encoding='UTF-8') as f:
  33. return f.read()
  34. readme = _read_file('README.md')
  35. def _write_version(file):
  36. file.write("__version__ = '{}'\n".format(version))
  37. def _write_config(file):
  38. file.write("__backend__ = '{}'\n".format(backend_policy))
  39. def _write_commit_file(file):
  40. file.write("__commit_id__ = '{}'\n".format(commit_id))
  41. def _write_package_name(file):
  42. file.write("__package_name__ = '{}'\n".format(package_name))
  43. def _write_device_target(file):
  44. file.write("__device_target__ = '{}'\n".format(device_target))
  45. def build_dependencies():
  46. """generate python file"""
  47. version_file = os.path.join(pkg_dir, 'mindspore', 'version.py')
  48. with open(version_file, 'w') as f:
  49. _write_version(f)
  50. version_file = os.path.join(pwd, 'mindspore', 'version.py')
  51. with open(version_file, 'w') as f:
  52. _write_version(f)
  53. config_file = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  54. with open(config_file, 'w') as f:
  55. _write_config(f)
  56. config_file = os.path.join(pwd, 'mindspore', 'default_config.py')
  57. with open(config_file, 'w') as f:
  58. _write_config(f)
  59. target = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  60. with open(target, 'a') as f:
  61. _write_device_target(f)
  62. target = os.path.join(pwd, 'mindspore', 'default_config.py')
  63. with open(target, 'a') as f:
  64. _write_device_target(f)
  65. package_info = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  66. with open(package_info, 'a') as f:
  67. _write_package_name(f)
  68. package_info = os.path.join(pwd, 'mindspore', 'default_config.py')
  69. with open(package_info, 'a') as f:
  70. _write_package_name(f)
  71. commit_file = os.path.join(pkg_dir, 'mindspore', '.commit_id')
  72. with open(commit_file, 'w') as f:
  73. _write_commit_file(f)
  74. commit_file = os.path.join(pwd, 'mindspore', '.commit_id')
  75. with open(commit_file, 'w') as f:
  76. _write_commit_file(f)
  77. build_dependencies()
  78. required_package = [
  79. 'numpy >= 1.17.0',
  80. 'protobuf >= 3.8.0',
  81. 'asttokens >= 1.1.13',
  82. 'pillow >= 6.2.0',
  83. 'scipy >= 1.5.2',
  84. 'easydict >= 1.9',
  85. 'sympy >= 1.4',
  86. 'cffi >= 1.12.3',
  87. 'wheel >= 0.32.0',
  88. 'decorator >= 4.4.0',
  89. 'setuptools >= 40.8.0',
  90. 'astunparse >= 1.6.3',
  91. 'packaging >= 20.0',
  92. 'psutil >= 5.6.1'
  93. ]
  94. package_data = {
  95. '': [
  96. '*.so*',
  97. '*.pyd',
  98. '*.dll',
  99. 'bin/*',
  100. 'lib/*.so*',
  101. 'lib/*.a',
  102. 'lib/*.dylib*',
  103. '.commit_id',
  104. 'config/*',
  105. 'include/*',
  106. 'include/*/*',
  107. 'include/*/*/*',
  108. 'include/*/*/*/*'
  109. ]
  110. }
  111. def update_permissions(path):
  112. """
  113. Update permissions.
  114. Args:
  115. path (str): Target directory path.
  116. """
  117. if platform.system() == "Windows":
  118. return
  119. for dirpath, dirnames, filenames in os.walk(path):
  120. for dirname in dirnames:
  121. dir_fullpath = os.path.join(dirpath, dirname)
  122. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE |
  123. stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  124. for filename in filenames:
  125. file_fullpath = os.path.join(dirpath, filename)
  126. os.chmod(file_fullpath, stat.S_IREAD)
  127. class EggInfo(egg_info):
  128. """Egg info."""
  129. def run(self):
  130. super().run()
  131. egg_info_dir = os.path.join(pkg_dir, 'mindspore.egg-info')
  132. update_permissions(egg_info_dir)
  133. class BuildPy(build_py):
  134. """BuildPy."""
  135. def run(self):
  136. super().run()
  137. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore')
  138. update_permissions(mindspore_dir)
  139. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore', '_akg')
  140. update_permissions(mindspore_dir)
  141. setup(
  142. name=package_name,
  143. version=version,
  144. author='The MindSpore Authors',
  145. author_email='contact@mindspore.cn',
  146. url='https://www.mindspore.cn',
  147. download_url='https://github.com/mindspore-ai/mindspore/tags',
  148. project_urls={
  149. 'Sources': 'https://github.com/mindspore-ai/mindspore',
  150. 'Issue Tracker': 'https://github.com/mindspore-ai/mindspore/issues',
  151. },
  152. description='MindSpore is a new open source deep learning training/inference '
  153. 'framework that could be used for mobile, edge and cloud scenarios.',
  154. long_description=readme,
  155. long_description_content_type="text/markdown",
  156. packages=find_packages(),
  157. package_data=package_data,
  158. include_package_data=True,
  159. cmdclass={
  160. 'egg_info': EggInfo,
  161. 'build_py': BuildPy,
  162. },
  163. entry_points={
  164. 'console_scripts': [
  165. 'cache_admin=mindspore.dataset.engine.cache_admin:main',
  166. ],
  167. },
  168. python_requires='>=3.7',
  169. install_requires=required_package,
  170. classifiers=[
  171. 'Development Status :: 4 - Beta',
  172. 'Environment :: Console',
  173. 'Intended Audience :: Science/Research',
  174. 'Intended Audience :: Developers',
  175. 'License :: OSI Approved :: Apache Software License',
  176. 'Programming Language :: Python :: 3 :: Only',
  177. 'Programming Language :: Python :: 3.7',
  178. 'Programming Language :: Python :: 3.8',
  179. 'Programming Language :: C++',
  180. 'Topic :: Scientific/Engineering',
  181. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  182. 'Topic :: Software Development',
  183. 'Topic :: Software Development :: Libraries',
  184. 'Topic :: Software Development :: Libraries :: Python Modules',
  185. ],
  186. license='Apache 2.0',
  187. keywords='mindspore machine learning',
  188. )