mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-09 10:17:38 +08:00
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import sys
|
|
from urllib.parse import urlparse
|
|
|
|
from deploy.config import DeployConfig
|
|
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
|
|
|
|
@cached_property
|
|
def requirements_file(self):
|
|
if self.RequirementsFile == 'requirements.txt':
|
|
return 'requirements.txt'
|
|
else:
|
|
return self.filepath("RequirementsFile")
|
|
|
|
@cached_property
|
|
def pip(self):
|
|
return f'"{self.python}" -m pip'
|
|
|
|
def pip_install(self):
|
|
logger.hr('Update Dependencies', 0)
|
|
|
|
if not self.InstallDependencies:
|
|
logger.info('InstallDependencies is disabled, skip')
|
|
return
|
|
|
|
logger.hr('Check Python', 1)
|
|
self.execute(f'"{self.python}" --version')
|
|
|
|
arg = []
|
|
if self.PypiMirror:
|
|
mirror = self.PypiMirror
|
|
arg += ['-i', mirror]
|
|
# Trust http mirror or skip ssl verify
|
|
if 'http:' in mirror or not self.SSLVerify:
|
|
arg += ['--trusted-host', urlparse(mirror).hostname]
|
|
elif not self.SSLVerify:
|
|
arg += ['--trusted-host', 'pypi.org']
|
|
arg += ['--trusted-host', 'files.pythonhosted.org']
|
|
|
|
# Don't update pip, just leave it.
|
|
# logger.hr('Update pip', 1)
|
|
# self.execute(f'"{self.pip}" install --upgrade pip{arg}')
|
|
arg += ['--disable-pip-version-check']
|
|
|
|
logger.hr('Update Dependencies', 1)
|
|
arg = ' ' + ' '.join(arg) if arg else ''
|
|
self.execute(f'{self.pip} install -r {self.requirements_file}{arg}')
|