Fixed update & install commands #113

This commit is contained in:
2022-09-19 21:09:41 +02:00
parent 1ed721cccb
commit ef2d73aadc
6 changed files with 58 additions and 20 deletions

View File

@@ -76,23 +76,33 @@ class InstallService(CommandABC):
Console.spinner(
f'Installing: {dependency}',
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
'--upgrade',
source=self._cli_settings.pip_path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.cyan
)
local_package = Pip.get_package(dependency)
if local_package is None:
Error.warn(f'Installation of package {dependency} failed!')
return
for dependency in self._project_settings.dev_dependencies:
Console.spinner(
f'Installing dev: {dependency}',
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
'--upgrade',
source=self._cli_settings.pip_path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.cyan
)
local_package = Pip.get_package(dependency)
if local_package is None:
Error.warn(f'Installation of package {dependency} failed!')
return
if not self._is_virtual:
Pip.reset_executable()
@@ -154,7 +164,7 @@ class InstallService(CommandABC):
Console.spinner(
f'Installing: {package}' if not self._is_dev else f'Installing dev: {package}',
Pip.install if not self._is_virtual else self._wait, package if not self._is_virtual else 2,
source=self._cli_settings.pip_path if 'cpl-' in package or 'cpl_' in package else None,
source=self._cli_settings.pip_path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text_foreground_color=ForegroundColorEnum.green,
@@ -221,6 +231,18 @@ class InstallService(CommandABC):
args.remove('simulate')
Console.write_line('Running in simulation mode:')
if 'cpl-prod' in args:
args.remove('cpl-prod')
self._cli_settings.from_dict({'PipPath': 'https://pip.sh-edraft.de'})
if 'cpl-exp' in args:
args.remove('cpl-exp')
self._cli_settings.from_dict({'PipPath': 'https://pip-exp.sh-edraft.de'})
if 'cpl-dev' in args:
args.remove('cpl-dev')
self._cli_settings.from_dict({'PipPath': 'https://pip-dev.sh-edraft.de'})
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
if len(args) == 0:

View File

@@ -76,7 +76,7 @@ class UpdateService(CommandABC):
'--upgrade',
'--upgrade-strategy',
'eager',
source=self._cli_settings.pip_path if 'cpl-' in name else None,
source=self._cli_settings.pip_path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
@@ -169,6 +169,18 @@ class UpdateService(CommandABC):
Console.write_line('Running in simulation mode:')
self._is_simulation = True
if 'cpl-prod' in args:
args.remove('cpl-prod')
self._cli_settings.from_dict({'PipPath': 'https://pip.sh-edraft.de'})
if 'cpl-exp' in args:
args.remove('cpl-exp')
self._cli_settings.from_dict({'PipPath': 'https://pip-exp.sh-edraft.de'})
if 'cpl-dev' in args:
args.remove('cpl-dev')
self._cli_settings.from_dict({'PipPath': 'https://pip-dev.sh-edraft.de'})
VenvHelper.init_venv(False, self._env, self._project_settings)
self._check_project_dependencies()

View File

@@ -42,7 +42,10 @@ class StartupArgumentExtension(StartupExtensionABC):
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True, validators=[ProjectValidator]) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-prod', ['cp', 'CP']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-exp', ['ce', 'CE']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-dev', ['cd', 'CD'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'new', ['n', 'N'], NewService, True) \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'console', ['c', 'C'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'library', ['l', 'L'], ' ') \
@@ -63,7 +66,10 @@ class StartupArgumentExtension(StartupExtensionABC):
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService, True, validators=[ProjectValidator]) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-prod', ['cp', 'CP']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-exp', ['ce', 'CE']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-dev', ['cd', 'CD'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'version', ['v', 'V'], VersionService, True)
config.for_each_argument(lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, '--', 'help', ['h', 'H']))

View File

@@ -65,7 +65,7 @@ class Pip:
"""
result = None
with suppress(Exception):
args = [cls._executable, "-m", "pip", "show", package]
args = [cls._executable, "-m", "pip", "freeze"]
result = subprocess.check_output(
args,
@@ -75,17 +75,11 @@ class Pip:
if result is None:
return None
new_package: list[str] = str(result, 'utf-8').lower().split('\n')
new_version = ''
for p in str(result.decode()).split('\n'):
if p == package:
return p
for atr in new_package:
if 'version' in atr:
new_version = atr.split(': ')[1]
if new_version != '':
return f'{package}=={new_version}'
return package
return None
@classmethod
def get_outdated(cls) -> bytes: