88from configparser import UNNAMED_SECTION , ConfigParser
99from os import PathLike , environ
1010from pathlib import Path
11- from typing import List , Optional , Self
11+ from typing import Any , Dict , List , Optional , Self
1212
1313from ..constants import (
1414 ARCHS ,
1515 GL_BUG_REPORT_URL ,
1616 GL_DISTRIBUTION_NAME ,
1717 GL_HOME_URL ,
18+ GL_PLATFORM_FRANKENSTEIN ,
1819 GL_RELEASE_ID ,
1920 GL_SUPPORT_URL ,
2021)
@@ -59,14 +60,20 @@ def __init__(
5960 self ._feature_flags_cached : Optional [List [str ]] = None
6061 self ._feature_platforms_cached : Optional [List [str ]] = None
6162 self ._feature_set_cached : Optional [str ] = None
63+ self ._features_cached : Optional [Dict [str , Any ]] = None
6264 self ._platform_variant_cached : Optional [str ] = None
6365 self ._flavor = ""
6466 self ._version = None
6567
68+ self ._flag_frankenstein = bool (environ .get ("GL_ALLOW_FRANKENSTEIN" , False ))
69+
6670 self ._flag_multiple_platforms = bool (
67- environ .get ("GL_ALLOW_FRANKENSTEIN " , False )
71+ environ .get ("GL_ALLOW_MULTIPLE_PLATFORMS " , False )
6872 )
6973
74+ if self ._flag_frankenstein :
75+ self ._flag_multiple_platforms = True
76+
7077 commit_id_or_hash = None
7178
7279 if version is not None :
@@ -213,6 +220,20 @@ def flavor(self) -> str:
213220
214221 return self ._flavor
215222
223+ @property
224+ def features (self ) -> Dict [str , Any ]:
225+ """
226+ Returns the features for the cname parsed.
227+
228+ :return: (dict) Features of the cname
229+ :since: 0.10.14
230+ """
231+
232+ if self ._features_cached is None :
233+ self ._features_cached = Parser ().filter_as_dict (self .flavor )
234+
235+ return self ._features_cached
236+
216237 @property
217238 def feature_set (self ) -> str :
218239 """
@@ -239,7 +260,7 @@ def feature_set_element(self) -> str:
239260 if self ._feature_elements_cached is not None :
240261 return "," .join (self ._feature_elements_cached )
241262
242- return "," .join (Parser (). filter_as_dict ( self .flavor ) ["element" ])
263+ return "," .join (self .features ["element" ])
243264
244265 @property
245266 def feature_set_flag (self ) -> str :
@@ -253,7 +274,7 @@ def feature_set_flag(self) -> str:
253274 if self ._feature_flags_cached is not None :
254275 return "," .join (self ._feature_flags_cached )
255276
256- return "," .join (Parser (). filter_as_dict ( self .flavor ) ["flag" ])
277+ return "," .join (self .features ["flag" ])
257278
258279 @property
259280 def feature_set_platform (self ) -> str :
@@ -265,7 +286,7 @@ def feature_set_platform(self) -> str:
265286 """
266287
267288 if self ._feature_platforms_cached is None :
268- platforms = Parser (). filter_as_dict ( self .flavor ) ["platform" ]
289+ platforms = self .features ["platform" ]
269290 else :
270291 platforms = self ._feature_platforms_cached
271292
@@ -274,7 +295,7 @@ def feature_set_platform(self) -> str:
274295
275296 assert len (platforms ) < 2
276297 "Only one platform is supported"
277- return platforms [0 ]
298+ return platforms [0 ] # type: ignore[no-any-return]
278299
279300 @property
280301 def feature_set_list (self ) -> List [str ]:
@@ -293,21 +314,20 @@ def feature_set_list(self) -> List[str]:
293314 @property
294315 def platform (self ) -> str :
295316 """
296- Returns the feature set of type " platform" for the cname parsed.
317+ Returns the platform for the cname parsed.
297318
298- :return: (str) Feature set platforms
319+ :return: (str) Platform
299320 :since: 0.7.0
300321 """
301322
302- if self ._feature_platforms_cached is None :
303- platforms = Parser ().filter_as_dict (self .flavor )["platform" ]
304- else :
305- platforms = self ._feature_platforms_cached
306-
307- if not self ._flag_multiple_platforms :
308- assert len (platforms ) < 2
323+ if (
324+ self ._flag_frankenstein
325+ and self ._feature_platforms_cached is not None
326+ and len (self ._feature_platforms_cached ) > 1
327+ ):
328+ return GL_PLATFORM_FRANKENSTEIN
309329
310- return platforms [ 0 ]
330+ return self . feature_set_platform
311331
312332 @property
313333 def platform_variant (self ) -> Optional [str ]:
@@ -345,18 +365,8 @@ def release_metadata_string(self) -> str:
345365 :since: 1.0.0
346366 """
347367
348- features = Parser ().filter_as_dict (self .flavor )
349-
350- if not self ._flag_multiple_platforms :
351- assert len (features ["platform" ]) < 2
352- "Only one platform is supported"
353-
354368 commit_hash = self .commit_hash
355369 commit_id = self .commit_id
356- elements = "," .join (features ["element" ])
357- flags = "," .join (features ["flag" ])
358- platform = features ["platform" ][0 ]
359- platforms = "," .join (features ["platform" ])
360370 platform_variant = self .platform_variant
361371 version = self .version
362372
@@ -387,10 +397,10 @@ def release_metadata_string(self) -> str:
387397BUG_REPORT_URL="{ GL_BUG_REPORT_URL } "
388398GARDENLINUX_CNAME="{ self .cname } "
389399GARDENLINUX_FEATURES="{ self .feature_set } "
390- GARDENLINUX_FEATURES_PLATFORMS="{ platforms } "
391- GARDENLINUX_FEATURES_ELEMENTS="{ elements } "
392- GARDENLINUX_FEATURES_FLAGS="{ flags } "
393- GARDENLINUX_PLATFORM="{ platform } "
400+ GARDENLINUX_FEATURES_PLATFORMS="{ self . feature_set_platform } "
401+ GARDENLINUX_FEATURES_ELEMENTS="{ self . feature_set_element } "
402+ GARDENLINUX_FEATURES_FLAGS="{ self . feature_set_flag } "
403+ GARDENLINUX_PLATFORM="{ self . platform } "
394404GARDENLINUX_PLATFORM_VARIANT="{ platform_variant } "
395405GARDENLINUX_VERSION="{ version } "
396406GARDENLINUX_COMMIT_ID="{ commit_id } "
0 commit comments