Skip to content

Conversation

@uttam282005
Copy link
Contributor

Fixes #3281

Description

This PR adds support for additional CLI options in HTML output to match the functionality available in JSON/YAML formats:

  • --license-text: Display matched license text
  • --license-text-diagnostics: Show diagnostic information for license matches
  • --summary: Display scan summary with declared license and holder information
  • --license-clarity-score: Show license clarity score breakdown

Changes Made

Template Changes (src/formattedcode/templates/html/template.html)

  • Added Scan Summary section displaying:
    • Declared license expression
    • Declared holder
    • Primary language
    • Other license expressions (with counts)
    • Other holders
  • Added License Clarity Score table showing:
    • Overall score (0-100)
    • Component metrics (declared_license, identification_precision, has_license_text, etc.)
  • Enhanced Copyrights and Licenses table:
    • Added new column for matched text and diagnostics
    • Used HTML5 <details>/<summary> elements for collapsible sections
    • Display matched text when --license-text is used
    • Display diagnostics when --license-text-diagnostics is used
  • Added CSS styling for new elements

Code Changes (src/formattedcode/output_html.py)

  • Modified generate_output() to pass summary parameter to template.generate()
  • Summary data already being collected in process_codebase() - just needed to be passed through

Testing

Tested with various command combinations:

# License text
scancode --license --license-text test_dir/ --html output.html

# License text with diagnostics
scancode --license --license-text --license-text-diagnostics test_dir/ --html output.html

# Summary and clarity score
scancode --license --classify --summary --license-clarity-score test_dir/ --html output.html

# All options combined
scancode --license --license-text --license-text-diagnostics --classify --summary --license-clarity-score --license-references test_dir/ --html output.html

…license-clarity-score in HTML output

The HTML output now supports --license-text, --license-text-diagnostics, --summary,--license-clarity-score

Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Copilot AI review requested due to automatic review settings January 15, 2026 10:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for additional CLI options (--license-text, --license-text-diagnostics, --summary, --license-clarity-score) in HTML output to match functionality available in JSON/YAML formats.

Changes:

  • Added template sections for Scan Summary and License Clarity Score display
  • Enhanced Copyrights and Licenses table with new column for matched text and diagnostics using collapsible HTML5 details/summary elements
  • Modified output_html.py to pass summary parameter through the template generation pipeline

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
src/formattedcode/templates/html/template.html Added Scan Summary section, License Clarity Score table, and matched text/diagnostics column with collapsible display
src/formattedcode/output_html.py Modified to extract and pass summary data, matched_text, and matched_text_diagnostics to template
tests/formattedcode/test_output_templated.py Added integration tests for the new HTML output features
Comments suppressed due to low confidence (2)

src/formattedcode/output_html.py:160

  • Outdated docstring. The function signature includes a summary parameter, but the docstring doesn't document it. Update the docstring to describe the summary parameter.
    """
    Write scan output `results` to the `output_file` opened file using a template
    file at `template_loc`.
    Raise an exception on errors.
    """

src/formattedcode/output_html.py:200

  • Outdated docstring. The function signature includes license_references and summary parameters, but the docstring only mentions results and version. Update the docstring to describe all parameters including license_references and summary.
    """
    Yield unicode strings from incrementally rendering `results` and `version`
    with the Jinja `template` object.
    """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

<p><strong>Other Holders:</strong></p>
<ul>
{% for holder in summary.other_holders %}
<li>{{ holder }}</li>
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Incorrect template variable access. The other_holders list contains dictionary objects with 'value' and 'count' keys (similar to other_license_expressions), but the template is rendering the holder object directly instead of accessing holder.value. Change the line to display holder.value and optionally holder.count to match the format used for other_license_expressions.

Suggested change
<li>{{ holder }}</li>
<li>{{ holder.value }}{% if holder.count is not none %} (count: {{ holder.count }}){% endif %}</li>

Copilot uses AI. Check for mistakes.
test_file = test_env.get_test_loc('templated/simple-license.txt')
result_file = test_env.get_temp_file('html')
run_scan_click(['--license', '--license-text', test_file, '--html', result_file])
results = open(result_file).read()
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

File is opened but is not closed.

Copilot uses AI. Check for mistakes.
result_file = test_env.get_temp_file('html')
run_scan_click(['--license', '--license-text', '--license-text-diagnostics',
test_file, '--html', result_file])
results = open(result_file).read()
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

File is opened but is not closed.

Copilot uses AI. Check for mistakes.
result_file = test_env.get_temp_file('html')
run_scan_click(['--license', '--classify', '--license-clarity-score',
test_dir, '--html', result_file])
results = open(result_file).read()
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

File is opened but is not closed.

Copilot uses AI. Check for mistakes.
result_file = test_env.get_temp_file('html')
run_scan_click(['--license', '--classify', '--summary',
test_dir, '--html', result_file])
results = open(result_file).read()
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

File is opened but is not closed.

Copilot uses AI. Check for mistakes.
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
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.

[RFC] Upgrade HTML output

1 participant