11import logging
22from typing import Any , Tuple , Callable
33from beet import Context , Pack , NamespaceFile , ItemModel
4- from beet .core .utils import SupportedFormats
54
65logger = logging .getLogger ("gm4.backwards" )
76
@@ -55,8 +54,7 @@ def backport(pack: Pack[Any], format: int, run: Callable[[str, NamespaceFile], N
5554 resources [(file_type , path )] = proxy [path ]
5655
5756 for overlay in pack .overlays .values ():
58- overlay_formats = overlay .supported_formats or overlay .pack_format
59- if check_formats (overlay_formats , format ):
57+ if check_formats (overlay , format ):
6058 for file_type in overlay .resolve_scope_map ().values ():
6159 proxy = overlay [file_type ]
6260 for path in proxy .keys ():
@@ -74,13 +72,23 @@ def backport(pack: Pack[Any], format: int, run: Callable[[str, NamespaceFile], N
7472 overlay [path ] = new_resource
7573
7674
77- def check_formats (supported : SupportedFormats , format : int ):
78- match supported :
79- case int (value ):
80- return value == format
81- case [min , max ]:
82- return min <= format <= max
83- case { "min_inclusive" : min , "max_inclusive" : max }:
84- return min <= format <= max
85- case _:
86- raise ValueError (f"Unknown supported_formats structure { supported } " )
75+ def check_formats (overlay : Pack [Any ], format : int ):
76+ if overlay .min_format and overlay .max_format :
77+ return get_major (overlay .min_format ) <= format <= get_major (overlay .max_format )
78+ if overlay .supported_formats :
79+ match overlay .supported_formats :
80+ case int (value ):
81+ return value == format
82+ case [min , max ]:
83+ return min <= format <= max
84+ case { "min_inclusive" : min , "max_inclusive" : max }:
85+ return min <= format <= max
86+ case _:
87+ raise ValueError (f"Unknown supported_formats structure { overlay .supported_formats } " )
88+ if overlay .pack_format :
89+ return overlay .pack_format == format
90+ return False
91+
92+
93+ def get_major (format : int | tuple [int ] | tuple [int , int ]):
94+ return format if isinstance (format , int ) else format [0 ]
0 commit comments