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