def __init__(self, number: int, ruledata: dict[str, Any]) -> None: self.names = None self.namepat = None self.rulesets = None self.norulesets = None self.number = number self.pretty = str(ruledata) self.texthash = xxhash.xxh64_intdigest(self.pretty) self._matchers = [] self._actions = [] # handle substitution of final name in name matchers if 'name' in ruledata: self.names = yaml_as_list(ruledata['name']) if 'setname' in ruledata: self.names = [ DOLLAR0.sub(ruledata['setname'], name) for name in self.names ] ruledata['name'] = self.names if 'namepat' in ruledata: self.namepat = ruledata['namepat'].replace('\n', '') if 'setname' in ruledata: self.namepat = DOLLAR0.sub(ruledata['setname'], self.namepat) ruledata['namepat'] = self.namepat if 'ruleset' in ruledata: self.rulesets = yaml_as_set(ruledata['ruleset']) if 'noruleset' in ruledata: self.norulesets = yaml_as_set(ruledata['noruleset']) # matchers for keyword, generate_matcher in get_matcher_generators(): if keyword in ruledata: self._matchers.append(generate_matcher(ruledata)) # actions for keyword, generate_action in get_action_generators(): if keyword in ruledata: self._actions.append(generate_action(ruledata))
def noflag(ruledata: Any) -> Matcher: noflags = yaml_as_set(ruledata['noflag']) def matcher(package: Package, package_context: PackageContext, match_context: MatchContext) -> bool: return not package_context.has_flags(noflags) return matcher
def notver(ruledata: Any) -> Matcher: notversions = yaml_as_set(ruledata['notver']) if len(notversions) == 1: notversion: Final[str] = notversions.pop() def matcher(package: Package, package_context: PackageContext, match_context: MatchContext) -> bool: return package.version != notversion return matcher else: def matcher(package: Package, package_context: PackageContext, match_context: MatchContext) -> bool: return package.version not in notversions return matcher
def ver(ruledata: Any) -> Matcher: versions = yaml_as_set(ruledata['ver']) if len(versions) == 1: version = versions.pop() def matcher(package: Package, package_context: PackageContext, match_context: MatchContext) -> bool: return package.version == version return matcher else: def matcher(package: Package, package_context: PackageContext, match_context: MatchContext) -> bool: return package.version in versions return matcher