Compare commits
25 Commits
89d591ce0a
...
2022.6.0rc
Author | SHA1 | Date | |
---|---|---|---|
b9e0b7ccd0 | |||
4b9e428abb | |||
63ad13e09a | |||
cc06a308a1 | |||
e9fdd20181 | |||
8692686cb5 | |||
db29ad36fe | |||
0710b25317 | |||
cbd2964f42 | |||
f51118f13c | |||
323e363b42 | |||
e8a4fe6142 | |||
587d9b359c | |||
c2632253ac | |||
45be77dd10 | |||
78ffbcc33d | |||
d83d1a244e | |||
fa002a50ac | |||
32507afae9 | |||
6de3bbdaf4 | |||
6e50d0cb22 | |||
9e978f3ece | |||
32478926c8 | |||
2925788d01 | |||
c0789cf4f7 |
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .main import main
|
||||
from .startup import Startup
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.build'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.generate'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.unittest'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.unittest.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.unittest.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"CLI": {
|
||||
"PipPath": "https://pip-dev.sh-edraft.de"
|
||||
"PipPath": "https://pip-exp.sh-edraft.de"
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
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='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,19 +4,20 @@ import subprocess
|
||||
import textwrap
|
||||
import time
|
||||
|
||||
from packaging import version
|
||||
|
||||
from cpl_cli.cli_settings import CLISettings
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_cli.error import Error
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.environment.application_environment_abc import \
|
||||
ApplicationEnvironmentABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.pip import Pip
|
||||
from packaging import version
|
||||
|
||||
|
||||
class InstallService(CommandABC):
|
||||
@@ -41,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'
|
||||
|
||||
@@ -62,7 +64,6 @@ class InstallService(CommandABC):
|
||||
Installs dependencies of CPl project
|
||||
:return:
|
||||
"""
|
||||
|
||||
if self._project_settings is None or self._build_settings is None:
|
||||
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
|
||||
return
|
||||
@@ -71,8 +72,6 @@ class InstallService(CommandABC):
|
||||
Error.error(f'Found invalid dependencies in {self._project_file}.')
|
||||
return
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
for dependency in self._project_settings.dependencies:
|
||||
Console.spinner(
|
||||
f'Installing: {dependency}',
|
||||
@@ -84,6 +83,17 @@ class InstallService(CommandABC):
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
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,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.reset_executable()
|
||||
|
||||
@@ -94,9 +104,6 @@ class InstallService(CommandABC):
|
||||
:return:
|
||||
"""
|
||||
is_already_in_project = False
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
|
||||
if self._project_settings is None or self._build_settings is None:
|
||||
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
|
||||
return
|
||||
@@ -112,7 +119,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:
|
||||
@@ -126,7 +137,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:
|
||||
@@ -138,9 +152,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,
|
||||
@@ -170,7 +184,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 = {
|
||||
@@ -190,6 +207,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')
|
||||
@@ -200,7 +221,12 @@ class InstallService(CommandABC):
|
||||
args.remove('simulate')
|
||||
Console.write_line('Running in simulation mode:')
|
||||
|
||||
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
|
||||
|
||||
if len(args) == 0:
|
||||
self._install_project()
|
||||
else:
|
||||
self._install_package(args[0])
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.reset_executable()
|
||||
|
@@ -5,7 +5,9 @@ from typing import Optional
|
||||
|
||||
from packaging import version
|
||||
|
||||
import cpl_cli
|
||||
import cpl_core
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_cli.source_creator.unittest_builder import UnittestBuilder
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
@@ -36,7 +38,7 @@ class NewService(CommandABC):
|
||||
self._config = configuration
|
||||
self._env = self._config.environment
|
||||
|
||||
self._workspace = self._config.get_configuration(WorkspaceSettings)
|
||||
self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
|
||||
self._project: ProjectSettings = ProjectSettings()
|
||||
self._project_dict = {}
|
||||
self._build: BuildSettings = BuildSettings()
|
||||
@@ -51,6 +53,7 @@ class NewService(CommandABC):
|
||||
self._use_startup: bool = False
|
||||
self._use_service_providing: bool = False
|
||||
self._use_async: bool = False
|
||||
self._use_venv: bool = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -105,9 +108,12 @@ class NewService(CommandABC):
|
||||
ProjectSettingsNameEnum.dependencies.value: [
|
||||
f'cpl-core>={version.parse(cpl_core.__version__)}'
|
||||
],
|
||||
ProjectSettingsNameEnum.dev_dependencies.value: [
|
||||
f'cpl-cli>={version.parse(cpl_cli.__version__)}'
|
||||
],
|
||||
ProjectSettingsNameEnum.python_version.value: f'>={sys.version.split(" ")[0]}',
|
||||
ProjectSettingsNameEnum.python_path.value: {
|
||||
sys.platform: ''
|
||||
sys.platform: '../../venv/bin/python' if self._use_venv else ''
|
||||
},
|
||||
ProjectSettingsNameEnum.classifiers.value: []
|
||||
}
|
||||
@@ -275,6 +281,22 @@ class NewService(CommandABC):
|
||||
except Exception as e:
|
||||
Console.error('Could not create project', str(e))
|
||||
|
||||
def _create_venv(self):
|
||||
|
||||
project = self._project.name
|
||||
if self._workspace is not None:
|
||||
project = self._workspace.default_project
|
||||
|
||||
if self._env.working_directory.endswith(project):
|
||||
project = ''
|
||||
|
||||
VenvHelper.init_venv(
|
||||
False,
|
||||
self._env,
|
||||
self._project,
|
||||
explicit_path=os.path.join(self._env.working_directory, project, self._project.python_executable.replace('../', ''))
|
||||
)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
@@ -308,6 +330,9 @@ class NewService(CommandABC):
|
||||
if 'service-providing' in args:
|
||||
self._use_service_providing = True
|
||||
args.remove('service-providing')
|
||||
if 'venv' in args:
|
||||
self._use_venv = True
|
||||
args.remove('venv')
|
||||
|
||||
console = self._config.get_configuration(ProjectTypeEnum.console.value)
|
||||
library = self._config.get_configuration(ProjectTypeEnum.library.value)
|
||||
@@ -316,16 +341,22 @@ class NewService(CommandABC):
|
||||
self._name = console
|
||||
self._schematic = ProjectTypeEnum.console.value
|
||||
self._console(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
elif console is None and library is not None and unittest is None:
|
||||
self._name = library
|
||||
self._schematic = ProjectTypeEnum.library.value
|
||||
self._library(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
elif console is None and library is None and unittest is not None:
|
||||
self._name = unittest
|
||||
self._schematic = ProjectTypeEnum.unittest.value
|
||||
self._unittest(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
else:
|
||||
self._help('Usage: cpl new <schematic> [options]')
|
||||
|
@@ -4,6 +4,7 @@ import subprocess
|
||||
import textwrap
|
||||
import time
|
||||
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -35,6 +36,9 @@ class UninstallService(CommandABC):
|
||||
|
||||
self._is_simulating = False
|
||||
self._is_virtual = False
|
||||
self._is_dev = False
|
||||
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -60,6 +64,9 @@ class UninstallService(CommandABC):
|
||||
Console.error(f'Usage: cpl uninstall <package>')
|
||||
return
|
||||
|
||||
if 'dev' in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
|
||||
if '--virtual' in args:
|
||||
self._is_virtual = True
|
||||
@@ -71,8 +78,7 @@ class UninstallService(CommandABC):
|
||||
args.remove('--simulate')
|
||||
Console.write_line('Running in simulation mode:')
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
|
||||
|
||||
package = args[0]
|
||||
is_in_dependencies = False
|
||||
@@ -82,7 +88,11 @@ class UninstallService(CommandABC):
|
||||
else:
|
||||
pip_package = package
|
||||
|
||||
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:
|
||||
if package in dependency:
|
||||
is_in_dependencies = True
|
||||
package = dependency
|
||||
@@ -95,7 +105,7 @@ class UninstallService(CommandABC):
|
||||
package = pip_package
|
||||
|
||||
Console.spinner(
|
||||
f'Uninstalling: {package}',
|
||||
f'Uninstalling: {package}' if not self._is_dev else f'Uninstalling dev: {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,
|
||||
@@ -103,14 +113,18 @@ class UninstallService(CommandABC):
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
if package in self._project_settings.dependencies:
|
||||
self._project_settings.dependencies.remove(package)
|
||||
deps = self._project_settings.dependencies
|
||||
if self._is_dev:
|
||||
deps = self._project_settings.dev_dependencies
|
||||
|
||||
if package in deps:
|
||||
deps.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)
|
||||
}
|
||||
with open(os.path.join(self._env.working_directory, f'{self._config.get_configuration("ProjectName")}.json'), 'w') as project_file:
|
||||
with open(os.path.join(self._env.working_directory, self._project_file), 'w') as project_file:
|
||||
project_file.write(json.dumps(config, indent=2))
|
||||
project_file.close()
|
||||
|
||||
|
@@ -3,6 +3,7 @@ import os
|
||||
import subprocess
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -40,6 +41,8 @@ class UpdateService(CommandABC):
|
||||
self._cli_settings = cli_settings
|
||||
self._is_simulation = False
|
||||
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
return textwrap.dedent("""\
|
||||
@@ -81,7 +84,7 @@ class UpdateService(CommandABC):
|
||||
new_package = Pip.get_package(name)
|
||||
if new_package is None:
|
||||
Console.error(f'Update for package {package} failed')
|
||||
return
|
||||
continue
|
||||
|
||||
self._project_json_update_dependency(package, new_package)
|
||||
|
||||
@@ -151,8 +154,7 @@ class UpdateService(CommandABC):
|
||||
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings)
|
||||
}
|
||||
|
||||
with open(os.path.join(self._env.working_directory, f'{self._config.get_configuration("ProjectName")}.json'),
|
||||
'w') as project:
|
||||
with open(os.path.join(self._env.working_directory, self._project_file), 'w') as project:
|
||||
project.write(json.dumps(config, indent=2))
|
||||
project.close()
|
||||
|
||||
@@ -167,7 +169,8 @@ class UpdateService(CommandABC):
|
||||
Console.write_line('Running in simulation mode:')
|
||||
self._is_simulation = True
|
||||
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
VenvHelper.init_venv(False, self._env, self._project_settings)
|
||||
|
||||
self._check_project_dependencies()
|
||||
self._check_outdated()
|
||||
Pip.reset_executable()
|
||||
|
@@ -5,7 +5,6 @@ import pkg_resources
|
||||
import textwrap
|
||||
|
||||
import cpl_cli
|
||||
import cpl_core
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -30,4 +30,4 @@ from .workspace_settings import WorkspaceSettings
|
||||
from .workspace_settings_name_enum import WorkspaceSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -3,12 +3,12 @@ import sys
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsNameEnum
|
||||
from cpl_cli.configuration.version_settings import VersionSettings
|
||||
from cpl_cli.error import Error
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_cli.configuration.version_settings import VersionSettings
|
||||
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsNameEnum
|
||||
from cpl_cli.error import Error
|
||||
|
||||
|
||||
class ProjectSettings(ConfigurationModelABC):
|
||||
@@ -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,16 +116,16 @@ 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]
|
||||
|
||||
if ProjectSettingsNameEnum.python_path.value in settings and \
|
||||
sys.platform in settings[ProjectSettingsNameEnum.python_path.value]:
|
||||
if ProjectSettingsNameEnum.python_path.value in settings and sys.platform in settings[ProjectSettingsNameEnum.python_path.value]:
|
||||
path = settings[ProjectSettingsNameEnum.python_path.value][sys.platform]
|
||||
if not os.path.isfile(path) and not os.path.islink(path):
|
||||
if path != '' and path is not None:
|
||||
Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not found')
|
||||
|
||||
if path == '' or path is None:
|
||||
Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not found')
|
||||
path = sys.executable
|
||||
else:
|
||||
path = sys.executable
|
||||
@@ -134,7 +139,6 @@ class ProjectSettings(ConfigurationModelABC):
|
||||
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(
|
||||
f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettings.__name__} settings')
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettings.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
@@ -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'
|
||||
|
@@ -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
|
||||
|
43
src/cpl_cli/configuration/venv_helper_service.py
Normal file
43
src/cpl_cli/configuration/venv_helper_service.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from cpl_cli.configuration import ProjectSettings
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from cpl_core.utils import Pip
|
||||
|
||||
from cpl_core.console import Console, ForegroundColorEnum
|
||||
|
||||
|
||||
class VenvHelper:
|
||||
|
||||
@staticmethod
|
||||
def init_venv(is_virtual: bool, env: ApplicationEnvironmentABC, project_settings: ProjectSettings, explicit_path=None):
|
||||
if is_virtual:
|
||||
return
|
||||
|
||||
venv_path = os.path.abspath(os.path.join(env.working_directory, project_settings.python_executable))
|
||||
|
||||
if explicit_path is not None:
|
||||
venv_path = os.path.abspath(explicit_path)
|
||||
|
||||
if not os.path.exists(venv_path):
|
||||
Console.spinner(
|
||||
f'Creating venv: {venv_path}',
|
||||
VenvHelper.create_venv,
|
||||
venv_path,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
Pip.set_executable(venv_path)
|
||||
|
||||
@staticmethod
|
||||
def create_venv(path):
|
||||
subprocess.run(
|
||||
[sys.executable, '-m', 'venv', os.path.abspath(os.path.join(path, '../../'))],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stdin=subprocess.DEVNULL
|
||||
)
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev10"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,10 +16,13 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"PythonPath": {
|
||||
"linux": "../../venv"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -5,6 +5,7 @@ import pkg_resources
|
||||
from cpl_cli.cli import CLI
|
||||
from cpl_cli.startup import Startup
|
||||
from cpl_cli.startup_argument_extension import StartupArgumentExtension
|
||||
from cpl_cli.startup_workspace_extension import StartupWorkspaceExtension
|
||||
from cpl_core.application.application_builder import ApplicationBuilder
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
|
||||
@@ -31,6 +32,7 @@ def get_startup_extensions() -> list[Type[StartupExtensionABC]]:
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(CLI)
|
||||
app_builder.use_startup(Startup)
|
||||
app_builder.use_extension(StartupWorkspaceExtension)
|
||||
app_builder.use_extension(StartupArgumentExtension)
|
||||
for extension in get_startup_extensions():
|
||||
app_builder.use_extension(extension)
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .publisher_abc import PublisherABC
|
||||
from .publisher_service import PublisherService
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -426,7 +426,7 @@ class PublisherService(PublisherABC):
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self.exclude(f'*/{self._config.get_configuration("ProjectName")}.json')
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'build'))
|
||||
|
||||
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -449,7 +449,7 @@ class PublisherService(PublisherABC):
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self.exclude(f'*/{self._config.get_configuration("ProjectName")}.json')
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'publish'))
|
||||
|
||||
Console.write_line('Build:')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.source_creator'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,5 +1,23 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.command.add_service import AddService
|
||||
from cpl_cli.command.build_service import BuildService
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.command.generate_service import GenerateService
|
||||
from cpl_cli.command.help_service import HelpService
|
||||
from cpl_cli.command.install_service import InstallService
|
||||
from cpl_cli.command.new_service import NewService
|
||||
from cpl_cli.command.publish_service import PublishService
|
||||
from cpl_cli.command.remove_service import RemoveService
|
||||
from cpl_cli.command.run_service import RunService
|
||||
from cpl_cli.command.start_service import StartService
|
||||
from cpl_cli.command.uninstall_service import UninstallService
|
||||
from cpl_cli.command.update_service import UpdateService
|
||||
from cpl_cli.command.version_service import VersionService
|
||||
from cpl_cli.validators.project_validator import ProjectValidator
|
||||
|
||||
from cpl_cli.validators.workspace_validator import WorkspaceValidator
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
from cpl_cli.error import Error
|
||||
@@ -37,4 +55,22 @@ class Startup(StartupABC):
|
||||
services.add_transient(PublisherABC, PublisherService)
|
||||
services.add_transient(LiveServerService)
|
||||
|
||||
services.add_transient(WorkspaceValidator)
|
||||
services.add_transient(ProjectValidator)
|
||||
|
||||
services.add_transient(AddService)
|
||||
services.add_transient(BuildService)
|
||||
services.add_transient(CustomScriptService)
|
||||
services.add_transient(GenerateService)
|
||||
services.add_transient(HelpService)
|
||||
services.add_transient(InstallService)
|
||||
services.add_transient(NewService)
|
||||
services.add_transient(PublishService)
|
||||
services.add_transient(RemoveService)
|
||||
services.add_transient(RunService)
|
||||
services.add_transient(StartService)
|
||||
services.add_transient(UninstallService)
|
||||
services.add_transient(UpdateService)
|
||||
services.add_transient(VersionService)
|
||||
|
||||
return services.build_service_provider()
|
||||
|
@@ -1,11 +1,5 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
from cpl_cli.command.add_service import AddService
|
||||
from cpl_cli.command.build_service import BuildService
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.command.generate_service import GenerateService
|
||||
from cpl_cli.command.help_service import HelpService
|
||||
from cpl_cli.command.install_service import InstallService
|
||||
@@ -17,7 +11,6 @@ from cpl_cli.command.start_service import StartService
|
||||
from cpl_cli.command.uninstall_service import UninstallService
|
||||
from cpl_cli.command.update_service import UpdateService
|
||||
from cpl_cli.command.version_service import VersionService
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_cli.validators.project_validator import ProjectValidator
|
||||
from cpl_cli.validators.workspace_validator import WorkspaceValidator
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
@@ -25,7 +18,6 @@ from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class StartupArgumentExtension(StartupExtensionABC):
|
||||
@@ -33,40 +25,7 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _search_project_json(working_directory: str) -> Optional[str]:
|
||||
project_name = None
|
||||
name = os.path.basename(working_directory)
|
||||
for r, d, f in os.walk(working_directory):
|
||||
for file in f:
|
||||
if file.endswith('.json'):
|
||||
f_name = file.split('.json')[0]
|
||||
if f_name == name or String.convert_to_camel_case(f_name).lower() == String.convert_to_camel_case(name).lower():
|
||||
project_name = f_name
|
||||
break
|
||||
|
||||
return project_name
|
||||
|
||||
def _read_cpl_environment(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
workspace: Optional[WorkspaceSettings] = config.get_configuration(WorkspaceSettings)
|
||||
config.add_configuration('PATH_WORKSPACE', env.working_directory)
|
||||
if workspace is not None:
|
||||
for script in workspace.scripts:
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', script, [], CustomScriptService)
|
||||
return
|
||||
|
||||
project = self._search_project_json(env.working_directory)
|
||||
if project is not None:
|
||||
project = f'{project}.json'
|
||||
|
||||
if project is None:
|
||||
return
|
||||
|
||||
config.add_json_file(project, optional=True, output=False)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
config.add_json_file('cpl-workspace.json', path=env.working_directory, optional=True, output=False)
|
||||
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'add', ['a', 'A'], AddService, True, validators=[WorkspaceValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'build', ['b', 'B'], BuildService, True, validators=[ProjectValidator])
|
||||
@@ -81,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) \
|
||||
@@ -91,13 +51,15 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'application-base', ['ab', 'AB']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'startup', ['s', 'S']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'service-providing', ['sp', 'SP']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'nothing', ['n', 'N'])
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'nothing', ['n', 'N']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'venv', ['v', 'V'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
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]) \
|
||||
@@ -107,23 +69,5 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
config.for_each_argument(lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, '--', 'help', ['h', 'H']))
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'help', ['h', 'H'], HelpService)
|
||||
|
||||
self._read_cpl_environment(config, env)
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(WorkspaceValidator)
|
||||
services.add_transient(ProjectValidator)
|
||||
|
||||
services.add_transient(AddService)
|
||||
services.add_transient(BuildService)
|
||||
services.add_transient(CustomScriptService)
|
||||
services.add_transient(GenerateService)
|
||||
services.add_transient(HelpService)
|
||||
services.add_transient(InstallService)
|
||||
services.add_transient(NewService)
|
||||
services.add_transient(PublishService)
|
||||
services.add_transient(RemoveService)
|
||||
services.add_transient(RunService)
|
||||
services.add_transient(StartService)
|
||||
services.add_transient(UninstallService)
|
||||
services.add_transient(UpdateService)
|
||||
services.add_transient(VersionService)
|
||||
pass
|
||||
|
55
src/cpl_cli/startup_workspace_extension.py
Normal file
55
src/cpl_cli/startup_workspace_extension.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class StartupWorkspaceExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _search_project_json(working_directory: str) -> Optional[str]:
|
||||
project_name = None
|
||||
name = os.path.basename(working_directory)
|
||||
for r, d, f in os.walk(working_directory):
|
||||
for file in f:
|
||||
if file.endswith('.json'):
|
||||
f_name = file.split('.json')[0]
|
||||
if f_name == name or String.convert_to_camel_case(f_name).lower() == String.convert_to_camel_case(name).lower():
|
||||
project_name = f_name
|
||||
break
|
||||
|
||||
return project_name
|
||||
|
||||
def _read_cpl_environment(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
workspace: Optional[WorkspaceSettings] = config.get_configuration(WorkspaceSettings)
|
||||
config.add_configuration('PATH_WORKSPACE', env.working_directory)
|
||||
if workspace is not None:
|
||||
for script in workspace.scripts:
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', script, [], CustomScriptService)
|
||||
return
|
||||
|
||||
project = self._search_project_json(env.working_directory)
|
||||
if project is not None:
|
||||
project = f'{project}.json'
|
||||
|
||||
if project is None:
|
||||
return
|
||||
|
||||
config.add_json_file(project, optional=True, output=False)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
config.add_json_file('cpl-workspace.json', path=env.working_directory, optional=True, output=False)
|
||||
self._read_cpl_environment(config, env)
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.validators'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev10'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev10')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_core'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .startup_abc import StartupABC
|
||||
from .startup_extension_abc import StartupExtensionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -34,4 +34,4 @@ from .validator_abc import ValidatorABC
|
||||
from .variable_argument import VariableArgument
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum
|
||||
from .spinner_thread import SpinnerThread
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -28,6 +28,7 @@
|
||||
"watchdog==2.1.7",
|
||||
"wheel==0.37.1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings
|
||||
from .table_abc import TableABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection
|
||||
from .database_connection_abc import DatabaseConnectionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .database_context import DatabaseContext
|
||||
from .database_context_abc import DatabaseContextABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -30,4 +30,4 @@ from .service_provider import ServiceProvider
|
||||
from .service_provider_abc import ServiceProviderABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum
|
||||
from .application_environment import ApplicationEnvironment
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings
|
||||
from .logging_settings_name_enum import LoggingSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings
|
||||
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.pipes'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -29,4 +29,4 @@ from .to_camel_case_pipe import ToCamelCasePipe
|
||||
from .to_snake_case_pipe import ToSnakeCasePipe
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings
|
||||
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .string import String
|
||||
from .pip import Pip
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,19 +4,22 @@ import sys
|
||||
from contextlib import suppress
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class Pip:
|
||||
r"""Executes pip commands"""
|
||||
_executable = sys.executable
|
||||
_env = os.environ
|
||||
_is_venv = False
|
||||
|
||||
"""Getter"""
|
||||
|
||||
@classmethod
|
||||
def get_executable(cls) -> str:
|
||||
return cls._executable
|
||||
|
||||
"""Setter"""
|
||||
|
||||
@classmethod
|
||||
def set_executable(cls, executable: str):
|
||||
r"""Sets the executable
|
||||
@@ -26,25 +29,28 @@ class Pip:
|
||||
executable: :class:`str`
|
||||
The python command
|
||||
"""
|
||||
if executable is not None and executable != sys.executable:
|
||||
cls._executable = executable
|
||||
if os.path.islink(cls._executable):
|
||||
cls._is_venv = True
|
||||
path = os.path.dirname(os.path.dirname(cls._executable))
|
||||
cls._env = os.environ
|
||||
if sys.platform == 'win32':
|
||||
cls._env['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
cls._env['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
cls._env['VIRTUAL_ENV'] = path
|
||||
if executable is None or executable == sys.executable:
|
||||
return
|
||||
|
||||
cls._executable = executable
|
||||
if not os.path.islink(cls._executable):
|
||||
return
|
||||
|
||||
path = os.path.dirname(os.path.dirname(cls._executable))
|
||||
cls._env = os.environ
|
||||
if sys.platform == 'win32':
|
||||
cls._env['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
cls._env['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
cls._env['VIRTUAL_ENV'] = path
|
||||
|
||||
@classmethod
|
||||
def reset_executable(cls):
|
||||
r"""Resets the executable to system standard"""
|
||||
cls._executable = sys.executable
|
||||
cls._is_venv = False
|
||||
|
||||
"""Public utils functions"""
|
||||
|
||||
@classmethod
|
||||
def get_package(cls, package: str) -> Optional[str]:
|
||||
r"""Gets given package py local pip list
|
||||
@@ -60,8 +66,6 @@ class Pip:
|
||||
result = None
|
||||
with suppress(Exception):
|
||||
args = [cls._executable, "-m", "pip", "show", package]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "show", package]
|
||||
|
||||
result = subprocess.check_output(
|
||||
args,
|
||||
@@ -92,8 +96,6 @@ class Pip:
|
||||
Bytes string of the command result
|
||||
"""
|
||||
args = [cls._executable, "-m", "pip", "list", "--outdated"]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "list", "--outdated"]
|
||||
|
||||
return subprocess.check_output(args, env=cls._env)
|
||||
|
||||
@@ -115,8 +117,6 @@ class Pip:
|
||||
Stderr of subprocess.run
|
||||
"""
|
||||
pip_args = [cls._executable, "-m", "pip", "install"]
|
||||
if cls._is_venv:
|
||||
pip_args = ["pip", "install"]
|
||||
|
||||
for arg in args:
|
||||
pip_args.append(arg)
|
||||
@@ -142,8 +142,6 @@ class Pip:
|
||||
Stderr of subprocess.run
|
||||
"""
|
||||
args = [cls._executable, "-m", "pip", "uninstall", "--yes", package]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "uninstall", "--yes", package]
|
||||
|
||||
subprocess.run(
|
||||
args,
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_query._query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,6 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_query.extension'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.17.dev8'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .ordered_iterable_abc import OrderedIterableABC
|
||||
from .ordered_iterable import OrderedIterable
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='17.dev8')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -18,9 +18,10 @@
|
||||
"Dependencies": [
|
||||
"cpl_core==2022.6.1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {
|
||||
"linux": "../../../../../../cpl-env/bin/python3.9",
|
||||
"linux": "../../venv/bin/python",
|
||||
"win32": ""
|
||||
},
|
||||
"Classifiers": []
|
||||
|
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -55,9 +55,13 @@ class Application(ApplicationABC):
|
||||
return
|
||||
|
||||
try:
|
||||
|
||||
version[VersionSettingsNameEnum.major.value] = branch.split('.')[0]
|
||||
version[VersionSettingsNameEnum.minor.value] = branch.split('.')[1]
|
||||
version[VersionSettingsNameEnum.micro.value] = f'{branch.split(".")[2]}{suffix}'
|
||||
if len(branch.split('.')) == 2:
|
||||
version[VersionSettingsNameEnum.micro.value] = f'0{suffix}'
|
||||
else:
|
||||
version[VersionSettingsNameEnum.micro.value] = f'{branch.split(".")[2]}{suffix}'
|
||||
except Exception as e:
|
||||
Console.error(f'Branch {branch} does not contain valid version')
|
||||
return
|
||||
|
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8",
|
||||
"cpl-core>=2022.6.0.rc1",
|
||||
"gitpython==3.1.27"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
|
@@ -1,10 +1,88 @@
|
||||
import filecmp
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class BuildTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'build-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def _are_dir_trees_equal(self, dir1, dir2):
|
||||
"""
|
||||
found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi
|
||||
|
||||
Compare two directories recursively. Files in each directory are
|
||||
assumed to be equal if their names and contents are equal.
|
||||
|
||||
@param dir1: First directory path
|
||||
@param dir2: Second directory path
|
||||
|
||||
@return: True if the directory trees are the same and
|
||||
there were no errors while accessing the directories or files,
|
||||
False otherwise.
|
||||
"""
|
||||
|
||||
dirs_cmp = filecmp.dircmp(dir1, dir2)
|
||||
if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or len(dirs_cmp.funny_files) > 0:
|
||||
return False
|
||||
|
||||
(_, mismatch, errors) = filecmp.cmpfiles(dir1, dir2, dirs_cmp.common_files, shallow=False)
|
||||
|
||||
if len(mismatch) > 0 or len(errors) > 0:
|
||||
return False
|
||||
|
||||
for common_dir in dirs_cmp.common_dirs:
|
||||
new_dir1 = os.path.join(dir1, common_dir)
|
||||
new_dir2 = os.path.join(dir2, common_dir)
|
||||
if not self._are_dir_trees_equal(new_dir1, new_dir2):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def test_build(self):
|
||||
CLICommands.build()
|
||||
dist_path = './dist'
|
||||
full_dist_path = f'{dist_path}/{self._source}/build/{String.convert_to_snake_case(self._source)}'
|
||||
self.assertTrue(os.path.exists(dist_path))
|
||||
self.assertTrue(os.path.exists(full_dist_path))
|
||||
self.assertFalse(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
with open(f'{full_dist_path}/{self._source}.json', 'w') as file:
|
||||
file.write(json.dumps(self._get_project_settings(), indent=2))
|
||||
file.close()
|
||||
self.assertTrue(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
|
@@ -6,10 +6,18 @@ from typing import Optional
|
||||
from unittest import TestResult
|
||||
|
||||
from unittests_cli.add_test_case import AddTestCase
|
||||
from unittests_cli.build_test_case import BuildTestCase
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_cli.generate_test_case import GenerateTestCase
|
||||
from unittests_cli.install_test_case import InstallTestCase
|
||||
from unittests_cli.new_test_case import NewTestCase
|
||||
from unittests_cli.publish_test_case import PublishTestCase
|
||||
from unittests_cli.remove_test_case import RemoveTestCase
|
||||
from unittests_cli.run_test_case import RunTestCase
|
||||
from unittests_cli.start_test_case import StartTestCase
|
||||
from unittests_cli.uninstall_test_case import UninstallTestCase
|
||||
from unittests_cli.update_test_case import UpdateTestCase
|
||||
from unittests_cli.version_test_case import VersionTestCase
|
||||
|
||||
|
||||
class CLITestSuite(unittest.TestSuite):
|
||||
@@ -19,23 +27,30 @@ class CLITestSuite(unittest.TestSuite):
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
self._result: Optional[TestResult] = None
|
||||
# nothing needed
|
||||
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
|
||||
self.addTests(loader.loadTestsFromTestCase(NewTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(VersionTestCase))
|
||||
self._is_online = True
|
||||
|
||||
# project needed
|
||||
# self.addTests(loader.loadTestsFromTestCase(BuildTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(InstallTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(PublishTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(RunTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(StartTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(UninstallTestCase))
|
||||
# self.addTests(loader.loadTestsFromTestCase(UpdateTestCase))
|
||||
active_tests = [
|
||||
# nothing needed
|
||||
VersionTestCase,
|
||||
GenerateTestCase,
|
||||
NewTestCase,
|
||||
# project needed
|
||||
BuildTestCase,
|
||||
PublishTestCase,
|
||||
RunTestCase,
|
||||
StartTestCase,
|
||||
# workspace needed
|
||||
AddTestCase,
|
||||
RemoveTestCase
|
||||
]
|
||||
|
||||
# workspace needed
|
||||
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
||||
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
||||
if self._is_online:
|
||||
active_tests.append(InstallTestCase)
|
||||
active_tests.append(UninstallTestCase)
|
||||
active_tests.append(UpdateTestCase)
|
||||
|
||||
for test in active_tests:
|
||||
self.addTests(loader.loadTestsFromTestCase(test))
|
||||
|
||||
def _setup(self):
|
||||
try:
|
||||
|
@@ -1,10 +1,127 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class InstallTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'install-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
|
||||
def test_install_package(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
CLICommands.install(package)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
||||
def test_dev_install_package(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
CLICommands.install(package, is_dev=True)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn(
|
||||
package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
||||
def _test_install_all(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
settings = self._get_project_settings()
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
settings['ProjectSettings']['Dependencies'].append(package)
|
||||
settings['ProjectSettings']['DevDependencies'].append(package)
|
||||
self._save_project_settings(settings)
|
||||
CLICommands.install()
|
||||
new_settings = self._get_project_settings()
|
||||
self.assertEqual(settings, new_settings)
|
||||
self.assertIn('ProjectSettings', new_settings)
|
||||
self.assertIn('Dependencies', new_settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', new_settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
package,
|
||||
new_settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn(
|
||||
package,
|
||||
new_settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
|
@@ -1,10 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
@@ -14,10 +12,15 @@ class NewTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
|
||||
def _test_project(self, project_type: str, name: str, *args):
|
||||
def _test_project(self, project_type: str, name: str, *args, test_venv=False):
|
||||
CLICommands.new(project_type, name, *args)
|
||||
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name))
|
||||
self.assertTrue(os.path.exists(workspace_path))
|
||||
if test_venv:
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name, 'src', String.convert_to_snake_case(name)))
|
||||
self.assertTrue(os.path.exists(project_path))
|
||||
@@ -40,11 +43,16 @@ class NewTestCase(unittest.TestCase):
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'test_case.py')))
|
||||
|
||||
def _test_sub_project(self, project_type: str, name: str, workspace_name: str, *args):
|
||||
def _test_sub_project(self, project_type: str, name: str, workspace_name: str, *args, test_venv=False):
|
||||
os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
|
||||
CLICommands.new(project_type, name, *args)
|
||||
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name))
|
||||
self.assertTrue(os.path.exists(workspace_path))
|
||||
if test_venv:
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, 'src', String.convert_to_snake_case(name)))
|
||||
self.assertTrue(os.path.exists(project_path))
|
||||
@@ -78,7 +86,7 @@ class NewTestCase(unittest.TestCase):
|
||||
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
|
||||
|
||||
def test_console(self):
|
||||
self._test_project('console', 'test-console', '--ab', '--s')
|
||||
self._test_project('console', 'test-console', '--ab', '--s', '--venv', test_venv=True)
|
||||
|
||||
def test_console_without_s(self):
|
||||
self._test_project('console', 'test-console-without-s', '--ab')
|
||||
@@ -90,7 +98,7 @@ class NewTestCase(unittest.TestCase):
|
||||
self._test_project('console', 'test-console-without-anything', '--n')
|
||||
|
||||
def test_sub_console(self):
|
||||
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp')
|
||||
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', test_venv=True)
|
||||
|
||||
def test_library(self):
|
||||
self._test_project('library', 'test-library', '--ab', '--s', '--sp')
|
||||
|
@@ -1,10 +1,92 @@
|
||||
import filecmp
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class PublishTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'publish-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def _are_dir_trees_equal(self, dir1, dir2):
|
||||
"""
|
||||
found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi
|
||||
|
||||
Compare two directories recursively. Files in each directory are
|
||||
assumed to be equal if their names and contents are equal.
|
||||
|
||||
@param dir1: First directory path
|
||||
@param dir2: Second directory path
|
||||
|
||||
@return: True if the directory trees are the same and
|
||||
there were no errors while accessing the directories or files,
|
||||
False otherwise.
|
||||
"""
|
||||
|
||||
dirs_cmp = filecmp.dircmp(dir1, dir2)
|
||||
if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or len(dirs_cmp.funny_files) > 0:
|
||||
return False
|
||||
|
||||
(_, mismatch, errors) = filecmp.cmpfiles(dir1, dir2, dirs_cmp.common_files, shallow=False)
|
||||
|
||||
if len(mismatch) > 0 or len(errors) > 0:
|
||||
return False
|
||||
|
||||
for common_dir in dirs_cmp.common_dirs:
|
||||
new_dir1 = os.path.join(dir1, common_dir)
|
||||
new_dir2 = os.path.join(dir2, common_dir)
|
||||
if not self._are_dir_trees_equal(new_dir1, new_dir2):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def test_publish(self):
|
||||
CLICommands.publish()
|
||||
dist_path = './dist'
|
||||
setup_path = f'{dist_path}/{self._source}/publish/setup'
|
||||
full_dist_path = f'{dist_path}/{self._source}/publish/build/lib/{String.convert_to_snake_case(self._source)}'
|
||||
self.assertTrue(os.path.exists(dist_path))
|
||||
self.assertTrue(os.path.exists(setup_path))
|
||||
self.assertTrue(os.path.exists(os.path.join(setup_path, f'{self._source}-0.0.0.tar.gz')))
|
||||
self.assertTrue(os.path.exists(os.path.join(setup_path, f'{String.convert_to_snake_case(self._source)}-0.0.0-py3-none-any.whl')))
|
||||
self.assertTrue(os.path.exists(full_dist_path))
|
||||
self.assertFalse(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
with open(f'{full_dist_path}/{self._source}.json', 'w') as file:
|
||||
file.write(json.dumps(self._get_project_settings(), indent=2))
|
||||
file.close()
|
||||
self.assertTrue(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
|
@@ -1,10 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
@@ -1,10 +1,91 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import pkg_resources
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class RunTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'run-test'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||
self._test_code = f"""
|
||||
import json
|
||||
settings = dict()
|
||||
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
settings = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
settings['RunTest']['WasStarted'] = 'True'
|
||||
|
||||
with open('appsettings.json', 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
"""
|
||||
|
||||
def _get_appsettings(self):
|
||||
with open(os.path.join(os.getcwd(), self._appsettings), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_appsettings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._appsettings), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
settings = {'RunTest': {'WasStarted': 'False'}}
|
||||
self._save_appsettings(settings)
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'\t\t{self._test_code}')
|
||||
file.close()
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def test_run(self):
|
||||
CLICommands.run()
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
|
||||
def test_run_by_project(self):
|
||||
os.chdir(os.path.join(os.getcwd()))
|
||||
CLICommands.run(self._source)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
|
@@ -1,10 +1,101 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_cli.threads.start_test_thread import StartTestThread
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class StartTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'start-test'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||
self._test_code = f"""
|
||||
import json
|
||||
settings = dict()
|
||||
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
settings = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
if settings['RunTest']['WasStarted'] == 'True':
|
||||
settings['RunTest']['WasRestarted'] = 'True'
|
||||
|
||||
settings['RunTest']['WasStarted'] = 'True'
|
||||
|
||||
with open('appsettings.json', 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
"""
|
||||
|
||||
def _get_appsettings(self):
|
||||
with open(os.path.join(os.getcwd(), self._appsettings), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_appsettings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._appsettings), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
settings = {'RunTest': {'WasStarted': 'False', 'WasRestarted': 'False'}}
|
||||
self._save_appsettings(settings)
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'\t\t{self._test_code}')
|
||||
file.close()
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def test_start(self):
|
||||
thread = StartTestThread()
|
||||
thread.start()
|
||||
time.sleep(1)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'# trigger restart (comment generated by unittest)')
|
||||
file.close()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertIn('WasRestarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasRestarted']
|
||||
)
|
||||
|
1
unittests/unittests_cli/threads/__init__.py
Normal file
1
unittests/unittests_cli/threads/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# imports
|
12
unittests/unittests_cli/threads/start_test_thread.py
Normal file
12
unittests/unittests_cli/threads/start_test_thread.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import threading
|
||||
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class StartTestThread(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self, daemon=True)
|
||||
|
||||
def run(self):
|
||||
CLICommands.start(True)
|
@@ -1,10 +1,83 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class UninstallTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'uninstall-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._version = '1.7.3'
|
||||
self._package_name = 'discord.py'
|
||||
self._package = f'{self._package_name}=={self._version}'
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
|
||||
def test_uninstall(self):
|
||||
CLICommands.install(self._package)
|
||||
CLICommands.uninstall(self._package)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertNotIn(self._package_name, packages)
|
||||
|
||||
def test_dev_uninstall(self):
|
||||
CLICommands.install(self._package, is_dev=True)
|
||||
CLICommands.uninstall(self._package, is_dev=True)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertNotIn(self._package_name, packages)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev10"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,8 +16,8 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8",
|
||||
"cpl-cli>=2022.6.17.dev10"
|
||||
"cpl-core>=2022.6.0.rc1",
|
||||
"cpl-cli>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
|
@@ -1,10 +1,88 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from cpl_core.utils import String
|
||||
from unittests_cli.constants import PLAYGROUND_PATH
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class UpdateTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._source = 'install-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
|
||||
self._old_version = '1.7.1'
|
||||
self._old_package_name = 'discord.py'
|
||||
self._old_package = f'{self._old_package_name}=={self._old_version}'
|
||||
|
||||
self._new_version = '1.7.3'
|
||||
self._new_package_name = 'discord.py'
|
||||
self._new_package = f'{self._new_package_name}=={self._new_version}'
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
CLICommands.uninstall(self._old_package)
|
||||
CLICommands.uninstall(self._new_package)
|
||||
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.install(self._old_package)
|
||||
|
||||
def cleanUp(self):
|
||||
# remove projects
|
||||
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
|
||||
return
|
||||
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
|
||||
def test_install_package(self):
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
self._old_package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(self._old_package_name, packages)
|
||||
self.assertEqual(self._old_version, packages[self._old_package_name])
|
||||
|
||||
CLICommands.update()
|
||||
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
self._new_package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(self._new_package_name, packages)
|
||||
self.assertEqual(self._new_version, packages[self._new_package_name])
|
||||
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
|
@@ -1,10 +1,97 @@
|
||||
import pkgutil
|
||||
import platform
|
||||
import sys
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
import pkg_resources
|
||||
from art import text2art
|
||||
from tabulate import tabulate
|
||||
|
||||
import cpl_cli
|
||||
from cpl_core.console import ForegroundColorEnum
|
||||
from termcolor import colored
|
||||
|
||||
from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class VersionTestCase(unittest.TestCase):
|
||||
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._block_banner = ""
|
||||
self._block_version = ""
|
||||
self._block_package_header = ""
|
||||
self._block_cpl_packages = ""
|
||||
self._block_packages = ""
|
||||
self._name = "CPL CLI"
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
def _get_version_output(self, version: str):
|
||||
index = 0
|
||||
|
||||
for line in version.split('\n'):
|
||||
if line == "":
|
||||
continue
|
||||
|
||||
if index <= 5:
|
||||
self._block_banner += f'{line}\n'
|
||||
|
||||
if 7 <= index <= 9:
|
||||
self._block_version += f'{line}\n'
|
||||
|
||||
if 10 <= index <= 15:
|
||||
self._block_cpl_packages += f'{line}\n'
|
||||
|
||||
if index >= 17:
|
||||
self._block_packages += f'{line}\n'
|
||||
|
||||
index += 1
|
||||
|
||||
def test_version(self):
|
||||
version = CLICommands.version()
|
||||
self._get_version_output(version)
|
||||
reference_banner = colored(text2art(self._name), ForegroundColorEnum.yellow.value).split('\n')
|
||||
reference_banner = "\n".join(reference_banner[:len(reference_banner) - 1]) + '\n'
|
||||
self.assertEqual(reference_banner, self._block_banner)
|
||||
|
||||
reference_version = [
|
||||
colored(f'{colored("Common Python library CLI: ")}{colored(cpl_cli.__version__)}'),
|
||||
colored(f'{colored("Python: ")}{colored(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")}'),
|
||||
colored(f'OS: {colored(f"{platform.system()} {platform.processor()}")}') + '\n'
|
||||
]
|
||||
self.assertEqual('\n'.join(reference_version), self._block_version)
|
||||
packages = []
|
||||
cpl_packages = [
|
||||
'cpl_core',
|
||||
'cpl_cli',
|
||||
'cpl_query'
|
||||
]
|
||||
for modname in cpl_packages:
|
||||
module = pkgutil.find_loader(modname)
|
||||
if module is None:
|
||||
break
|
||||
|
||||
module = module.load_module(modname)
|
||||
if '__version__' in dir(module):
|
||||
packages.append([f'{modname}', module.__version__])
|
||||
|
||||
reference_cpl_packages = [
|
||||
colored(colored(f'CPL packages:')),
|
||||
colored(f'{tabulate(packages, headers=["Name", "Version"])}') + '\n'
|
||||
]
|
||||
self.assertEqual('\n'.join(reference_cpl_packages), self._block_cpl_packages)
|
||||
|
||||
packages = []
|
||||
dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
|
||||
for p in dependencies:
|
||||
packages.append([p, dependencies[p]])
|
||||
|
||||
reference_packages = [
|
||||
colored(colored(f'Python packages:')),
|
||||
colored(f'{tabulate(packages, headers=["Name", "Version"])}'),
|
||||
'\x1b[0m\x1b[0m\n\x1b[0m\x1b[0m\n' # fix colored codes
|
||||
]
|
||||
self.assertEqual('\n'.join(reference_packages), self._block_packages)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,8 +16,8 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8",
|
||||
"cpl-query>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1",
|
||||
"cpl-query>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
|
@@ -15,20 +15,73 @@ class CLICommands:
|
||||
for arg in args:
|
||||
command.append(arg)
|
||||
|
||||
subprocess.run(command, env=env_vars)
|
||||
if output:
|
||||
subprocess.run(command, env=env_vars)
|
||||
else:
|
||||
subprocess.run(command, env=env_vars, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
|
||||
|
||||
@staticmethod
|
||||
def _run_with_output(cmd: str, *args) -> str:
|
||||
env_vars = os.environ
|
||||
env_vars['CPL_IS_UNITTEST'] = 'NO'
|
||||
|
||||
command = ['python', CLI_PATH, cmd]
|
||||
for arg in args:
|
||||
command.append(arg)
|
||||
|
||||
return subprocess.run(command, env=env_vars, check=True, capture_output=True, text=True).stdout
|
||||
|
||||
@classmethod
|
||||
def add(cls, source: str, target: str):
|
||||
cls._run('add', source, target)
|
||||
def add(cls, source: str, target: str, output=False):
|
||||
cls._run('add', source, target, output=output)
|
||||
|
||||
@classmethod
|
||||
def build(cls, output=False):
|
||||
cls._run('build', output=output)
|
||||
|
||||
@classmethod
|
||||
def generate(cls, schematic: str, name: str, output=False):
|
||||
cls._run('generate', schematic, name, output=output)
|
||||
|
||||
@classmethod
|
||||
def install(cls, package: str = None, is_dev=False, output=False):
|
||||
if package is None:
|
||||
cls._run('install', output=output)
|
||||
return
|
||||
|
||||
cls._run('install', package, '--dev' if is_dev else '', output=output)
|
||||
|
||||
@classmethod
|
||||
def new(cls, project_type: str, name: str, *args, output=False):
|
||||
cls._run('new', project_type, name, *args, output=output)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, project: str):
|
||||
cls._run('remove', project)
|
||||
def publish(cls, output=False):
|
||||
cls._run('publish', output=output)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, project: str, output=False):
|
||||
cls._run('remove', project, output=output)
|
||||
|
||||
@classmethod
|
||||
def run(cls, project: str = None, output=False):
|
||||
if project is None:
|
||||
cls._run('run', output=output)
|
||||
return
|
||||
cls._run('run', project, output=output)
|
||||
|
||||
@classmethod
|
||||
def start(cls, output=False):
|
||||
cls._run('start', output=output)
|
||||
|
||||
@classmethod
|
||||
def uninstall(cls, package: str, is_dev=False, output=False):
|
||||
cls._run('uninstall', package, '--dev' if is_dev else '', output=output)
|
||||
|
||||
@classmethod
|
||||
def update(cls, output=False):
|
||||
cls._run('update', output=output)
|
||||
|
||||
@classmethod
|
||||
def version(cls) -> str:
|
||||
return cls._run_with_output('version')
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "17.dev8"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.17.dev8"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
|
Reference in New Issue
Block a user