From 5203ae1d7e6e7b8309cf06c99fdb41e39061b0d9 Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Tue, 11 Mar 2025 12:46:34 -0700 Subject: [PATCH] Moved `SemanticVersion` class to `semver` file from generic `helpers file --- io_scene_psk_psa/psa/export/operators.py | 3 +- io_scene_psk_psa/shared/helpers.py | 56 +----------------------- io_scene_psk_psa/shared/semver.py | 54 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 io_scene_psk_psa/shared/semver.py diff --git a/io_scene_psk_psa/psa/export/operators.py b/io_scene_psk_psa/psa/export/operators.py index 6feeea6..858c1aa 100644 --- a/io_scene_psk_psa/psa/export/operators.py +++ b/io_scene_psk_psa/psa/export/operators.py @@ -11,7 +11,8 @@ from .properties import PSA_PG_export, PSA_PG_export_action_list_item, filter_se get_sequences_from_name_and_frame_range from ..builder import build_psa, PsaBuildSequence, PsaBuildOptions from ..writer import write_psa -from ...shared.helpers import populate_bone_collection_list, get_nla_strips_in_frame_range, SemanticVersion +from ...shared.helpers import populate_bone_collection_list, get_nla_strips_in_frame_range +from ...shared.semver import SemanticVersion from ...shared.ui import draw_bone_filter_mode diff --git a/io_scene_psk_psa/shared/helpers.py b/io_scene_psk_psa/shared/helpers.py index 520d75c..7d20d40 100644 --- a/io_scene_psk_psa/shared/helpers.py +++ b/io_scene_psk_psa/shared/helpers.py @@ -1,4 +1,4 @@ -from typing import List, Iterable, cast, Tuple +from typing import List, Iterable, cast, Optional import bpy from bpy.props import CollectionProperty @@ -159,60 +159,6 @@ def is_bdk_addon_loaded() -> bool: return 'bdk' in dir(bpy.ops) -class SemanticVersion(object): - def __init__(self, version: Tuple[int, int, int]): - self.major, self.minor, self.patch = version - - def __iter__(self): - yield self.major - yield self.minor - yield self.patch - - @staticmethod - def compare(lhs: 'SemanticVersion', rhs: 'SemanticVersion') -> int: - """ - Compares two semantic versions. - - Returns: - -1 if lhs < rhs - 0 if lhs == rhs - 1 if lhs > rhs - """ - for l, r in zip(lhs, rhs): - if l < r: - return -1 - if l > r: - return 1 - return 0 - - def __str__(self): - return f'{self.major}.{self.minor}.{self.patch}' - - def __repr__(self): - return str(self) - - def __eq__(self, other): - return self.compare(self, other) == 0 - - def __ne__(self, other): - return not self == other - - def __lt__(self, other): - return self.compare(self, other) == -1 - - def __le__(self, other): - return self.compare(self, other) <= 0 - - def __gt__(self, other): - return self.compare(self, other) == 1 - - def __ge__(self, other): - return self.compare(self, other) >= 0 - - def __hash__(self): - return hash((self.major, self.minor, self.patch)) - - def convert_blender_bones_to_psx_bones( bones: List[bpy.types.Bone], bone_class: type, diff --git a/io_scene_psk_psa/shared/semver.py b/io_scene_psk_psa/shared/semver.py new file mode 100644 index 0000000..cc1606e --- /dev/null +++ b/io_scene_psk_psa/shared/semver.py @@ -0,0 +1,54 @@ +from typing import Tuple + +class SemanticVersion(object): + def __init__(self, version: Tuple[int, int, int]): + self.major, self.minor, self.patch = version + + def __iter__(self): + yield self.major + yield self.minor + yield self.patch + + @staticmethod + def compare(lhs: 'SemanticVersion', rhs: 'SemanticVersion') -> int: + """ + Compares two semantic versions. + + Returns: + -1 if lhs < rhs + 0 if lhs == rhs + 1 if lhs > rhs + """ + for l, r in zip(lhs, rhs): + if l < r: + return -1 + if l > r: + return 1 + return 0 + + def __str__(self): + return f'{self.major}.{self.minor}.{self.patch}' + + def __repr__(self): + return str(self) + + def __eq__(self, other): + return self.compare(self, other) == 0 + + def __ne__(self, other): + return not self == other + + def __lt__(self, other): + return self.compare(self, other) == -1 + + def __le__(self, other): + return self.compare(self, other) <= 0 + + def __gt__(self, other): + return self.compare(self, other) == 1 + + def __ge__(self, other): + return self.compare(self, other) >= 0 + + def __hash__(self): + return hash((self.major, self.minor, self.patch))