1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-09 18:39:04 +08:00
AzurLaneAutoScript/deploy/pip.py

50 lines
1.4 KiB
Python
Raw Normal View History

from urllib.parse import urlparse
from deploy.config import DeployConfig
2022-06-25 20:24:34 +08:00
from deploy.logger import logger
from deploy.utils import *
class PipManager(DeployConfig):
@cached_property
def python(self):
return self.filepath("PythonExecutable")
2022-02-03 22:16:18 +08:00
@cached_property
def requirements_file(self):
2022-06-03 21:28:44 +08:00
if self.RequirementsFile == 'requirements.txt':
return 'requirements.txt'
else:
return self.filepath("RequirementsFile")
2022-02-03 22:16:18 +08:00
@cached_property
def pip(self):
return f'"{self.python}" -m pip'
def pip_install(self):
2022-06-25 20:24:34 +08:00
logger.hr('Update Dependencies', 0)
2022-06-03 21:28:44 +08:00
if not self.InstallDependencies:
2022-06-25 20:24:34 +08:00
logger.info('InstallDependencies is disabled, skip')
return
2022-06-25 20:24:34 +08:00
logger.hr('Check Python', 1)
self.execute(f'"{self.python}" --version')
arg = []
2022-06-03 21:28:44 +08:00
if self.PypiMirror:
mirror = self.PypiMirror
arg += ['-i', mirror]
# Trust http mirror
if 'http:' in mirror:
arg += ['--trusted-host', urlparse(mirror).hostname]
# Don't update pip, just leave it.
2022-06-25 20:24:34 +08:00
# logger.hr('Update pip', 1)
# self.execute(f'"{self.pip}" install --upgrade pip{arg}')
arg += ['--disable-pip-version-check']
2022-06-25 20:24:34 +08:00
logger.hr('Update Dependencies', 1)
arg = ' ' + ' '.join(arg) if arg else ''
self.execute(f'{self.pip} install -r {self.requirements_file}{arg}')