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_package.py 4.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. from setuptools import setup, find_packages
  21. from setuptools.command.egg_info import egg_info
  22. from setuptools.command.build_py import build_py
  23. version = '0.1.0'
  24. author = 'The MindSpore Authors'
  25. author_email = 'contact@mindspore.cn'
  26. home_page = 'https://www.mindspore.cn'
  27. backend_policy = os.getenv('BACKEND_POLICY')
  28. commit_id = os.getenv('COMMIT_ID').replace("\n", "")
  29. package_name = os.getenv('MS_PACKAGE_NAME').replace("\n", "")
  30. pwd = os.path.dirname(os.path.realpath(__file__))
  31. pkg_dir = os.path.join(pwd, 'build/package')
  32. def write_version(file):
  33. file.write("__version__ = '{}'\n".format(version))
  34. def write_config(file):
  35. file.write("__backend__ = '{}'\n".format(backend_policy))
  36. def write_commit_file(file):
  37. file.write("__commit_id__ = '{}'\n".format(commit_id))
  38. def build_depends():
  39. """generate python file"""
  40. version_file = os.path.join(pwd, 'build/package/mindspore', 'version.py')
  41. with open(version_file, 'w') as f:
  42. write_version(f)
  43. version_file = os.path.join(pwd, 'mindspore/', 'version.py')
  44. with open(version_file, 'w') as f:
  45. write_version(f)
  46. config_file = os.path.join(pwd, 'build/package/mindspore', 'default_config.py')
  47. with open(config_file, 'w') as f:
  48. write_config(f)
  49. config_file = os.path.join(pwd, 'mindspore/', 'default_config.py')
  50. with open(config_file, 'w') as f:
  51. write_config(f)
  52. commit_file = os.path.join(pwd, 'build/package/mindspore', '.commit_id')
  53. with open(commit_file, 'w') as f:
  54. write_commit_file(f)
  55. commit_file = os.path.join(pwd, 'mindspore/', '.commit_id')
  56. with open(commit_file, 'w') as f:
  57. write_commit_file(f)
  58. descriptions = 'An AI computing framework that supports development for AI applications in all scenarios.'
  59. requires = [
  60. 'numpy >= 1.17.0',
  61. 'protobuf >= 3.8.0',
  62. 'asttokens >= 1.1.13',
  63. 'pillow >= 6.2.0',
  64. 'scipy == 1.3.3',
  65. 'easydict >= 1.9',
  66. 'sympy >= 1.4',
  67. 'cffi >= 1.13.2',
  68. 'decorator >= 4.4.0'
  69. ],
  70. package_datas = {
  71. '': [
  72. '*.so*',
  73. 'lib/*.so*',
  74. 'lib/*.a',
  75. '.commit_id',
  76. ]
  77. }
  78. build_depends()
  79. def update_permissions(path):
  80. """
  81. Update permissions.
  82. Args:
  83. path (str): Target directory path.
  84. """
  85. for dirpath, dirnames, filenames in os.walk(path):
  86. for dirname in dirnames:
  87. dir_fullpath = os.path.join(dirpath, dirname)
  88. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  89. for filename in filenames:
  90. file_fullpath = os.path.join(dirpath, filename)
  91. os.chmod(file_fullpath, stat.S_IREAD)
  92. class EggInfo(egg_info):
  93. """Egg info."""
  94. def run(self):
  95. super().run()
  96. egg_info_dir = os.path.join(pkg_dir, 'mindspore.egg-info')
  97. update_permissions(egg_info_dir)
  98. class BuildPy(build_py):
  99. """BuildPy."""
  100. def run(self):
  101. super().run()
  102. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore')
  103. update_permissions(mindspore_dir)
  104. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'akg')
  105. update_permissions(mindspore_dir)
  106. setup(
  107. python_requires='>=3.7',
  108. name=package_name,
  109. version=version,
  110. author=author,
  111. author_email=author_email,
  112. url=home_page,
  113. packages=find_packages(),
  114. package_data=package_datas,
  115. include_package_data=True,
  116. cmdclass={
  117. 'egg_info': EggInfo,
  118. 'build_py': BuildPy,
  119. },
  120. install_requires=requires,
  121. description=descriptions,
  122. license='Apache 2.0',
  123. )