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

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