From cbd2964f42d3752329faf4f825377cab3d6b4e24 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 27 Jun 2022 20:02:01 +0200 Subject: [PATCH] Added dev-dependencies to install command --- src/cpl_cli/command/install_service.py | 25 +++++++++++++++---- src/cpl_cli/configuration/project_settings.py | 8 ++++++ .../project_settings_name_enum.py | 1 + src/cpl_cli/configuration/settings_helper.py | 1 + src/cpl_cli/startup_argument_extension.py | 2 ++ src/cpl_core/utils/pip.py | 1 - .../custom/general/src/general/general.json | 3 +++ 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/cpl_cli/command/install_service.py b/src/cpl_cli/command/install_service.py index 43db92b9..bc7ee764 100644 --- a/src/cpl_cli/command/install_service.py +++ b/src/cpl_cli/command/install_service.py @@ -42,6 +42,7 @@ class InstallService(CommandABC): self._is_simulation = False self._is_virtual = False + self._is_dev = False self._project_file = f'{self._project_settings.name}.json' @@ -107,7 +108,11 @@ class InstallService(CommandABC): package_version = package.split('==')[1] to_remove_list = [] - for dependency in self._project_settings.dependencies: + deps = self._project_settings.dependencies + if self._is_dev: + deps = self._project_settings.dev_dependencies + + for dependency in deps: dependency_version = '' if '==' in dependency: @@ -121,7 +126,10 @@ class InstallService(CommandABC): is_already_in_project = True for to_remove in to_remove_list: - self._project_settings.dependencies.remove(to_remove) + if self._is_dev: + self._project_settings.dev_dependencies.remove(to_remove) + else: + self._project_settings.dependencies.remove(to_remove) local_package = Pip.get_package(package) if local_package is not None and local_package in self._project_settings.dependencies: @@ -133,9 +141,9 @@ class InstallService(CommandABC): return Console.spinner( - f'Installing: {package}', + 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 else None, + source=self._cli_settings.pip_path if 'cpl-' in package or 'cpl_' in package else None, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text_foreground_color=ForegroundColorEnum.green, @@ -165,7 +173,10 @@ class InstallService(CommandABC): if '\r' in new_name: new_name = new_name.replace('\r', '') - self._project_settings.dependencies.append(new_name) + if self._is_dev: + self._project_settings.dev_dependencies.append(new_name) + else: + self._project_settings.dependencies.append(new_name) if not self._is_simulation: config = { @@ -185,6 +196,10 @@ class InstallService(CommandABC): :param args: :return: """ + if 'dev' in args: + self._is_dev = True + args.remove('dev') + if 'virtual' in args: self._is_virtual = True args.remove('virtual') diff --git a/src/cpl_cli/configuration/project_settings.py b/src/cpl_cli/configuration/project_settings.py index 94d490c6..98d0fa97 100644 --- a/src/cpl_cli/configuration/project_settings.py +++ b/src/cpl_cli/configuration/project_settings.py @@ -28,6 +28,7 @@ class ProjectSettings(ConfigurationModelABC): self._license_name: Optional[str] = None self._license_description: Optional[str] = None self._dependencies: Optional[list[str]] = None + self._dev_dependencies: Optional[list[str]] = None self._python_version: Optional[str] = None self._python_path: Optional[str] = None self._python_executable: Optional[str] = None @@ -81,6 +82,10 @@ class ProjectSettings(ConfigurationModelABC): def dependencies(self) -> list[str]: return self._dependencies + @property + def dev_dependencies(self) -> list[str]: + return self._dev_dependencies + @property def python_version(self) -> str: return self._python_version @@ -111,6 +116,9 @@ class ProjectSettings(ConfigurationModelABC): self._license_name = settings[ProjectSettingsNameEnum.license_name.value] self._license_description = settings[ProjectSettingsNameEnum.license_description.value] self._dependencies = settings[ProjectSettingsNameEnum.dependencies.value] + if ProjectSettingsNameEnum.dev_dependencies.value not in settings: + settings[ProjectSettingsNameEnum.dev_dependencies.value] = [] + self._dev_dependencies = settings[ProjectSettingsNameEnum.dev_dependencies.value] self._python_version = settings[ProjectSettingsNameEnum.python_version.value] self._python_path = settings[ProjectSettingsNameEnum.python_path.value] diff --git a/src/cpl_cli/configuration/project_settings_name_enum.py b/src/cpl_cli/configuration/project_settings_name_enum.py index 7b4b6557..17d2319b 100644 --- a/src/cpl_cli/configuration/project_settings_name_enum.py +++ b/src/cpl_cli/configuration/project_settings_name_enum.py @@ -14,6 +14,7 @@ class ProjectSettingsNameEnum(Enum): license_name = 'LicenseName' license_description = 'LicenseDescription' dependencies = 'Dependencies' + dev_dependencies = 'DevDependencies' python_version = 'PythonVersion' python_path = 'PythonPath' classifiers = 'Classifiers' diff --git a/src/cpl_cli/configuration/settings_helper.py b/src/cpl_cli/configuration/settings_helper.py index 8a7c47ad..660c1285 100644 --- a/src/cpl_cli/configuration/settings_helper.py +++ b/src/cpl_cli/configuration/settings_helper.py @@ -26,6 +26,7 @@ class SettingsHelper: ProjectSettingsNameEnum.license_name.value: project.license_name, ProjectSettingsNameEnum.license_description.value: project.license_description, ProjectSettingsNameEnum.dependencies.value: project.dependencies, + ProjectSettingsNameEnum.dev_dependencies.value: project.dev_dependencies, ProjectSettingsNameEnum.python_version.value: project.python_version, ProjectSettingsNameEnum.python_path.value: project.python_path, ProjectSettingsNameEnum.classifiers.value: project.classifiers diff --git a/src/cpl_cli/startup_argument_extension.py b/src/cpl_cli/startup_argument_extension.py index e3f1fef4..de0047fd 100644 --- a/src/cpl_cli/startup_argument_extension.py +++ b/src/cpl_cli/startup_argument_extension.py @@ -40,6 +40,7 @@ class StartupArgumentExtension(StartupExtensionABC): .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'validator', ['v', 'V'], ' ') 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']) config.create_console_argument(ArgumentTypeEnum.Executable, '', 'new', ['n', 'N'], NewService, True) \ @@ -58,6 +59,7 @@ class StartupArgumentExtension(StartupExtensionABC): config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator]) config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, 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']) config.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService, True, validators=[ProjectValidator]) \ diff --git a/src/cpl_core/utils/pip.py b/src/cpl_core/utils/pip.py index c0ebf062..7d97e496 100644 --- a/src/cpl_core/utils/pip.py +++ b/src/cpl_core/utils/pip.py @@ -126,7 +126,6 @@ class Pip: pip_args.append(source) pip_args.append(package) - print(pip_args) subprocess.run(pip_args, stdout=stdout, stderr=stderr, env=cls._env) @classmethod diff --git a/src/tests/custom/general/src/general/general.json b/src/tests/custom/general/src/general/general.json index fc68548e..4af74368 100644 --- a/src/tests/custom/general/src/general/general.json +++ b/src/tests/custom/general/src/general/general.json @@ -18,6 +18,9 @@ "Dependencies": [ "cpl_core==2022.6.1" ], + "DevDependencies": [ + "cpl-cli==2022.6.17.dev10" + ], "PythonVersion": ">=3.10", "PythonPath": { "linux": "../../venv/bin/python",