From 703d20f43fd15f1aa600af91fdf1a213e7bbee9a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 7 Apr 2021 18:35:14 +0200 Subject: [PATCH] Improved version handling --- src/cpl_cli/configuration/version_settings.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cpl_cli/configuration/version_settings.py b/src/cpl_cli/configuration/version_settings.py index 3d64d71e..86fac84c 100644 --- a/src/cpl_cli/configuration/version_settings.py +++ b/src/cpl_cli/configuration/version_settings.py @@ -31,16 +31,25 @@ class VersionSettings(ConfigurationModelABC): return self._micro def to_str(self) -> str: - return f'{self._major}.{self._minor}.{self._micro}' + if self._micro is None: + return f'{self._major}.{self._minor}' + else: + return f'{self._major}.{self._minor}.{self._micro}' def from_dict(self, settings: dict): self._major = settings[VersionSettingsNameEnum.major.value] self._minor = settings[VersionSettingsNameEnum.minor.value] - self._micro = settings[VersionSettingsNameEnum.micro.value] + micro = settings[VersionSettingsNameEnum.micro.value] + if micro != '': + self._micro = micro def to_dict(self) -> dict: - return { + version = { VersionSettingsNameEnum.major.value: self._major, VersionSettingsNameEnum.minor.value: self._minor, - VersionSettingsNameEnum.micro.value: self._micro } + + if self._micro is not None: + version[VersionSettingsNameEnum.micro.value] = self._micro + + return version