def validate_root_artifact(pralinefile: Dict[str, Any]): artifact = pralinefile.get('artifact', '') if not isinstance(artifact, str): raise PralinefileValidationError( f"pralinefile artifact '{artifact}' has invalid type '{type(artifact)}' -- type must be str" ) if not artifact_pattern.fullmatch(artifact): raise PralinefileValidationError( f"pralinefile artifact '{artifact}' is not valid -- artifact should contain lowercase words separated by underscores" )
def validate_mandatory_fields(pralinefile: Dict[str, Any]): for mandatory_field in mandatory_fields: if mandatory_field not in pralinefile: raise PralinefileValidationError( f"pralinefile doesn't have mandatory field '{mandatory_field}'" ) dependencies = pralinefile.get('dependencies', []) for dependency in dependencies: for mandatory_field in mandatory_fields: if mandatory_field not in dependency: raise PralinefileValidationError( f"pralinefile dependency {dependency} doesn't have mandatory field '{mandatory_field}'" )
def validate_allowed_fields(pralinefile: Dict[str, Any]): for field in pralinefile: if field not in allowed_pralinefile_fields: raise PralinefileValidationError( f"pralinefile has unrecognized field '{field}' -- allowed fields are {allowed_pralinefile_fields}" ) dependencies = pralinefile.get('dependencies', []) for dependency in dependencies: for field in dependency: if field not in allowed_pralinefile_dependency_fields: raise PralinefileValidationError( f"pralinefile dependency {dependency} has unrecognized field '{field}' -- allowed fields are {allowed_pralinefile_dependency_fields}" )
def validate_compilers(pralinefile: Dict[str, Any]): compilers = pralinefile.get('compilers', allowed_compilers) if not compilers: raise PralinefileValidationError( "pralinefile compilers field cannot be empty") if not isinstance(compilers, list): raise PralinefileValidationError( f"pralinefile compilers {compilers} has invalid type '{type(compilers)}' -- type must be list" ) for compiler in compilers: if compiler not in allowed_compilers: raise PralinefileValidationError( f"pralinefile çompiler '{compiler}' is not recognized -- allowed compilers are {allowed_compilers}" )
def validate_mode(pralinefile: Dict[str, Any]): modes = pralinefile.get('modes', allowed_modes) if not modes: raise PralinefileValidationError( "pralinefile modes field cannot be empty") if not isinstance(modes, list): raise PralinefileValidationError( f"pralinefile modes {modes} has invalid type '{type(modes)}' -- type must be list" ) for mode in modes: if mode not in allowed_modes: raise PralinefileValidationError( f"pralinefile has unrecognized mode '{mode}' -- allowed modes are {allowed_modes}" )
def validate_architecture(pralinefile: Dict[str, Any]): architectures = pralinefile.get('architectures', allowed_architectures) if not architectures: raise PralinefileValidationError( "pralinefile architectures field cannot be empty") if not isinstance(architectures, list): raise PralinefileValidationError( f"pralinefile architectures {architectures} has invalid type '{type(architectures)}' -- type must be list" ) for architecture in architectures: if architecture not in allowed_architectures: raise PralinefileValidationError( f"pralinefile architecture '{architecture}' is not recognized -- allowed architectures are {allowed_architectures}" )
def validate_platforms(pralinefile: Dict[str, Any]): platforms = pralinefile.get('platforms', allowed_platforms) if not platforms: raise PralinefileValidationError( "pralinefile platforms field cannot be empty") if not isinstance(platforms, list): raise PralinefileValidationError( f"pralinefile platforms {platforms} has invalid type '{type(platforms)}' -- type must be list" ) for platform in platforms: if platform not in allowed_platforms: raise PralinefileValidationError( f"pralinefile platform '{platform}' is not recognized -- allowed platforms are {allowed_platforms}" )
def validate_root_version(pralinefile: Dict[str, Any], pattern: Pattern[str]): version = pralinefile['version'] if not isinstance(version, str): raise PralinefileValidationError(f"pralinefile version '{version}' has invalid type '{type(version)}' -- type must be str") if not pattern.fullmatch(version): raise PralinefileValidationError(f"pralinefile version '{version}' is not valid")
def validate_root_organization(pralinefile: Dict[str, Any]): organization = pralinefile.get('organization', '') if not isinstance(organization, str): raise PralinefileValidationError(f"pralinefile organization '{organization}' has invalid type '{type(organization)}' -- type must be str") if not organization_pattern.fullmatch(organization): raise PralinefileValidationError(f"pralinefile organization '{organization}' is not valid -- organization should contain lowercase words separated by underscores")
def validate_scope(pralinefile: Dict[str, Any]): for dependency in pralinefile.get('dependencies', []): if dependency.get('scope', 'main') not in allowed_dependency_scopes: raise PralinefileValidationError( f"pralinefile dependency {dependency} has unrecognized scope '{dependency['scope']}' -- allowed scopes are {allowed_dependency_scopes}" )