Skip to content

Add --composite-rules flag to annotate multi license rules with required phrases - #5118

Open
Kaushik-Kumar-CEG wants to merge 2 commits into
aboutcode-org:developfrom
Kaushik-Kumar-CEG:gsoc/annotate-composite-rules
Open

Add --composite-rules flag to annotate multi license rules with required phrases#5118
Kaushik-Kumar-CEG wants to merge 2 commits into
aboutcode-org:developfrom
Kaushik-Kumar-CEG:gsoc/annotate-composite-rules

Conversation

@Kaushik-Kumar-CEG

@Kaushik-Kumar-CEG Kaushik-Kumar-CEG commented Jun 5, 2026

Copy link
Copy Markdown

references #5077

adds --composite-rules (-c) flag to the add-required-phrases CLI command.

For composite (AND/OR) rules, collects candidate phrases from existing required phrase rules with a single license key, skips generic licenses, then marks the rule only if every remaining key has a non-overlapping match in the text.

uses existing: find_phrase_spans_in_text for token-based matching, add_required_phrase_to_rule for safe injection with overlap and ignorable checks, and get_updatable_rules_by_expression for rule filtering.

Usage:

add-required-phrases --composite-rules --dry-run --verbose

Tests cover candidate collection, multi-key matching, the all-keys gate, existing markers, overlaps, rollback, dry-run behavior, and CLI wiring.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled and links the original issue above
  • Focused tests pass
  • Commits are in a uniquely named feature branch and have no merge conflicts

disclosure: used Claude to help review and clean up a few bugs in the script

@Kaushik-Kumar-CEG

Copy link
Copy Markdown
Author

@AyanSinhaMahapatra ready for review when you have a moment

@Kaushik-Kumar-CEG
Kaushik-Kumar-CEG force-pushed the gsoc/annotate-composite-rules branch from baa56a6 to 59026a3 Compare June 20, 2026 20:52
@Kaushik-Kumar-CEG Kaushik-Kumar-CEG changed the title Add script to annotate composite license rules with required phrases Add --composite-rules flag to annotate multi license rules with required phrases Jun 20, 2026
@Kaushik-Kumar-CEG

Copy link
Copy Markdown
Author

@AyanSinhaMahapatra please review when you have a moment :)

@AyanSinhaMahapatra AyanSinhaMahapatra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kaushik-Kumar-CEG thanks for the PR.

The logic is looking better than before and should work, but your tests aren't testing for the functionality added at all. And we need a lot of refactoring elsewhere. Also skip using attributes for this, as this is redundant double work.

Could you also rebase/merge from main?

Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread tests/licensedcode/test_required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread src/licensedcode/required_phrases.py Outdated
Comment thread tests/licensedcode/test_required_phrases.py Outdated
Comment thread tests/licensedcode/test_required_phrases.py Outdated
@Kaushik-Kumar-CEG
Kaushik-Kumar-CEG force-pushed the gsoc/annotate-composite-rules branch from 4502b67 to a8beda9 Compare August 23, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants