2021.11 #50

Merged
edraft merged 10 commits from 2021.11 into master 2021-11-30 12:03:04 +01:00
2 changed files with 43 additions and 18 deletions
Showing only changes of commit 403837901b - Show all commits

View File

@ -172,6 +172,7 @@ class InstallService(CommandABC):
self._project_settings.dependencies.append(new_name)
if not self._is_simulating:
config = {
ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(self._project_settings),
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings)

View File

@ -2,6 +2,7 @@ import json
import os
import subprocess
import textwrap
import time
from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console
@ -32,6 +33,9 @@ class UninstallService(CommandABC):
self._build_settings = build_settings
self._project_settings = project_settings
self._is_simulating = False
self._is_virtual = False
@property
def help_message(self) -> str:
return textwrap.dedent("""\
@ -42,6 +46,9 @@ class UninstallService(CommandABC):
package The package to uninstall
""")
def _wait(self, t: int, *args, source: str = None, stdout=None, stderr=None):
time.sleep(t)
def run(self, args: list[str]):
"""
Entry point of command
@ -53,12 +60,27 @@ class UninstallService(CommandABC):
Console.error(f'Usage: cpl uninstall <package>')
return
if '--virtual' in args:
self._is_virtual = True
args.remove('--virtual')
Console.write_line('Running in virtual mode:')
if '--simulate' in args:
self._is_virtual = True
args.remove('--simulate')
Console.write_line('Running in simulation mode:')
if not self._is_virtual:
Pip.set_executable(self._project_settings.python_executable)
package = args[0]
is_in_dependencies = False
if not self._is_virtual:
pip_package = Pip.get_package(package)
else:
pip_package = package
for dependency in self._project_settings.dependencies:
if package in dependency:
@ -74,7 +96,7 @@ class UninstallService(CommandABC):
Console.spinner(
f'Uninstalling: {package}',
Pip.uninstall, package,
Pip.uninstall if not self._is_virtual else self._wait, package if not self._is_virtual else 2,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text_foreground_color=ForegroundColorEnum.green,
@ -83,6 +105,7 @@ class UninstallService(CommandABC):
if package in self._project_settings.dependencies:
self._project_settings.dependencies.remove(package)
if not self._is_simulating:
config = {
ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(self._project_settings),
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings)
@ -92,4 +115,5 @@ class UninstallService(CommandABC):
project_file.close()
Console.write_line(f'Removed {package}')
if not self._is_virtual:
Pip.reset_executable()