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.5 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
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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_readme_content():
  30. pwd = os.path.dirname(os.path.realpath(__file__))
  31. with open(os.path.join(pwd, 'README.md'), encoding='UTF-8') as f:
  32. return f.read()
  33. def get_version():
  34. """
  35. Get version.
  36. Returns:
  37. str, mindinsight version.
  38. """
  39. machinery = import_module('importlib.machinery')
  40. module_path = os.path.join(os.path.dirname(__file__), 'mindinsight', '_version.py')
  41. module_name = '__mindinsightversion__'
  42. version_module = types.ModuleType(module_name)
  43. loader = machinery.SourceFileLoader(module_name, module_path)
  44. loader.exec_module(version_module)
  45. return version_module.VERSION
  46. def get_platform():
  47. """
  48. Get platform name.
  49. Returns:
  50. str, platform name in lowercase.
  51. """
  52. return platform.system().strip().lower()
  53. def get_description():
  54. """
  55. Get description.
  56. Returns:
  57. str, wheel package description.
  58. """
  59. os_info = get_platform()
  60. cpu_info = platform.machine().strip()
  61. cmd = "git log --format='[sha1]:%h, [branch]:%d' -1"
  62. process = subprocess.Popen(
  63. shlex.split(cmd),
  64. shell=False,
  65. stdin=subprocess.PIPE,
  66. stdout=subprocess.PIPE,
  67. stderr=subprocess.PIPE
  68. )
  69. stdout, _ = process.communicate()
  70. if not process.returncode:
  71. git_version = stdout.decode().strip()
  72. return 'mindinsight platform: %s, cpu: %s, git version: %s' % (os_info, cpu_info, git_version)
  73. return 'mindinsight platform: %s, cpu: %s' % (os_info, cpu_info)
  74. def get_install_requires():
  75. """
  76. Get install requirements.
  77. Returns:
  78. list, list of dependent packages.
  79. """
  80. with open('requirements.txt') as file:
  81. return file.read().strip().splitlines()
  82. def update_permissions(path):
  83. """
  84. Update permissions.
  85. Args:
  86. path (str): Target directory path.
  87. """
  88. for dirpath, dirnames, filenames in os.walk(path):
  89. for dirname in dirnames:
  90. dir_fullpath = os.path.join(dirpath, dirname)
  91. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  92. for filename in filenames:
  93. file_fullpath = os.path.join(dirpath, filename)
  94. os.chmod(file_fullpath, stat.S_IREAD)
  95. def run_script(script):
  96. """
  97. Run script.
  98. Args:
  99. script (str): Target script file path.
  100. Returns:
  101. int, return code.
  102. """
  103. cmd = '/bin/bash {}'.format(script)
  104. process = subprocess.Popen(
  105. shlex.split(cmd),
  106. shell=False
  107. )
  108. return process.wait()
  109. def build_dependencies():
  110. """Build dependencies."""
  111. build_dir = os.path.join(os.path.dirname(__file__), 'build')
  112. sys.stdout.write('building crc32 ...\n')
  113. crc32_script = os.path.join(build_dir, 'scripts', 'crc32.sh')
  114. rc = run_script(crc32_script)
  115. if rc:
  116. sys.stdout.write('building crc32 failure\n')
  117. sys.exit(1)
  118. sys.stdout.write('building ui ...\n')
  119. ui_script = os.path.join(build_dir, 'scripts', 'ui.sh')
  120. rc = run_script(ui_script)
  121. if rc:
  122. sys.stdout.write('building ui failure\n')
  123. sys.exit(1)
  124. class EggInfo(egg_info):
  125. """Egg info."""
  126. def run(self):
  127. build_dependencies()
  128. egg_info_dir = os.path.join(os.path.dirname(__file__), 'mindinsight.egg-info')
  129. shutil.rmtree(egg_info_dir, ignore_errors=True)
  130. super().run()
  131. update_permissions(egg_info_dir)
  132. class BuildPy(build_py):
  133. """Build py files."""
  134. def run(self):
  135. mindinsight_lib_dir = os.path.join(os.path.dirname(__file__), 'build', 'lib', 'mindinsight')
  136. shutil.rmtree(mindinsight_lib_dir, ignore_errors=True)
  137. super().run()
  138. update_permissions(mindinsight_lib_dir)
  139. class Install(install):
  140. """Install."""
  141. def run(self):
  142. super().run()
  143. if sys.argv[-1] == 'install':
  144. pip = import_module('pip')
  145. mindinsight_dir = os.path.join(os.path.dirname(pip.__path__[0]), 'mindinsight')
  146. update_permissions(mindinsight_dir)
  147. if __name__ == '__main__':
  148. version_info = sys.version_info
  149. if (version_info.major, version_info.minor) < (3, 7):
  150. sys.stderr.write('Python version should be at least 3.7\r\n')
  151. sys.exit(1)
  152. setup(
  153. name='mindinsight',
  154. version=get_version(),
  155. author='The MindSpore Authors',
  156. author_email='contact@mindspore.cn',
  157. url='https://www.mindspore.cn',
  158. download_url='https://gitee.com/mindspore/mindinsight/tags',
  159. project_urls={
  160. 'Sources': 'https://gitee.com/mindspore/mindinsight',
  161. 'Issue Tracker': 'https://gitee.com/mindspore/mindinsight/issues',
  162. },
  163. description=get_description(),
  164. long_description=get_readme_content(),
  165. long_description_content_type="text/markdown",
  166. packages=['mindinsight'],
  167. platforms=[get_platform()],
  168. include_package_data=True,
  169. cmdclass={
  170. 'egg_info': EggInfo,
  171. 'build_py': BuildPy,
  172. 'install': Install,
  173. },
  174. entry_points={
  175. 'console_scripts': [
  176. 'mindinsight=mindinsight.utils.command:main',
  177. 'mindconverter=mindinsight.mindconverter.cli:cli_entry',
  178. 'mindwizard=mindinsight.wizard.cli:cli_entry',
  179. 'mindoptimizer=mindinsight.optimizer.cli:cli_entry',
  180. ],
  181. },
  182. python_requires='>=3.7',
  183. install_requires=get_install_requires(),
  184. classifiers=[
  185. 'Development Status :: 5 - Production/Stable',
  186. 'Environment :: Console',
  187. 'Environment :: Web Environment',
  188. 'Intended Audience :: Science/Research',
  189. 'Intended Audience :: Developers',
  190. 'License :: OSI Approved :: Apache Software License',
  191. 'Programming Language :: Python :: 3 :: Only',
  192. 'Programming Language :: Python :: 3.7',
  193. 'Programming Language :: Python :: 3.8',
  194. 'Programming Language :: Python :: 3.9',
  195. 'Topic :: Scientific/Engineering',
  196. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  197. 'Topic :: Software Development',
  198. 'Topic :: Software Development :: Libraries',
  199. 'Topic :: Software Development :: Libraries :: Python Modules',
  200. ],
  201. license='Apache 2.0',
  202. keywords='mindinsight',
  203. )