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
4 years ago
5 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. backend_policy = os.getenv('BACKEND_POLICY')
  25. device_target = os.getenv('BACKEND_TARGET')
  26. commit_id = os.getenv('COMMIT_ID').replace("\n", "")
  27. package_name = os.getenv('MS_PACKAGE_NAME').replace("\n", "")
  28. build_path = os.getenv('BUILD_PATH')
  29. pwd = os.path.dirname(os.path.realpath(__file__))
  30. pkg_dir = os.path.join(build_path, 'package')
  31. def _read_file(filename):
  32. with open(os.path.join(pwd, filename), encoding='UTF-8') as f:
  33. return f.read()
  34. version = _read_file('version.txt').replace("\n", "")
  35. readme = _read_file('README.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/python/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/python/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/python/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/python/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/python/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',
  81. 'protobuf >= 3.13.0',
  82. 'asttokens >= 2.0.0',
  83. 'pillow >= 6.2.0',
  84. 'scipy >= 1.5.2',
  85. 'packaging >= 20.0',
  86. 'psutil >= 5.6.1'
  87. ]
  88. package_data = {
  89. '': [
  90. '*.so*',
  91. '*.pyd',
  92. '*.dll',
  93. 'bin/*',
  94. 'lib/*.so*',
  95. 'lib/*.a',
  96. 'lib/*.dylib*',
  97. '.commit_id',
  98. 'config/*',
  99. 'ops/bprop_mindir/*',
  100. 'include/*',
  101. 'include/*/*',
  102. 'include/*/*/*',
  103. 'include/*/*/*/*'
  104. ]
  105. }
  106. def update_permissions(path):
  107. """
  108. Update permissions.
  109. Args:
  110. path (str): Target directory path.
  111. """
  112. if platform.system() == "Windows":
  113. return
  114. for dirpath, dirnames, filenames in os.walk(path):
  115. for dirname in dirnames:
  116. dir_fullpath = os.path.join(dirpath, dirname)
  117. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE |
  118. stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  119. for filename in filenames:
  120. file_fullpath = os.path.join(dirpath, filename)
  121. os.chmod(file_fullpath, stat.S_IREAD)
  122. class EggInfo(egg_info):
  123. """Egg info."""
  124. def run(self):
  125. super().run()
  126. egg_info_dir = os.path.join(pkg_dir, 'mindspore.egg-info')
  127. update_permissions(egg_info_dir)
  128. class BuildPy(build_py):
  129. """BuildPy."""
  130. def run(self):
  131. super().run()
  132. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore')
  133. update_permissions(mindspore_dir)
  134. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore', '_akg')
  135. update_permissions(mindspore_dir)
  136. setup(
  137. name=package_name,
  138. version=version,
  139. author='The MindSpore Authors',
  140. author_email='contact@mindspore.cn',
  141. url='https://www.mindspore.cn',
  142. download_url='https://github.com/mindspore-ai/mindspore/tags',
  143. project_urls={
  144. 'Sources': 'https://github.com/mindspore-ai/mindspore',
  145. 'Issue Tracker': 'https://github.com/mindspore-ai/mindspore/issues',
  146. },
  147. description='MindSpore is a new open source deep learning training/inference '
  148. 'framework that could be used for mobile, edge and cloud scenarios.',
  149. long_description=readme,
  150. long_description_content_type="text/markdown",
  151. packages=find_packages(),
  152. package_data=package_data,
  153. include_package_data=True,
  154. cmdclass={
  155. 'egg_info': EggInfo,
  156. 'build_py': BuildPy,
  157. },
  158. entry_points={
  159. 'console_scripts': [
  160. 'cache_admin=mindspore.dataset.engine.cache_admin:main',
  161. ],
  162. },
  163. python_requires='>=3.7',
  164. install_requires=required_package,
  165. classifiers=[
  166. 'Development Status :: 4 - Beta',
  167. 'Environment :: Console',
  168. 'Intended Audience :: Science/Research',
  169. 'Intended Audience :: Developers',
  170. 'License :: OSI Approved :: Apache Software License',
  171. 'Programming Language :: Python :: 3 :: Only',
  172. 'Programming Language :: Python :: 3.7',
  173. 'Programming Language :: Python :: 3.8',
  174. 'Programming Language :: C++',
  175. 'Topic :: Scientific/Engineering',
  176. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  177. 'Topic :: Software Development',
  178. 'Topic :: Software Development :: Libraries',
  179. 'Topic :: Software Development :: Libraries :: Python Modules',
  180. ],
  181. license='Apache 2.0',
  182. keywords='mindspore machine learning',
  183. )