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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 = '1.1.0'
  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), encoding='UTF-8') 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 _write_package_name(file):
  42. file.write("__package_name__ = '{}'\n".format(package_name))
  43. def build_dependencies():
  44. """generate python file"""
  45. version_file = os.path.join(pkg_dir, 'mindspore_serving', 'version.py')
  46. with open(version_file, 'w') as f:
  47. _write_version(f)
  48. version_file = os.path.join(pwd, 'mindspore_serving', 'version.py')
  49. with open(version_file, 'w') as f:
  50. _write_version(f)
  51. config_file = os.path.join(pkg_dir, 'mindspore_serving', 'default_config.py')
  52. with open(config_file, 'w') as f:
  53. _write_config(f)
  54. config_file = os.path.join(pwd, 'mindspore_serving', 'default_config.py')
  55. with open(config_file, 'w') as f:
  56. _write_config(f)
  57. package_info = os.path.join(pkg_dir, 'mindspore_serving', 'default_config.py')
  58. with open(package_info, 'a') as f:
  59. _write_package_name(f)
  60. package_info = os.path.join(pwd, 'mindspore_serving', 'default_config.py')
  61. with open(package_info, 'a') as f:
  62. _write_package_name(f)
  63. commit_file = os.path.join(pkg_dir, 'mindspore_serving', '.commit_id')
  64. with open(commit_file, 'w') as f:
  65. _write_commit_file(f)
  66. commit_file = os.path.join(pwd, 'mindspore_serving', '.commit_id')
  67. with open(commit_file, 'w') as f:
  68. _write_commit_file(f)
  69. build_dependencies()
  70. required_package = [
  71. 'numpy >= 1.17.0',
  72. 'protobuf >= 3.8.0',
  73. 'grpcio >= 1.27.3'
  74. ]
  75. package_data = {
  76. '': [
  77. '*.so*',
  78. '*.pyd',
  79. '*.dll',
  80. 'lib/*.so*',
  81. 'lib/*.a',
  82. '.commit_id',
  83. '_mindspore_serving',
  84. 'proto/*.py'
  85. ]
  86. }
  87. def update_permissions(path):
  88. """
  89. Update permissions.
  90. Args:
  91. path (str): Target directory path.
  92. """
  93. if platform.system() == "Windows":
  94. return
  95. for dirpath, dirnames, filenames in os.walk(path):
  96. for dirname in dirnames:
  97. dir_fullpath = os.path.join(dirpath, dirname)
  98. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE |
  99. stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  100. for filename in filenames:
  101. file_fullpath = os.path.join(dirpath, filename)
  102. os.chmod(file_fullpath, stat.S_IREAD)
  103. def bin_files():
  104. """
  105. Gets the binary files to be installed.
  106. """
  107. data_files = []
  108. binary_files = []
  109. cache_server_bin = os.path.join('mindspore_serving', 'bin', 'cache_server')
  110. if not os.path.exists(cache_server_bin):
  111. return data_files
  112. binary_files.append(cache_server_bin)
  113. cache_admin_bin = os.path.join('mindspore_serving', 'bin', 'cache_admin')
  114. if not os.path.exists(cache_admin_bin):
  115. return data_files
  116. binary_files.append(cache_admin_bin)
  117. data_files.append(('bin', binary_files))
  118. return data_files
  119. class EggInfo(egg_info):
  120. """Egg info."""
  121. def run(self):
  122. super().run()
  123. egg_info_dir = os.path.join(pkg_dir, 'mindspore_serving.egg-info')
  124. update_permissions(egg_info_dir)
  125. class BuildPy(build_py):
  126. """BuildPy."""
  127. def run(self):
  128. super().run()
  129. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'mindspore_serving')
  130. update_permissions(mindspore_dir)
  131. mindspore_dir = os.path.join(pkg_dir, 'build', 'lib', 'akg')
  132. update_permissions(mindspore_dir)
  133. setup(
  134. name=package_name,
  135. version=version,
  136. author='The MindSpore Authors',
  137. author_email='contact@mindspore.cn',
  138. url='https://www.mindspore.cn',
  139. download_url='https://gitee.com/mindspore/serving/tags',
  140. project_urls={
  141. 'Sources': 'https://gitee.com/mindspore/serving',
  142. 'Issue Tracker': 'https://gitee.com/mindspore/serving/issues',
  143. },
  144. description='MindSpore is a new open source deep learning training/inference '
  145. 'framework that could be used for mobile, edge and cloud scenarios.',
  146. # long_description="\n\n".join([readme, release]),
  147. long_description="\n\n".join([readme]),
  148. long_description_content_type="text/markdown",
  149. data_files=bin_files(),
  150. packages=find_packages(),
  151. package_data=package_data,
  152. include_package_data=True,
  153. cmdclass={
  154. 'egg_info': EggInfo,
  155. 'build_py': BuildPy,
  156. },
  157. python_requires='>=3.7',
  158. install_requires=required_package,
  159. classifiers=[
  160. 'Development Status :: 4 - Beta',
  161. 'Environment :: Console',
  162. 'Intended Audience :: Science/Research',
  163. 'Intended Audience :: Developers',
  164. 'License :: OSI Approved :: Apache Software License',
  165. 'Programming Language :: Python :: 3 :: Only',
  166. 'Programming Language :: Python :: 3.7',
  167. 'Programming Language :: Python :: 3.8',
  168. 'Programming Language :: C++',
  169. 'Topic :: Scientific/Engineering',
  170. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  171. 'Topic :: Software Development',
  172. 'Topic :: Software Development :: Libraries',
  173. 'Topic :: Software Development :: Libraries :: Python Modules',
  174. ],
  175. license='Apache 2.0',
  176. keywords='mindspore machine learning',
  177. )

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.