This commit is contained in:
2021-03-14 13:22:10 +01:00
parent 5c012ab4a0
commit 7ffd553709
34 changed files with 156 additions and 103 deletions

View File

@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.4.1.post1'
__version__ = '2021.4.1.post2'
from collections import namedtuple
@@ -28,4 +28,4 @@ from .publish_service import PublishService
from .version_service import VersionService
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='04', micro='01-1')
version_info = VersionInfo(major='2021', minor='04', micro='01-2')

View File

@@ -1,8 +1,6 @@
import json
import os
import subprocess
import sys
from typing import Optional
from cpl.application import ApplicationRuntimeABC
from cpl.configuration import ConfigurationABC
@@ -85,6 +83,7 @@ class InstallService(CommandABC):
is_already_in_project = False
project: ProjectSettings = self._config.get_configuration(ProjectSettings)
build: BuildSettings = self._config.get_configuration(BuildSettings)
Pip.set_executable(project.python_path)
if project is None or build is None:
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
@@ -128,6 +127,8 @@ class InstallService(CommandABC):
project_file.write(json.dumps(config, indent=2))
project_file.close()
Pip.reset_executable()
def run(self, args: list[str]):
if len(args) == 0:
self._install_project()

View File

@@ -64,6 +64,8 @@ class UninstallService(CommandABC):
Console.error(f'Usage: cpl uninstall <package>')
return
Pip.set_executable(self._project_settings.python_path)
package = args[0]
is_in_dependencies = False
@@ -101,6 +103,4 @@ class UninstallService(CommandABC):
project_file.close()
Console.write_line(f'Removed {package}')
Pip.reset_executable()

View File

@@ -20,8 +20,26 @@ class UpdateService(CommandABC):
self._project_settings = project_settings
@staticmethod
def _get_outdated() -> bytes:
return subprocess.check_output([sys.executable, "-m", "pip", "list", "--outdated"])
def _install_package(name: str):
if 'sh_cpl' in name:
Pip.install(
name,
'--upgrade',
'--upgrade-strategy',
'eager',
source='https://pip.sh-edraft.de',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
else:
Pip.install(
name,
'--upgrade',
'--upgrade-strategy',
'eager',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
def _update_project_dependencies(self):
for package in self._project_settings.dependencies:
@@ -29,29 +47,11 @@ class UpdateService(CommandABC):
if '==' in package:
name = package.split('==')[0]
if 'sh_cpl' in name:
Pip.install(
name,
'--upgrade',
'--upgrade-strategy',
'eager',
source='https://pip.sh-edraft.de',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
else:
Pip.install(
name,
'--upgrade',
'--upgrade-strategy',
'eager',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
self._install_package(name)
new_package = Pip.get_package(name)
if new_package is None:
Console.error(f'Invalid name: {name}')
Console.error(f'Update for package {package} failed')
return
self._project_json_update_dependency(package, new_package)
@@ -64,9 +64,10 @@ class UpdateService(CommandABC):
)
Console.write_line(f'Found {len(self._project_settings.dependencies)} dependencies.')
def _check_outdated(self):
@staticmethod
def _check_outdated():
table_str: bytes = Console.spinner(
'Analyzing for available package updates', self._get_outdated,
'Analyzing for available package updates', Pip.get_outdated,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.cyan
)
@@ -78,7 +79,7 @@ class UpdateService(CommandABC):
Console.write_line(f'\t{row}')
Console.set_foreground_color(ForegroundColorEnum.yellow)
Console.write_line(f'\tUpdate with {sys.executable} -m pip install --upgrade <package>')
Console.write_line(f'\tUpdate with {Pip.get_executable()} -m pip install --upgrade <package>')
Console.set_foreground_color(ForegroundColorEnum.default)
def _project_json_update_dependency(self, old_package: str, new_package: str):
@@ -98,8 +99,9 @@ class UpdateService(CommandABC):
project.close()
def run(self, args: list[str]):
# target update discord 1.5.1 to discord 1.6.0
Pip.set_executable(self._project_settings.python_path)
self._check_project_dependencies()
self._check_outdated()
Pip.reset_executable()
Console.write('\n')