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

Function get_rules

src/licensedcode/models.py:860–894  ·  view source on GitHub ↗

Yield Rule objects loaded from a ``licenses_db`` and license files found in ``licenses_data_dir`` and rule files found in `rules_data_dir`. Raise an Exception if a rule is inconsistent or incorrect. If ``validate`` flag is True, we validate all the license rules for consistency

(
    licenses_db=None,
    licenses_data_dir=licenses_data_dir,
    rules_data_dir=rules_data_dir,
    validate=False,
    validate_thorough=False,
    is_builtin=True,
    with_deprecated=False
)

Source from the content-addressed store, hash-verified

858
859
860def get_rules(
861 licenses_db=None,
862 licenses_data_dir=licenses_data_dir,
863 rules_data_dir=rules_data_dir,
864 validate=False,
865 validate_thorough=False,
866 is_builtin=True,
867 with_deprecated=False
868):
869 """
870 Yield Rule objects loaded from a ``licenses_db`` and license files found in
871 ``licenses_data_dir`` and rule files found in `rules_data_dir`. Raise an
872 Exception if a rule is inconsistent or incorrect.
873
874 If ``validate`` flag is True, we validate all the license rules for consistency
875 and if ``validate_thorough`` is True we perform additional validation tests
876 (like whether it would produce valid YAML) which is skipped normally because these
877 are expensive operations.
878 """
879 licenses_db = licenses_db or load_licenses(
880 licenses_data_dir=licenses_data_dir,
881 with_deprecated=with_deprecated,
882 )
883
884 rules = list(load_rules(
885 rules_data_dir=rules_data_dir,
886 is_builtin=is_builtin,
887 with_deprecated=with_deprecated,
888 ))
889
890 if validate:
891 validate_rules(rules=rules, licenses_by_key=licenses_db, thorough=validate_thorough)
892
893 licenses_as_rules = build_rules_from_licenses(licenses_db)
894 return chain(licenses_as_rules, rules)
895
896
897def load_dump_licenses():

Callers 2

Calls 4

load_licensesFunction · 0.85
load_rulesFunction · 0.85
validate_rulesFunction · 0.85

Tested by 1