11"""Helpers for creating and updating projects"""
22
33import json
4+ import operator
45import shutil
56from dataclasses import dataclass , field
67from pathlib import Path
78from typing import Any
89
9- from packaging import version as p_version
10-
1110V3_BACKUP_PATH = "v3_to_v4_upgrade_backups"
1211V4_BUILD = "szBuildVersion.json"
1312SZ_SYS_PATH = Path ("/opt/senzing" )
6362
6463@dataclass ()
6564class SzBuildDetails :
66- """Build information for a project or Senzing SDK system install"""
65+ """
66+ Build information for a project or Senzing SDK system install
67+ SzBuildDetails(platform='Linux', version='4.0.0', build_version='4.0.0.25164', build_number='2025_06_13__13_07', major=4, minor=0, micro=0)
68+ """
6769
6870 platform : str
6971 version : str
@@ -72,13 +74,48 @@ class SzBuildDetails:
7274 major : int = field (init = False )
7375 minor : int = field (init = False )
7476 micro : int = field (init = False )
77+ build_v : int = field (init = False )
7578
7679 def __post_init__ (self ) -> None :
77- self .version_parsed = p_version .parse (self .version )
78- self .build_version_parsed = p_version .parse (self .build_version )
79- self .major = self .version_parsed .major
80- self .minor = self .version_parsed .minor
81- self .micro = self .version_parsed .micro
80+ self .major , self .minor , self .micro , self .build_v = [int (n ) for n in self .build_version .split ("." )]
81+
82+ def _operators (self , other : "SzBuildDetails" , operator_ : Any ) -> tuple [bool , ...]:
83+ """Check instances of version details are with different operators"""
84+ to_compare = (
85+ (self .major , other .major ),
86+ (self .minor , other .minor ),
87+ (self .micro , other .micro ),
88+ (self .build_v , other .build_v ),
89+ )
90+ return tuple (operator_ (t [0 ], t [1 ]) for t in to_compare )
91+
92+ def __lt__ (self , other : "SzBuildDetails" ) -> bool :
93+ if not isinstance (other , SzBuildDetails ):
94+ return NotImplemented
95+
96+ major_equal , minor_equal , micro_equal , _ = self ._operators (other , operator .eq )
97+ major_lt , minor_lt , micro_lt , build_v_lt = self ._operators (other , operator .lt )
98+
99+ if major_lt or (
100+ major_equal and any ((minor_lt , all ((minor_equal , micro_lt )), all ((minor_equal , micro_equal , build_v_lt ))))
101+ ):
102+ return True
103+
104+ return False
105+
106+ def __gt__ (self , other : "SzBuildDetails" ) -> bool :
107+ if not isinstance (other , SzBuildDetails ):
108+ return NotImplemented
109+
110+ major_equal , minor_equal , micro_equal , _ = self ._operators (other , operator .eq )
111+ major_gt , minor_gt , micro_gt , build_v_gt = self ._operators (other , operator .gt )
112+
113+ if major_gt or (
114+ major_equal and any ((minor_gt , all ((minor_equal , micro_gt )), all ((minor_equal , micro_equal , build_v_gt ))))
115+ ):
116+ return True
117+
118+ return False
82119
83120
84121def get_build_details (path : Path ) -> SzBuildDetails :
0 commit comments