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

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