MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / validate_rules

Function validate_rules

src/licensedcode/models.py:1098–1123  ·  view source on GitHub ↗

Return a mapping of {error message: [list of Rule]) from validating a list of ``rules`` Rule integrity and correctness using known licenses from a mapping of ``licenses_by_key`` {key: License}`.

(rules, licenses_by_key, with_text=False, rules_data_dir=rules_data_dir, thorough=False)

Source from the content-addressed store, hash-verified

1096
1097
1098def validate_rules(rules, licenses_by_key, with_text=False, rules_data_dir=rules_data_dir, thorough=False):
1099 """
1100 Return a mapping of {error message: [list of Rule]) from validating a list
1101 of ``rules`` Rule integrity and correctness using known licenses from a
1102 mapping of ``licenses_by_key`` {key: License}`.
1103 """
1104 # always skip deprecated rules
1105 rules = [r for r in rules if not r.is_deprecated]
1106 errors = _validate_all_rules(rules=rules, licenses_by_key=licenses_by_key, thorough=thorough)
1107 if errors:
1108 message = ['Errors while validating rules:']
1109 for msg, rules in errors.items():
1110 message.append('')
1111 message.append(msg)
1112 for rule in rules:
1113 message.append(f' {rule!r}')
1114
1115 if rule.identifier:
1116 rule_file = rule.rule_file(rules_data_dir=rules_data_dir)
1117 if rule_file and exists(rule_file):
1118 message.append(f' file://{rule_file}')
1119
1120 if with_text:
1121 txt = rule.text[:100].strip()
1122 message.append(f' {txt}...')
1123 raise InvalidRule('\n'.join(message))
1124
1125
1126def build_rules_from_licenses(licenses_by_key):

Callers 2

get_rulesFunction · 0.85

Calls 5

_validate_all_rulesFunction · 0.85
InvalidRuleClass · 0.85
appendMethod · 0.45
rule_fileMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected