From 171b00562413b10cc424e36b178e0ead03381cc0 Mon Sep 17 00:00:00 2001 From: "Barry-Thomas-Paul: Moss" <4193389+Amourspirit@users.noreply.github.com> Date: Fri, 23 May 2025 13:07:23 -0600 Subject: [PATCH 1/2] fix fix info version --- ooodev/utils/info.py | 89 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/ooodev/utils/info.py b/ooodev/utils/info.py index b8f15494..1b06f10b 100644 --- a/ooodev/utils/info.py +++ b/ooodev/utils/info.py @@ -243,31 +243,38 @@ def get_reg_mods_path(cls) -> str: @overload @classmethod - def get_reg_item_prop(cls, item: str) -> str: ... + def get_reg_item_prop(cls, item: str) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, prop: str) -> str: ... + def get_reg_item_prop(cls, item: str, prop: str) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, prop: str, node: str) -> str: ... + def get_reg_item_prop(cls, item: str, prop: str, node: str) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, *, kind: Info.RegPropKind) -> str: ... + def get_reg_item_prop(cls, item: str, *, kind: Info.RegPropKind) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, *, kind: Info.RegPropKind, idx: int) -> str: ... + def get_reg_item_prop(cls, item: str, *, kind: Info.RegPropKind, idx: int) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, prop: str, *, idx: int) -> str: ... + def get_reg_item_prop(cls, item: str, prop: str, *, idx: int) -> str: + ... @overload @classmethod - def get_reg_item_prop(cls, item: str, prop: str, node: str, kind: Info.RegPropKind) -> str: ... + def get_reg_item_prop(cls, item: str, prop: str, node: str, kind: Info.RegPropKind) -> str: + ... @classmethod def get_reg_item_prop( @@ -2461,19 +2468,23 @@ def __delitem__(self, _item: int | str | DrawPage | XDrawPage) -> None: # region is_type_enum_multi() @overload @staticmethod - def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: Enum) -> bool: ... + def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: Enum) -> bool: + ... @overload @staticmethod - def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: str) -> bool: ... + def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: str) -> bool: + ... @overload @staticmethod - def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: Enum, arg_name: str) -> bool: ... + def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: Enum, arg_name: str) -> bool: + ... @overload @staticmethod - def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: str, arg_name: str) -> bool: ... + def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: str, arg_name: str) -> bool: + ... @staticmethod def is_type_enum_multi(alt_type: str, enum_type: Type[Enum], enum_val: Enum | str, arg_name: str = "") -> bool: @@ -2722,6 +2733,62 @@ def version_info(cls) -> Tuple[int, ...]: cls._version_info = tuple(int(s) for s in cls.version.split(".")) return cls._version_info + @classproperty + def version_info(cls) -> Tuple[int, ...]: + """ + Gets the running LibreOffice version. + + |lo_unsafe| + + Returns: + tuple: version as tuple such as ``(7, 3, 4, 2)`` + + Note: + This property only works after Office is Loaded. + """ + + try: + return cls._version_info + except AttributeError: + cls._version_info = Info.parse_version_string_to_int_tuple(cls.version) + return cls._version_info + + @staticmethod + def parse_version_string_to_int_tuple(version_string: str) -> tuple[int, ...]: + """ + Parses a version string (e.g., "2025.0.1.alpha1") into a tuple of integers. + The string is split by '.', and any non-integer parts are ignored. + + Args: + version_string: The string to parse. + + Returns: + A tuple of integers representing the version parts. + Example: "2025.0.1.alpha1" -> (2025, 0, 1) + "1.2.3" -> (1, 2, 3) + "5.0beta" -> (5, 0) + "abc" -> () + + Raises: + TypeError: If the input is not a string. + + .. versionadded:: 0.53.4 + """ + if not isinstance(version_string, str): + raise TypeError("Input must be a string.") + + parts = version_string.split(".") + int_parts = [] + for part in parts: + try: + # Attempt to convert the part to an integer + int_parts.append(int(part)) + except ValueError: + # If conversion fails (e.g., "alpha1", "beta"), + # stop processing further parts and break the loop. + break + return tuple(int_parts) + def _del_cache_attrs(source: object, e: EventArgs) -> None: # clears Write Attributes that are dynamically created From 72559465e974c42ebdd529827657dd114e068fba Mon Sep 17 00:00:00 2001 From: "Barry-Thomas-Paul: Moss" Date: Fri, 23 May 2025 13:36:09 -0600 Subject: [PATCH 2/2] fix for info version --- pyproject.toml | 2 +- tests/test_info/test_info.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b479c8cf..a7112390 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "ooo-dev-tools" -version = "0.53.3" +version = "0.53.4" description = "LibreOffice Developer Tools" license = "Apache Software License" diff --git a/tests/test_info/test_info.py b/tests/test_info/test_info.py index e3f64650..314b8595 100644 --- a/tests/test_info/test_info.py +++ b/tests/test_info/test_info.py @@ -175,3 +175,31 @@ def test_parese_language_code_error() -> None: _ = Info.parse_language_code("en_GB") with pytest.raises(ValueError): _ = Info.parse_language_code("-GB") + + +def test_parse_version_string_to_int_tuple() -> None: + from ooodev.utils.info import Info + + # Test valid version strings + assert Info.parse_version_string_to_int_tuple("2025.0.1.alpha1") == (2025, 0, 1) + assert Info.parse_version_string_to_int_tuple("1.2.3") == (1, 2, 3) + assert Info.parse_version_string_to_int_tuple("5.0beta") == (5,) + assert Info.parse_version_string_to_int_tuple("10.20.30.40") == (10, 20, 30, 40) + + # Test invalid version strings + assert Info.parse_version_string_to_int_tuple("abc") == () + assert Info.parse_version_string_to_int_tuple("") == () + + # Test mixed valid and invalid parts + assert Info.parse_version_string_to_int_tuple("1.2.alpha.3") == (1, 2) + assert Info.parse_version_string_to_int_tuple("1..3") == (1,) + + # Test edge cases + assert Info.parse_version_string_to_int_tuple("0") == (0,) + assert Info.parse_version_string_to_int_tuple("0.0.0") == (0, 0, 0) + + # Test input type validation + with pytest.raises(TypeError): + Info.parse_version_string_to_int_tuple(12345) # Not a string + with pytest.raises(TypeError): + Info.parse_version_string_to_int_tuple(None) # Not a string