generate_requirements.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import argparse
  5. import subprocess
  6. import time
  7. from module.logger import logger
  8. def generate(qml: bool=False):
  9. content = ''
  10. if not qml:
  11. with open("requirements-in.txt", "r", encoding="utf-8") as f:
  12. content = f.read()
  13. content = content.replace("pyside6==6.4.3\n", "")
  14. with open("requirements-in.txt", "w", encoding="utf-8") as f:
  15. f.write(content)
  16. logger.info("requirements-in.txt generated")
  17. else:
  18. with open("requirements-in.txt", "r", encoding="utf-8") as f:
  19. content = f.read()
  20. if content.find("pyside6==6.4.3\n") == -1:
  21. content.index("pyside6==6.4.3\n")
  22. with open("requirements-in.txt", "w", encoding="utf-8") as f:
  23. f.write(content)
  24. logger.info("requirements-in.txt generated")
  25. # 执行命令 pip-compile --annotation-style=line --output-file=requirements.txt requirements-in.txt
  26. subprocess.run(["pip-compile", "--annotation-style=line", "--output-file=requirements.txt", "requirements-in.txt"])
  27. content = ''
  28. with open("requirements.txt", "r", encoding="utf-8") as f:
  29. content = f.read()
  30. content = content.replace('''--index-url https://pypi.tuna.tsinghua.edu.cn/simple
  31. --trusted-host pypi.tuna.tsinghua.edu.cn''', '')
  32. with open("requirements.txt", "w", encoding="utf-8") as f:
  33. f.write(content)
  34. logger.info("requirements.txt generated")
  35. if __name__ == "__main__":
  36. parser = argparse.ArgumentParser(description="Generate requirements.txt")
  37. parser.add_argument(
  38. "--qml",
  39. action="store_true",
  40. help="Use qml",
  41. )
  42. args, _ = parser.parse_known_args()
  43. qml = True if args.qml else False
  44. logger.attr("QML", qml)
  45. generate(qml)