cythonize.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. 用于python源码打包成so文件,python解释器运行main.py
  3. """
  4. from distutils.core import setup
  5. from Cython.Build import cythonize
  6. import os
  7. py_dir = [
  8. '/home/server/projects/taiwuict/cscec-8bur-vms/build/component-interface',
  9. '/home/server/projects/taiwuict/cscec-8bur-vms/build/supplement-python',
  10. ]
  11. def get_file_path_list(dir_path, path_list=None):
  12. if not path_list:
  13. path_list = []
  14. for path, folders, files in os.walk(dir_path):
  15. for file_name in files:
  16. if file_name[-2:] != 'py':
  17. continue
  18. if 'cythonize' in file_name:
  19. continue
  20. # if '__init__' in file_name:
  21. # continue
  22. file_path = os.path.join(path, file_name)
  23. if file_path in path_list:
  24. continue
  25. path_list.append(file_path)
  26. for folder_name in folders:
  27. get_file_path_list(os.path.join(path, folder_name), path_list)
  28. return path_list
  29. py_list = []
  30. for dir in py_dir:
  31. py_list += get_file_path_list(dir)
  32. print(py_list)
  33. # setup(ext_modules=cythonize(module_list=py_list,
  34. # compiler_directives=dict(c_string_encoding="utf-8", language_level=3)))
  35. # --- one by one ---
  36. for py_file in py_list:
  37. setup(
  38. name='fra',
  39. package_dir={
  40. 'v3': '',
  41. 'base_original': '',
  42. },
  43. ext_modules=cythonize(module_list=[py_file],
  44. compiler_directives=dict(c_string_encoding="utf-8", language_level=3)))