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

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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.0.1'
  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. release = _read_file('RELEASE.md')
  36. def _write_version(file):
  37. file.write("__version__ = '{}'\n".format(version))
  38. def _write_config(file):
  39. file.write("__backend__ = '{}'\n".format(backend_policy))
  40. def _write_commit_file(file):
  41. file.write("__commit_id__ = '{}'\n".format(commit_id))
  42. def _write_package_name(file):
  43. file.write("__package_name__ = '{}'\n".format(package_name))
  44. def _write_device_target(file):
  45. file.write("__device_target__ = '{}'\n".format(device_target))
  46. def build_dependencies():
  47. """generate python file"""
  48. version_file = os.path.join(pkg_dir, 'mindspore', 'version.py')
  49. with open(version_file, 'w') as f:
  50. _write_version(f)
  51. version_file = os.path.join(pwd, 'mindspore', 'version.py')
  52. with open(version_file, 'w') as f:
  53. _write_version(f)
  54. config_file = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  55. with open(config_file, 'w') as f:
  56. _write_config(f)
  57. config_file = os.path.join(pwd, 'mindspore', 'default_config.py')
  58. with open(config_file, 'w') as f:
  59. _write_config(f)
  60. target = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  61. with open(target, 'a') as f:
  62. _write_device_target(f)
  63. target = os.path.join(pwd, 'mindspore', 'default_config.py')
  64. with open(target, 'a') as f:
  65. _write_device_target(f)
  66. package_info = os.path.join(pkg_dir, 'mindspore', 'default_config.py')
  67. with open(package_info, 'a') as f:
  68. _write_package_name(f)
  69. package_info = os.path.join(pwd, 'mindspore', 'default_config.py')
  70. with open(package_info, 'a') as f:
  71. _write_package_name(f)
  72. commit_file = os.path.join(pkg_dir, 'mindspore', '.commit_id')
  73. with open(commit_file, 'w') as f:
  74. _write_commit_file(f)
  75. commit_file = os.path.join(pwd, 'mindspore', '.commit_id')
  76. with open(commit_file, 'w') as f:
  77. _write_commit_file(f)
  78. build_dependencies()
  79. required_package = [
  80. 'numpy >= 1.17.0, <= 1.17.5',
  81. 'protobuf >= 3.8.0',
  82. 'asttokens >= 1.1.13',
  83. 'pillow >= 6.2.0',
  84. 'scipy == 1.3.3',
  85. 'easydict >= 1.9',
  86. 'sympy >= 1.4',
  87. 'cffi >= 1.13.2',
  88. 'decorator >= 4.4.0',
  89. 'astunparse >= 1.6.3',
  90. 'packaging >= 20.0'
  91. ]
  92. package_data = {
  93. '': [
  94. '*.so*',
  95. '*.pyd',
  96. '*.dll',
  97. 'lib/*.so*',
  98. 'lib/*.a',
  99. '.commit_id',
  100. 'ms_serving'
  101. ]
  102. }
  103. def update_permissions(path):
  104. """
  105. Update permissions.
  106. Args:
  107. path (str): Target directory path.
  108. """
  109. if platform.system() == "Windows":
  110. return
  111. for dirpath, dirnames, filenames in os.walk(path):
  112. for dirname in dirnames:
  113. dir_fullpath = os.path.join(dirpath, dirname)
  114. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE |
  115. stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  116. for filename in filenames:
  117. file_fullpath = os.path.join(dirpath, filename)
  118. os.chmod(file_fullpath, stat.S_IREAD)
  119. if filename == "ms_serving":
  120. os.chmod(file_fullpath, stat.S_IREAD | stat.S_IEXEC)
  121. class EggInfo(egg_info):
  122. """Egg info."""
  123. def run(self):
  124. super().run()
  125. egg_info_dir = os.path.join(pkg_dir, 'mindspore.egg-info')
  126. update_permissions(egg_info_dir)
  127. class BuildPy(build_py):
  128. """BuildPy."""
  129. def run(self):
  130. super().run()
  131. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore')
  132. update_permissions(mindspore_dir)
  133. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'akg')
  134. update_permissions(mindspore_dir)
  135. setup(
  136. name=package_name,
  137. version=version,
  138. author='The MindSpore Authors',
  139. author_email='contact@mindspore.cn',
  140. url='https://www.mindspore.cn',
  141. download_url='https://gitee.com/mindspore/mindspore/tags',
  142. project_urls={
  143. 'Sources': 'https://gitee.com/mindspore/mindspore',
  144. 'Issue Tracker': 'https://gitee.com/mindspore/mindspore/issues',
  145. },
  146. description='MindSpore is a new open source deep learning training/inference '
  147. 'framework that could be used for mobile, edge and cloud scenarios.',
  148. long_description="\n\n".join([readme, release]),
  149. long_description_content_type="text/markdown",
  150. packages=find_packages(),
  151. package_data=package_data,
  152. include_package_data=True,
  153. cmdclass={
  154. 'egg_info': EggInfo,
  155. 'build_py': BuildPy,
  156. },
  157. python_requires='>=3.7',
  158. install_requires=required_package,
  159. classifiers=[
  160. 'Development Status :: 4 - Beta',
  161. 'Environment :: Console',
  162. 'Intended Audience :: Science/Research',
  163. 'Intended Audience :: Developers',
  164. 'License :: OSI Approved :: Apache Software License',
  165. 'Programming Language :: Python :: 3 :: Only',
  166. 'Programming Language :: Python :: 3.7',
  167. 'Programming Language :: Python :: 3.8',
  168. 'Programming Language :: C++',
  169. 'Topic :: Scientific/Engineering',
  170. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  171. 'Topic :: Software Development',
  172. 'Topic :: Software Development :: Libraries',
  173. 'Topic :: Software Development :: Libraries :: Python Modules',
  174. ],
  175. license='Apache 2.0',
  176. keywords='mindspore machine learning',
  177. )