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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. # Copyright 2019-2021 Huawei Technologies Co., Ltd.All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Setup."""
  16. import sys
  17. import os
  18. import shutil
  19. import stat
  20. import platform
  21. import shlex
  22. import subprocess
  23. import types
  24. from importlib import import_module
  25. from setuptools import setup
  26. from setuptools.command.egg_info import egg_info
  27. from setuptools.command.build_py import build_py
  28. from setuptools.command.install import install
  29. def get_version():
  30. """
  31. Get version.
  32. Returns:
  33. str, mindinsight version.
  34. """
  35. machinery = import_module('importlib.machinery')
  36. module_path = os.path.join(os.path.dirname(__file__), 'mindinsight', '_version.py')
  37. module_name = '__mindinsightversion__'
  38. version_module = types.ModuleType(module_name)
  39. loader = machinery.SourceFileLoader(module_name, module_path)
  40. loader.exec_module(version_module)
  41. return version_module.VERSION
  42. def get_platform():
  43. """
  44. Get platform name.
  45. Returns:
  46. str, platform name in lowercase.
  47. """
  48. return platform.system().strip().lower()
  49. def get_description():
  50. """
  51. Get description.
  52. Returns:
  53. str, wheel package description.
  54. """
  55. os_info = get_platform()
  56. cpu_info = platform.machine().strip()
  57. cmd = "git log --format='[sha1]:%h, [branch]:%d' -1"
  58. process = subprocess.Popen(
  59. shlex.split(cmd),
  60. shell=False,
  61. stdin=subprocess.PIPE,
  62. stdout=subprocess.PIPE,
  63. stderr=subprocess.PIPE
  64. )
  65. stdout, _ = process.communicate()
  66. if not process.returncode:
  67. git_version = stdout.decode().strip()
  68. return 'mindinsight platform: %s, cpu: %s, git version: %s' % (os_info, cpu_info, git_version)
  69. return 'mindinsight platform: %s, cpu: %s' % (os_info, cpu_info)
  70. def get_install_requires():
  71. """
  72. Get install requirements.
  73. Returns:
  74. list, list of dependent packages.
  75. """
  76. with open('requirements.txt') as file:
  77. return file.read().strip().splitlines()
  78. def update_permissions(path):
  79. """
  80. Update permissions.
  81. Args:
  82. path (str): Target directory path.
  83. """
  84. for dirpath, dirnames, filenames in os.walk(path):
  85. for dirname in dirnames:
  86. dir_fullpath = os.path.join(dirpath, dirname)
  87. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  88. for filename in filenames:
  89. file_fullpath = os.path.join(dirpath, filename)
  90. os.chmod(file_fullpath, stat.S_IREAD)
  91. def run_script(script):
  92. """
  93. Run script.
  94. Args:
  95. script (str): Target script file path.
  96. Returns:
  97. int, return code.
  98. """
  99. cmd = '/bin/bash {}'.format(script)
  100. process = subprocess.Popen(
  101. shlex.split(cmd),
  102. shell=False
  103. )
  104. return process.wait()
  105. def build_dependencies():
  106. """Build dependencies."""
  107. build_dir = os.path.join(os.path.dirname(__file__), 'build')
  108. sys.stdout.write('building crc32 ...\n')
  109. crc32_script = os.path.join(build_dir, 'scripts', 'crc32.sh')
  110. rc = run_script(crc32_script)
  111. if rc:
  112. sys.stdout.write('building crc32 failure\n')
  113. sys.exit(1)
  114. sys.stdout.write('building ui ...\n')
  115. ui_script = os.path.join(build_dir, 'scripts', 'ui.sh')
  116. rc = run_script(ui_script)
  117. if rc:
  118. sys.stdout.write('building ui failure\n')
  119. sys.exit(1)
  120. class EggInfo(egg_info):
  121. """Egg info."""
  122. def run(self):
  123. build_dependencies()
  124. egg_info_dir = os.path.join(os.path.dirname(__file__), 'mindinsight.egg-info')
  125. shutil.rmtree(egg_info_dir, ignore_errors=True)
  126. super().run()
  127. update_permissions(egg_info_dir)
  128. class BuildPy(build_py):
  129. """Build py files."""
  130. def run(self):
  131. mindinsight_lib_dir = os.path.join(os.path.dirname(__file__), 'build', 'lib', 'mindinsight')
  132. shutil.rmtree(mindinsight_lib_dir, ignore_errors=True)
  133. super().run()
  134. update_permissions(mindinsight_lib_dir)
  135. class Install(install):
  136. """Install."""
  137. def run(self):
  138. super().run()
  139. if sys.argv[-1] == 'install':
  140. pip = import_module('pip')
  141. mindinsight_dir = os.path.join(os.path.dirname(pip.__path__[0]), 'mindinsight')
  142. update_permissions(mindinsight_dir)
  143. if __name__ == '__main__':
  144. version_info = sys.version_info
  145. if (version_info.major, version_info.minor) < (3, 7):
  146. sys.stderr.write('Python version should be at least 3.7\r\n')
  147. sys.exit(1)
  148. setup(
  149. name='mindinsight',
  150. version=get_version(),
  151. author='The MindSpore Authors',
  152. author_email='contact@mindspore.cn',
  153. url='https://www.mindspore.cn',
  154. download_url='https://gitee.com/mindspore/mindinsight/tags',
  155. project_urls={
  156. 'Sources': 'https://gitee.com/mindspore/mindinsight',
  157. 'Issue Tracker': 'https://gitee.com/mindspore/mindinsight/issues',
  158. },
  159. description=get_description(),
  160. packages=['mindinsight'],
  161. platforms=[get_platform()],
  162. include_package_data=True,
  163. cmdclass={
  164. 'egg_info': EggInfo,
  165. 'build_py': BuildPy,
  166. 'install': Install,
  167. },
  168. entry_points={
  169. 'console_scripts': [
  170. 'mindinsight=mindinsight.utils.command:main',
  171. 'mindconverter=mindinsight.mindconverter.cli:cli_entry',
  172. 'mindwizard=mindinsight.wizard.cli:cli_entry',
  173. 'mindoptimizer=mindinsight.optimizer.cli:cli_entry',
  174. ],
  175. },
  176. python_requires='>=3.7',
  177. install_requires=get_install_requires(),
  178. classifiers=[
  179. 'Development Status :: 5 - Production/Stable',
  180. 'Environment :: Console',
  181. 'Environment :: Web Environment',
  182. 'Intended Audience :: Science/Research',
  183. 'Intended Audience :: Developers',
  184. 'License :: OSI Approved :: Apache Software License',
  185. 'Programming Language :: Python :: 3 :: Only',
  186. 'Programming Language :: Python :: 3.7',
  187. 'Programming Language :: Python :: 3.8',
  188. 'Programming Language :: Python :: 3.9',
  189. 'Topic :: Scientific/Engineering',
  190. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  191. 'Topic :: Software Development',
  192. 'Topic :: Software Development :: Libraries',
  193. 'Topic :: Software Development :: Libraries :: Python Modules',
  194. ],
  195. license='Apache 2.0',
  196. keywords='mindinsight',
  197. )