Fixed some broken references

This commit is contained in:
Sven Heidemann 2023-04-05 18:03:13 +02:00
parent 9a6ce704b7
commit 8624549aa6
9 changed files with 31 additions and 67 deletions

View File

@ -3,14 +3,14 @@ import os
import textwrap
from typing import Optional
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_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.workspace_settings import WorkspaceSettings
from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
class AddService(CommandABC):

View File

@ -270,7 +270,7 @@ class InstallService(CommandABC):
args.remove("cpl-dev")
self._cli_settings.from_dict({"PipPath": "https://pip-dev.sh-edraft.de"})
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings.python_executable)
if len(args) == 0:
self._install_project()

View File

@ -11,12 +11,11 @@ import cpl_cli
import cpl_core
from cpl_cli.abc.project_type_abc import ProjectTypeABC
from cpl_cli.command_abc import CommandABC
from cpl_cli.configuration import VersionSettings, VersionSettingsNameEnum
from cpl_cli.configuration import VersionSettings
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.build_settings_name_enum import BuildSettingsNameEnum
from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsNameEnum
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
from cpl_cli.configuration.settings_helper import SettingsHelper
from cpl_cli.configuration.venv_helper_service import VenvHelper
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.helper.dependencies import Dependencies
@ -39,10 +38,10 @@ class NewService(CommandABC):
self._env = self._config.environment
self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
self._project: ProjectSettings = ProjectSettings()
self._project_dict = {}
self._build: BuildSettings = BuildSettings()
self._build_dict = {}
self._project_name = ""
self._python_executable = ""
self._project_type_classes = set()
@ -76,32 +75,12 @@ class NewService(CommandABC):
)
def _create_project_settings(self):
self._project_name = os.path.basename(self._name)
self._python_executable = ProjectSettings(
python_path={sys.platform: "../../venv/" if self._use_venv else ""}
).python_executable
self._rel_path = os.path.dirname(self._name)
self._project_dict = {
ProjectSettingsNameEnum.name.value: os.path.basename(self._name),
ProjectSettingsNameEnum.version.value: {
VersionSettingsNameEnum.major.value: "0",
VersionSettingsNameEnum.minor.value: "0",
VersionSettingsNameEnum.micro.value: "0",
},
ProjectSettingsNameEnum.author.value: "",
ProjectSettingsNameEnum.author_email.value: "",
ProjectSettingsNameEnum.description.value: "",
ProjectSettingsNameEnum.long_description.value: "",
ProjectSettingsNameEnum.url.value: "",
ProjectSettingsNameEnum.copyright_date.value: "",
ProjectSettingsNameEnum.copyright_name.value: "",
ProjectSettingsNameEnum.license_name.value: "",
ProjectSettingsNameEnum.license_description.value: "",
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: "../../venv/" if self._use_venv else ""},
ProjectSettingsNameEnum.classifiers.value: [],
}
self._project.from_dict(self._project_dict)
self._project = ProjectSettings(
self._project_dict = SettingsHelper.get_project_settings_dict(ProjectSettings(
os.path.basename(self._name),
VersionSettings("0", "0", "0"),
"",
@ -119,34 +98,21 @@ class NewService(CommandABC):
{sys.platform: "../../venv/" if self._use_venv else ""},
None,
[],
)
))
def _create_build_settings(self, project_type: str):
self._build_dict = {
BuildSettingsNameEnum.project_type.value: project_type,
BuildSettingsNameEnum.source_path.value: "",
BuildSettingsNameEnum.output_path.value: "../../dist",
BuildSettingsNameEnum.main.value: f"{String.convert_to_snake_case(self._project.name)}.main",
BuildSettingsNameEnum.entry_point.value: self._project.name,
BuildSettingsNameEnum.include_package_data.value: False,
BuildSettingsNameEnum.included.value: [],
BuildSettingsNameEnum.excluded.value: ["*/__pycache__", "*/logs", "*/tests"],
BuildSettingsNameEnum.package_data.value: {},
BuildSettingsNameEnum.project_references.value: [],
}
# self._build.from_dict(self._build_dict)
self._build = BuildSettings(
self._build_dict = SettingsHelper.get_build_settings_dict(BuildSettings(
ProjectTypeEnum[project_type],
"",
"../../dist",
f"{String.convert_to_snake_case(self._project.name)}.main",
self._project.name,
f"{String.convert_to_snake_case(self._project_name)}.main",
self._project_name,
False,
[],
["*/__pycache__", "*/logs", "*/tests"],
{},
[],
)
))
def _create_project_json(self):
"""
@ -161,11 +127,11 @@ class NewService(CommandABC):
:return:
"""
if self._workspace is None:
project_path = os.path.join(self._env.working_directory, self._rel_path, self._project.name)
project_path = os.path.join(self._env.working_directory, self._rel_path, self._project_name)
else:
base = "" if self._use_base else "src"
project_path = os.path.join(
self._env.working_directory, base, self._rel_path, String.convert_to_snake_case(self._project.name)
self._env.working_directory, base, self._rel_path, String.convert_to_snake_case(self._project_name)
)
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
@ -211,7 +177,7 @@ class NewService(CommandABC):
Console.set_foreground_color(ForegroundColorEnum.default)
def _create_venv(self):
project = self._project.name
project = self._project_name
if self._workspace is not None:
project = self._workspace.default_project
@ -224,9 +190,9 @@ class NewService(CommandABC):
VenvHelper.init_venv(
False,
self._env,
self._project,
self._python_executable,
explicit_path=os.path.join(
self._env.working_directory, project, self._project.python_executable.replace("../", "")
self._env.working_directory, project, self._python_executable.replace("../", "")
),
)
@ -283,7 +249,7 @@ class NewService(CommandABC):
return
self._get_project_information(project_type)
project_name = self._project.name
project_name = self._project_name
if self._rel_path != "":
project_name = f"{self._rel_path}/{project_name}"

