1818import typing as T
1919import uuid
2020
21- from version_utils import get_version
21+ from version_utils import get_version , parse_version , ParsedVersion
2222
23- from .. import Version
2423
25- __all__ = ["RecordingInfo" , "RecordingInfoFile" , "RecordingInfoInvalidError" , "Version" ]
24+ __all__ = ["RecordingInfo" , "RecordingInfoFile" , "RecordingInfoInvalidError" ]
2625
2726
2827logger = logging .getLogger (__name__ )
@@ -72,12 +71,12 @@ def __len__(self):
7271
7372 @property
7473 @abc .abstractmethod
75- def meta_version (self ) -> Version :
74+ def meta_version (self ) -> ParsedVersion :
7675 pass
7776
7877 @property
7978 @abc .abstractmethod
80- def min_player_version (self ) -> Version :
79+ def min_player_version (self ) -> ParsedVersion :
8180 pass
8281
8382 @property
@@ -377,11 +376,11 @@ def does_recording_contain_info_file(rec_dir: str) -> bool:
377376 return os .path .isfile (file_path )
378377
379378 @staticmethod
380- def detect_recording_info_file_version (rec_dir : str ) -> Version :
379+ def detect_recording_info_file_version (rec_dir : str ) -> ParsedVersion :
381380 file_path = RecordingInfoFile ._info_file_path (rec_dir = rec_dir )
382381 with open (file_path , "r" ) as file :
383382 read_dict = RecordingInfoFile ._read_dict_from_file (file = file )
384- return Version (read_dict ["meta_version" ])
383+ return parse_version (read_dict ["meta_version" ])
385384
386385 @staticmethod
387386 def read_file_from_recording (rec_dir : str ) -> "RecordingInfoFile" :
@@ -403,7 +402,7 @@ def read_file_from_recording(rec_dir: str) -> "RecordingInfoFile":
403402 info_file_path = RecordingInfoFile ._info_file_path (rec_dir )
404403 with open (info_file_path , "r" ) as f :
405404 info_dict = RecordingInfoFile ._read_dict_from_file (f )
406- min_player_version = Version (info_dict ["min_player_version" ])
405+ min_player_version = parse_version (info_dict ["min_player_version" ])
407406 except Exception as e :
408407 # Catching BaseException since at this point we don't know anything
409408 logger .error (
@@ -415,9 +414,7 @@ def read_file_from_recording(rec_dir: str) -> "RecordingInfoFile":
415414 f"Recording is too new to be opened with this version of Player!"
416415 )
417416
418- # TODO: get_version() returns a LooseVersion, but we are using
419- # packaging.Version now, need to adjust this across the codebase
420- if min_player_version > Version (get_version ().vstring ):
417+ if min_player_version > get_version ():
421418 raise RecordingInfoInvalidError (
422419 f"This recording requires Player version >= { min_player_version } !"
423420 )
@@ -440,7 +437,7 @@ def read_file_from_recording(rec_dir: str) -> "RecordingInfoFile":
440437
441438 @staticmethod
442439 def create_empty_file (
443- rec_dir : str , fixed_version : T .Optional [Version ] = None
440+ rec_dir : str , fixed_version : T .Optional [ParsedVersion ] = None
444441 ) -> "RecordingInfoFile" :
445442 """
446443 Creates a new `RecordingInfoFile` instance using the latest meta format version,
@@ -483,15 +480,15 @@ def validate(self):
483480 _info_file_versions = {}
484481
485482 @classmethod
486- def register_child_class (cls , version : Version , child_class : type ):
483+ def register_child_class (cls , version : ParsedVersion , child_class : type ):
487484 """Use this to register interface implementations for specific versions."""
488485 # NOTE: This is dependency inversion to avoids circular imports, because we
489486 # don't need to know our child classes.
490487 # TODO: Would be much cleaner with self-registering meta classes.
491488 cls ._info_file_versions [version ] = child_class
492489
493490 @classmethod
494- def get_latest_info_file_version (cls ) -> Version :
491+ def get_latest_info_file_version (cls ) -> ParsedVersion :
495492 if not cls ._info_file_versions :
496493 raise ValueError (
497494 "RecordingInfoFile not correctly initialized! No templates registered."
0 commit comments