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

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

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