Bugfixes for windows support
This commit is contained in:
parent
dffa1ac703
commit
8ef1416b35
1
cpl.json
1
cpl.json
@ -16,6 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"colorama==0.4.4",
|
||||
"mysql-connector==2.2.9",
|
||||
"psutil==5.8.0",
|
||||
"packaging==20.9",
|
||||
|
@ -11,9 +11,9 @@ from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.utils.pip import Pip
|
||||
from cpl_cli.cli_settings import CLISettings
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import ProjectSettingsNameEnum, VersionSettingsNameEnum, BuildSettingsNameEnum
|
||||
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.error import Error
|
||||
|
||||
|
||||
@ -61,43 +61,6 @@ class InstallService(CommandABC):
|
||||
|
||||
Pip.reset_executable()
|
||||
|
||||
@staticmethod
|
||||
def _get_project_settings_dict(project: ProjectSettings) -> dict:
|
||||
return {
|
||||
ProjectSettingsNameEnum.name.value: project.name,
|
||||
ProjectSettingsNameEnum.version.value: {
|
||||
VersionSettingsNameEnum.major.value: project.version.major,
|
||||
VersionSettingsNameEnum.minor.value: project.version.minor,
|
||||
VersionSettingsNameEnum.micro.value: project.version.micro
|
||||
},
|
||||
ProjectSettingsNameEnum.author.value: project.author,
|
||||
ProjectSettingsNameEnum.author_email.value: project.author_email,
|
||||
ProjectSettingsNameEnum.description.value: project.description,
|
||||
ProjectSettingsNameEnum.long_description.value: project.long_description,
|
||||
ProjectSettingsNameEnum.url.value: project.url,
|
||||
ProjectSettingsNameEnum.copyright_date.value: project.copyright_date,
|
||||
ProjectSettingsNameEnum.copyright_name.value: project.copyright_name,
|
||||
ProjectSettingsNameEnum.license_name.value: project.license_name,
|
||||
ProjectSettingsNameEnum.license_description.value: project.license_description,
|
||||
ProjectSettingsNameEnum.dependencies.value: project.dependencies,
|
||||
ProjectSettingsNameEnum.python_version.value: project.python_version,
|
||||
ProjectSettingsNameEnum.python_path.value: project.python_path,
|
||||
ProjectSettingsNameEnum.classifiers.value: project.classifiers
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_build_settings_dict(build: BuildSettings) -> dict:
|
||||
return {
|
||||
BuildSettingsNameEnum.source_path.value: build.source_path,
|
||||
BuildSettingsNameEnum.output_path.value: build.output_path,
|
||||
BuildSettingsNameEnum.main.value: build.main,
|
||||
BuildSettingsNameEnum.entry_point.value: build.entry_point,
|
||||
BuildSettingsNameEnum.include_package_data.value: build.include_package_data,
|
||||
BuildSettingsNameEnum.included.value: build.included,
|
||||
BuildSettingsNameEnum.excluded.value: build.excluded,
|
||||
BuildSettingsNameEnum.package_data.value: build.package_data
|
||||
}
|
||||
|
||||
def _install_package(self, package: str):
|
||||
"""
|
||||
Installs given package
|
||||
@ -171,8 +134,8 @@ class InstallService(CommandABC):
|
||||
project.dependencies.append(new_package)
|
||||
|
||||
config = {
|
||||
ProjectSettings.__name__: self._get_project_settings_dict(project),
|
||||
BuildSettings.__name__: self._get_build_settings_dict(build)
|
||||
ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(project),
|
||||
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(build)
|
||||
}
|
||||
with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'w') as project_file:
|
||||
project_file.write(json.dumps(config, indent=2))
|
||||
|
@ -7,9 +7,9 @@ from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.utils.pip import Pip
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import ProjectSettingsNameEnum, VersionSettingsNameEnum, BuildSettingsNameEnum
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
|
||||
|
||||
class UninstallService(CommandABC):
|
||||
@ -29,41 +29,6 @@ class UninstallService(CommandABC):
|
||||
self._build_settings = build_settings
|
||||
self._project_settings = project_settings
|
||||
|
||||
@staticmethod
|
||||
def _get_project_settings_dict(project: ProjectSettings) -> dict:
|
||||
return {
|
||||
ProjectSettingsNameEnum.name.value: project.name,
|
||||
ProjectSettingsNameEnum.version.value: {
|
||||
VersionSettingsNameEnum.major.value: project.version.major,
|
||||
VersionSettingsNameEnum.minor.value: project.version.minor,
|
||||
VersionSettingsNameEnum.micro.value: project.version.micro
|
||||
},
|
||||
ProjectSettingsNameEnum.author.value: project.author,
|
||||
ProjectSettingsNameEnum.author_email.value: project.author_email,
|
||||
ProjectSettingsNameEnum.description.value: project.description,
|
||||
ProjectSettingsNameEnum.long_description.value: project.long_description,
|
||||
ProjectSettingsNameEnum.url.value: project.url,
|
||||
ProjectSettingsNameEnum.copyright_date.value: project.copyright_date,
|
||||
ProjectSettingsNameEnum.copyright_name.value: project.copyright_name,
|
||||
ProjectSettingsNameEnum.license_name.value: project.license_name,
|
||||
ProjectSettingsNameEnum.license_description.value: project.license_description,
|
||||
ProjectSettingsNameEnum.dependencies.value: project.dependencies,
|
||||
ProjectSettingsNameEnum.python_version.value: project.python_version
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_build_settings_dict(build: BuildSettings) -> dict:
|
||||
return {
|
||||
BuildSettingsNameEnum.source_path.value: build.source_path,
|
||||
BuildSettingsNameEnum.output_path.value: build.output_path,
|
||||
BuildSettingsNameEnum.main.value: build.main,
|
||||
BuildSettingsNameEnum.entry_point.value: build.entry_point,
|
||||
BuildSettingsNameEnum.include_package_data.value: build.include_package_data,
|
||||
BuildSettingsNameEnum.included.value: build.included,
|
||||
BuildSettingsNameEnum.excluded.value: build.excluded,
|
||||
BuildSettingsNameEnum.package_data.value: build.package_data
|
||||
}
|
||||
|
||||
def run(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
@ -106,8 +71,8 @@ class UninstallService(CommandABC):
|
||||
if package in self._project_settings.dependencies:
|
||||
self._project_settings.dependencies.remove(package)
|
||||
config = {
|
||||
ProjectSettings.__name__: self._get_project_settings_dict(self._project_settings),
|
||||
BuildSettings.__name__: self._get_build_settings_dict(self._build_settings)
|
||||
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._runtime.working_directory, 'cpl.json'), 'w') as project_file:
|
||||
project_file.write(json.dumps(config, indent=2))
|
||||
|
@ -8,20 +8,29 @@ from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.utils.pip import Pip
|
||||
from cpl_cli.cli_settings import CLISettings
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
|
||||
|
||||
class UpdateService(CommandABC):
|
||||
|
||||
def __init__(self, runtime: ApplicationRuntimeABC, project_settings: ProjectSettings, cli_settings: CLISettings):
|
||||
def __init__(self,
|
||||
runtime: ApplicationRuntimeABC,
|
||||
build_settings: BuildSettings,
|
||||
project_settings: ProjectSettings,
|
||||
cli_settings: CLISettings):
|
||||
"""
|
||||
Service for the CLI command update
|
||||
:param runtime:
|
||||
:param build_settings:
|
||||
:param project_settings:
|
||||
:param cli_settings:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._runtime = runtime
|
||||
self._build_settings = build_settings
|
||||
self._project_settings = project_settings
|
||||
self._cli_settings = cli_settings
|
||||
|
||||
@ -93,19 +102,17 @@ class UpdateService(CommandABC):
|
||||
:param new_package:
|
||||
:return:
|
||||
"""
|
||||
content = ''
|
||||
with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'r') as project:
|
||||
content = project.read()
|
||||
project.close()
|
||||
if old_package in self._project_settings.dependencies:
|
||||
index = self._project_settings.dependencies.index(old_package)
|
||||
self._project_settings.dependencies[index] = new_package
|
||||
|
||||
if content == '' or content == '{}':
|
||||
return
|
||||
|
||||
if old_package in content:
|
||||
content = content.replace(old_package, new_package)
|
||||
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._runtime.working_directory, 'cpl.json'), 'w') as project:
|
||||
project.write(json.dumps(json.loads(content), indent=2))
|
||||
project.write(json.dumps(config, indent=2))
|
||||
project.close()
|
||||
|
||||
def run(self, args: list[str]):
|
||||
|
45
src/cpl_cli/configuration/settings_helper.py
Normal file
45
src/cpl_cli/configuration/settings_helper.py
Normal file
@ -0,0 +1,45 @@
|
||||
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum
|
||||
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
|
||||
|
||||
|
||||
class SettingsHelper:
|
||||
|
||||
@staticmethod
|
||||
def get_project_settings_dict(project: ProjectSettings) -> dict:
|
||||
return {
|
||||
ProjectSettingsNameEnum.name.value: project.name,
|
||||
ProjectSettingsNameEnum.version.value: {
|
||||
VersionSettingsNameEnum.major.value: project.version.major,
|
||||
VersionSettingsNameEnum.minor.value: project.version.minor,
|
||||
VersionSettingsNameEnum.micro.value: project.version.micro
|
||||
},
|
||||
ProjectSettingsNameEnum.author.value: project.author,
|
||||
ProjectSettingsNameEnum.author_email.value: project.author_email,
|
||||
ProjectSettingsNameEnum.description.value: project.description,
|
||||
ProjectSettingsNameEnum.long_description.value: project.long_description,
|
||||
ProjectSettingsNameEnum.url.value: project.url,
|
||||
ProjectSettingsNameEnum.copyright_date.value: project.copyright_date,
|
||||
ProjectSettingsNameEnum.copyright_name.value: project.copyright_name,
|
||||
ProjectSettingsNameEnum.license_name.value: project.license_name,
|
||||
ProjectSettingsNameEnum.license_description.value: project.license_description,
|
||||
ProjectSettingsNameEnum.dependencies.value: project.dependencies,
|
||||
ProjectSettingsNameEnum.python_version.value: project.python_version,
|
||||
ProjectSettingsNameEnum.python_path.value: project.python_path,
|
||||
ProjectSettingsNameEnum.classifiers.value: project.classifiers
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_build_settings_dict(build: BuildSettings) -> dict:
|
||||
return {
|
||||
BuildSettingsNameEnum.source_path.value: build.source_path,
|
||||
BuildSettingsNameEnum.output_path.value: build.output_path,
|
||||
BuildSettingsNameEnum.main.value: build.main,
|
||||
BuildSettingsNameEnum.entry_point.value: build.entry_point,
|
||||
BuildSettingsNameEnum.include_package_data.value: build.include_package_data,
|
||||
BuildSettingsNameEnum.included.value: build.included,
|
||||
BuildSettingsNameEnum.excluded.value: build.excluded,
|
||||
BuildSettingsNameEnum.package_data.value: build.package_data
|
||||
}
|
Loading…
Reference in New Issue
Block a user