pip.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This Python file uses the following encoding: utf-8
  2. # copy from alas https://github.com/LmeSzinc/AzurLaneAutoScript
  3. from urllib.parse import urlparse
  4. from deploy.config import DeployConfig
  5. from deploy.logger import logger
  6. from deploy.utils import *
  7. class PipManager(DeployConfig):
  8. @cached_property
  9. def python(self):
  10. return self.filepath("PythonExecutable")
  11. @cached_property
  12. def requirements_file(self):
  13. if self.RequirementsFile == 'requirements.txt':
  14. return 'requirements.txt'
  15. else:
  16. return self.filepath("RequirementsFile")
  17. @cached_property
  18. def pip(self):
  19. return f'"{self.python}" -m pip'
  20. def pip_install(self):
  21. logger.hr('Update Dependencies', 0)
  22. if not self.InstallDependencies:
  23. logger.info('InstallDependencies is disabled, skip')
  24. return
  25. logger.hr('Check Python', 1)
  26. self.execute(f'"{self.python}" --version')
  27. arg = []
  28. if self.PypiMirror:
  29. mirror = self.PypiMirror
  30. arg += ['-i', mirror]
  31. # Trust http mirror or skip ssl verify
  32. if 'http:' in mirror or not self.SSLVerify:
  33. arg += ['--trusted-host', urlparse(mirror).hostname]
  34. elif not self.SSLVerify:
  35. arg += ['--trusted-host', 'pypi.org']
  36. arg += ['--trusted-host', 'files.pythonhosted.org']
  37. # Don't update pip, just leave it.
  38. # logger.hr('Update pip', 1)
  39. # self.execute(f'"{self.pip}" install --upgrade pip{arg}')
  40. arg += ['--disable-pip-version-check']
  41. logger.hr('Update Dependencies', 1)
  42. arg = ' ' + ' '.join(arg) if arg else ''
  43. self.execute(f'{self.pip} install -r {self.requirements_file}{arg}')