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 4.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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  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. import os
  15. import stat
  16. import shlex
  17. import shutil
  18. import subprocess
  19. from setuptools import find_packages
  20. from setuptools import setup
  21. from setuptools.command.egg_info import egg_info
  22. from setuptools.command.build_py import build_py
  23. version = '1.6.0'
  24. cur_dir = os.path.dirname(os.path.realpath(__file__))
  25. pkg_dir = os.path.join(cur_dir, 'build')
  26. def clean():
  27. # pylint: disable=unused-argument
  28. def readonly_handler(func, path, execinfo):
  29. os.chmod(path, stat.S_IWRITE)
  30. func(path)
  31. if os.path.exists(os.path.join(cur_dir, 'build')):
  32. shutil.rmtree(os.path.join(cur_dir, 'build'), onerror=readonly_handler)
  33. if os.path.exists(os.path.join(cur_dir, 'mindarmour.egg-info')):
  34. shutil.rmtree(os.path.join(cur_dir, 'mindarmour.egg-info'), onerror=readonly_handler)
  35. def write_version(file):
  36. file.write("__version__ = '{}'\n".format(version))
  37. def build_depends():
  38. """generate python file"""
  39. version_file = os.path.join(cur_dir, 'mindarmour/', 'version.py')
  40. with open(version_file, 'w') as f:
  41. write_version(f)
  42. clean()
  43. build_depends()
  44. def update_permissions(path):
  45. """
  46. Update permissions.
  47. Args:
  48. path (str): Target directory path.
  49. """
  50. for dirpath, dirnames, filenames in os.walk(path):
  51. for dirname in dirnames:
  52. dir_fullpath = os.path.join(dirpath, dirname)
  53. os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
  54. for filename in filenames:
  55. file_fullpath = os.path.join(dirpath, filename)
  56. os.chmod(file_fullpath, stat.S_IREAD)
  57. def get_description():
  58. """
  59. Get description.
  60. Returns:
  61. str, wheel package description.
  62. """
  63. cmd = "git log --format='[sha1]:%h, [branch]:%d' -1"
  64. process = subprocess.Popen(
  65. shlex.split(cmd),
  66. shell=False,
  67. stdin=subprocess.PIPE,
  68. stdout=subprocess.PIPE,
  69. stderr=subprocess.PIPE
  70. )
  71. stdout, _ = process.communicate()
  72. if not process.returncode:
  73. git_version = stdout.decode().strip()
  74. return "A smart AI security and trustworthy tool box. Git version: %s" % (git_version)
  75. return "A smart AI security and trustworthy tool box."
  76. class EggInfo(egg_info):
  77. """Egg info."""
  78. def run(self):
  79. super().run()
  80. egg_info_dir = os.path.join(cur_dir, 'mindarmour.egg-info')
  81. update_permissions(egg_info_dir)
  82. class BuildPy(build_py):
  83. """BuildPy."""
  84. def run(self):
  85. super().run()
  86. mindarmour_dir = os.path.join(pkg_dir, 'lib', 'mindarmour')
  87. update_permissions(mindarmour_dir)
  88. setup(
  89. name='mindarmour',
  90. version=version,
  91. author='The MindSpore Authors',
  92. author_email='contact@mindspore.cn',
  93. url='https://www.mindspore.cn/',
  94. download_url='https://gitee.com/mindspore/mindarmour/tags',
  95. project_urls={
  96. 'Sources': 'https://gitee.com/mindspore/mindarmour',
  97. 'Issue Tracker': 'https://gitee.com/mindspore/mindarmour/issues',
  98. },
  99. description=get_description(),
  100. license='Apache 2.0',
  101. packages=find_packages(),
  102. include_package_data=True,
  103. cmdclass={
  104. 'egg_info': EggInfo,
  105. 'build_py': BuildPy,
  106. },
  107. install_requires=[
  108. 'scipy >= 1.5.2',
  109. 'numpy >= 1.17.0',
  110. 'matplotlib >= 3.2.1',
  111. 'pillow >= 7.2.0',
  112. 'scikit-learn >= 0.23.1',
  113. 'easydict >= 1.9',
  114. 'opencv-python >= 4.1.2.30',
  115. ],
  116. classifiers=[
  117. 'License :: OSI Approved :: Apache Software License'
  118. ]
  119. )
  120. print(find_packages())

MindArmour关注AI的安全和隐私问题。致力于增强模型的安全可信、保护用户的数据隐私。主要包含3个模块:对抗样本鲁棒性模块、Fuzz Testing模块、隐私保护与评估模块。 对抗样本鲁棒性模块 对抗样本鲁棒性模块用于评估模型对于对抗样本的鲁棒性,并提供模型增强方法用于增强模型抗对抗样本攻击的能力,提升模型鲁棒性。对抗样本鲁棒性模块包含了4个子模块:对抗样本的生成、对抗样本的检测、模型防御、攻防评估。