View File

@ -84,7 +84,7 @@ class UninstallService(CommandABC):
args.remove("--simulate")
Console.write_line("Running in simulation mode:")
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings.python_executable)
package = args[0]
is_in_dependencies = False

View File

@ -34,7 +34,7 @@ class SettingsHelper:
@staticmethod
def get_build_settings_dict(build: BuildSettings) -> dict:
return {
BuildSettingsNameEnum.project_type.value: build.project_type,
BuildSettingsNameEnum.project_type.value: build.project_type.value,
BuildSettingsNameEnum.source_path.value: build.source_path,
BuildSettingsNameEnum.output_path.value: build.output_path,
BuildSettingsNameEnum.main.value: build.main,

View File

@ -12,13 +12,11 @@ from cpl_core.console import Console, ForegroundColorEnum
class VenvHelper:
@staticmethod
def init_venv(
is_virtual: bool, env: ApplicationEnvironmentABC, project_settings: ProjectSettings, explicit_path=None
):
def init_venv(is_virtual: bool, env: ApplicationEnvironmentABC, python_executable: str, explicit_path=None):
if is_virtual:
return
venv_path = os.path.abspath(os.path.join(env.working_directory, project_settings.python_executable, "../../"))
venv_path = os.path.abspath(os.path.join(env.working_directory, python_executable, "../../"))
if explicit_path is not None:
venv_path = os.path.abspath(explicit_path)
@ -32,7 +30,7 @@ class VenvHelper:
spinner_foreground_color=ForegroundColorEnum.cyan,
)
Pip.set_executable(project_settings.python_executable)
Pip.set_executable(python_executable)
@staticmethod
def create_venv(path):

View File

@ -290,7 +290,6 @@ class Configuration(ConfigurationABC):
Console.color_reset()
configuration.from_dict(value)
else:
Console.error(sub, 1)
configuration = JSONProcessor.process(sub, value)
self.add_configuration(sub, configuration)

View File

@ -25,7 +25,7 @@ class JSONProcessor:
value = values[name_first_lower]
if isinstance(value, dict) and not issubclass(parameter.annotation, dict):
value = JSONProcessor.process(dict, value)
value = JSONProcessor.process(parameter.annotation, value)
if issubclass(parameter.annotation, enum.Enum):
value = parameter.annotation[value]

View File

@ -8,6 +8,7 @@ from unittests_shared.cli_commands import CLICommands
class AddTestCase(CommandTestCase):
def __init__(self, method_name: str):
CommandTestCase.__init__(self, method_name)
self._source = "add-test-project"