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

60 lines
1.9 KiB
Python
Raw Normal View History

import sys
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):
exe = self.filepath("PythonExecutable")
if os.path.exists(exe):
return exe
current = sys.executable.replace("\\", "/")
logger.warning(f'PythonExecutable: {exe} does not exist, use current python instead: {current}')
return current
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]
2022-11-15 09:45:42 +08:00
# Trust http mirror or skip ssl verify
if 'http:' in mirror or not self.SSLVerify:
arg += ['--trusted-host', urlparse(mirror).hostname]
2022-11-15 09:45:42 +08:00
elif not self.SSLVerify:
arg += ['--trusted-host', 'pypi.org']
arg += ['--trusted-host', 'files.pythonhosted.org']
# 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}')