您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. import importlib
  3. def run(bench_path):
  4. source_patch_file = os.path.join(
  5. os.path.dirname(os.path.abspath(__file__)), "patches.txt"
  6. )
  7. target_patch_file = os.path.join(os.path.abspath(bench_path), "patches.txt")
  8. with open(source_patch_file) as f:
  9. patches = [
  10. p.strip()
  11. for p in f.read().splitlines()
  12. if p.strip() and not p.strip().startswith("#")
  13. ]
  14. executed_patches = []
  15. if os.path.exists(target_patch_file):
  16. with open(target_patch_file) as f:
  17. executed_patches = f.read().splitlines()
  18. try:
  19. for patch in patches:
  20. if patch not in executed_patches:
  21. module = importlib.import_module(patch.split()[0])
  22. execute = getattr(module, "execute")
  23. result = execute(bench_path)
  24. if not result:
  25. executed_patches.append(patch)
  26. finally:
  27. with open(target_patch_file, "w") as f:
  28. f.write("\n".join(executed_patches))
  29. # end with an empty line
  30. f.write("\n")