diff --git a/AUTHORS.rst b/AUTHORS.rst index 9a8224dc7da..4822396cf93 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -79,6 +79,7 @@ The following organizations or individuals have contributed to ScanCode: - Sankha Das @sankha555 - Saravanan G @SaravananOffl - Sarita Singh @itssingh +- Sarthak Shubham @sarthak-shubham - Savino Sguera @savinos - Sebastian Roth @ened - Sebastian Schuberth @sschuberth diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d9a5a6b4026..94af05e6df7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,13 @@ Next release ``licensedcode-data``. https://github.com/aboutcode-org/scancode-toolkit/pull/5056 +- Fix ``report_license_rules.py`` and ``buildrules.py`` in + ``etc/scripts/licenses/`` to work correctly with the YAML frontmatter + fields added in #3100. + https://github.com/aboutcode-org/scancode-toolkit/pull/5259 + + + v33.0.0rc1 - 2026-05-14 ------------------------ diff --git a/etc/scripts/licenses/buildrules.py b/etc/scripts/licenses/buildrules.py index 6def6781a9f..ddf743bab79 100644 --- a/etc/scripts/licenses/buildrules.py +++ b/etc/scripts/licenses/buildrules.py @@ -294,6 +294,7 @@ def cli(licenses_file, dump_to_file_on_errors=False): """ rules_data = load_data(licenses_file) + click.echo("Loading existing rules to check for duplicates. This may take several minutes...") rule_by_tokens = all_rule_by_tokens() licenses_by_key = cache.get_licenses_db() diff --git a/etc/scripts/licenses/report_license_rules.py b/etc/scripts/licenses/report_license_rules.py index 7a5f84adada..32accda2606 100644 --- a/etc/scripts/licenses/report_license_rules.py +++ b/etc/scripts/licenses/report_license_rules.py @@ -83,8 +83,8 @@ def write_data_to_csv(data, output_csv, fieldnames): - with open(output_csv, "w") as f: - w = csv.DictWriter(f, fieldnames=fieldnames) + with open(output_csv, "w", encoding="utf-8") as f: + w = csv.DictWriter(f, fieldnames=fieldnames, extrasaction='ignore') w.writeheader() for entry in data: w.writerow(entry) @@ -180,6 +180,7 @@ def cli(licenses, rules, category, license_key, with_text): licenses_output = [] rules_output = [] + click.echo("Loading licenses from the database...") licenses_data = load_licenses() if licenses: @@ -208,8 +209,10 @@ def cli(licenses, rules, category, license_key, with_text): write_data_to_csv(data=licenses_output, output_csv=licenses, fieldnames=LICENSES_FIELDNAMES) if rules: - rules_data = list(load_rules()) - for rule in rules_data: + click.echo("Loading 30,000+ rules from the database. This will take several minutes, so please be patient...") + for i, rule in enumerate(load_rules()): + if i > 0 and i % 5000 == 0: + click.echo(f"Processed {i} rules...") rule_data = rule.to_dict() rule_data["identifier"] = rule.identifier rule_data["referenced_filenames"] = rule.referenced_filenames @@ -240,6 +243,9 @@ def cli(licenses, rules, category, license_key, with_text): rules_output = flatten_output(rules_output) write_data_to_csv(data=rules_output, output_csv=rules, fieldnames=RULES_FIELDNAMES) + if licenses or rules: + click.echo("Export complete! Check your CSV files.") + if __name__ == "__main__": cli()