setup_encrypt.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from setuptools import setup
  2. from Cython.Build import cythonize, build_ext
  3. from distutils.extension import Extension
  4. import os
  5. import sys
  6. import shutil
  7. class KitBuildExt(build_ext):
  8. def run(self):
  9. build_ext.run(self)
  10. if __name__ == '__main__':
  11. # 参数
  12. rel_path = os.path.dirname(os.path.abspath(__file__))
  13. project_name_tmp = (os.path.abspath(__file__).split('/')[-6] + '_common').replace("_","-").split("-")
  14. project_name = "".join([x.capitalize() for x in project_name_tmp])
  15. with open(os.path.join(rel_path, 'ver'),'r') as f:
  16. ver = int(f.readline())
  17. version = f"1.0.{ver}"
  18. # 获取待加密的问价
  19. file_to_encrypt_list = [] # 待加密的lib文件列表
  20. if os.path.exists(os.path.join(rel_path,project_name)):
  21. for root,dir,files in os.walk(os.path.join(rel_path,project_name)): # 遍历文件夹下的py文件
  22. if 'iotp_proto' not in root:
  23. for f in files:
  24. if f.endswith(".py") and f != '__init__.py':
  25. file_to_encrypt_list.append(os.path.join(root, f))
  26. with open(os.path.join(rel_path,"MANIFEST.in"), "w", encoding="utf-8") as fh: # 打包pyd 需要该文件
  27. fh.writelines(f"recursive-include {project_name} *.pyd *.h5 *.pkl *.so")
  28. setup(
  29. name=project_name,
  30. version=version,
  31. ext_modules=cythonize(file_to_encrypt_list,compiler_directives={'language_level': 3}),
  32. cmdclass=dict(build_ext=KitBuildExt)
  33. )