Skip to content

Commit

Permalink
Rename summary option to summary-legacy #2842
Browse files Browse the repository at this point in the history
    * Set summary2 to be new summary plugin
    * Update tests

Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Mar 28, 2022
1 parent d59d9df commit de4c250
Show file tree
Hide file tree
Showing 146 changed files with 196 additions and 146 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ scancode_scan =
# module for details and doc.
scancode_post_scan =
summary = summarycode.summarizer:ScanSummary
summary2 = summarycode.summarizer2:ScanSummary
summary-legacy = summarycode.summarizer:ScanSummaryLegacy
summary-keeping-details = summarycode.summarizer:ScanSummaryWithDetails
summary-key-files = summarycode.summarizer:ScanKeyFilesSummary
summary-by-facet = summarycode.summarizer:ScanByFacetSummary
Expand Down
67 changes: 51 additions & 16 deletions src/summarycode/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,38 @@ def logger_debug(*args):
"""


class SummaryPluginDeprecationWarning(DeprecationWarning):
@post_scan_impl
class ScanSummary(PostScanPlugin):
"""
Summarize a scan at the codebase level.
"""
sort_order = 10

codebase_attributes = dict(summary=attr.ib(default=attr.Factory(dict)))

options = [
PluggableCommandLineOption(('--summary',),
is_flag=True, default=False,
help='Summarize license, copyright and other scans at the codebase level.',
help_group=POST_SCAN_GROUP,
required_options=['classify', 'license_clarity_score']
)
]

def is_enabled(self, summary, **kwargs):
return summary

def process_codebase(self, codebase, summary, **kwargs):
if TRACE_LIGHT: logger_debug('ScanSummary:process_codebase')
summarize_codebase(codebase, keep_details=False, **kwargs)


class SummaryLegacyPluginDeprecationWarning(DeprecationWarning):
pass


@post_scan_impl
class ScanSummary(PostScanPlugin):
class ScanSummaryLegacy(PostScanPlugin):
"""
Summarize a scan at the codebase level.
"""
Expand All @@ -59,7 +85,7 @@ class ScanSummary(PostScanPlugin):
codebase_attributes = dict(summary=attr.ib(default=attr.Factory(dict)))

options = [
PluggableCommandLineOption(('--summary',),
PluggableCommandLineOption(('--summary-legacy',),
is_flag=True, default=False,
help='Summarize license, copyright and other scans at the codebase level.',
help_group=POST_SCAN_GROUP)
Expand All @@ -69,17 +95,17 @@ def is_enabled(self, summary, **kwargs):
return summary

def process_codebase(self, codebase, summary, **kwargs):
deprecation_message = "The --summary option will be deprecated in a future version of scancode-toolkit."
warnings.simplefilter('always', SummaryPluginDeprecationWarning)
deprecation_message = "The --summary-legacy option will be deprecated in a future version of scancode-toolkit."
warnings.simplefilter('always', SummaryLegacyPluginDeprecationWarning)
warnings.warn(
deprecation_message,
SummaryPluginDeprecationWarning,
SummaryLegacyPluginDeprecationWarning,
stacklevel=2,
)
codebase_header = codebase.get_or_create_current_header()
codebase_header.warnings.append(deprecation_message)
if TRACE_LIGHT: logger_debug('ScanSummary:process_codebase')
summarize_codebase(codebase, keep_details=False, **kwargs)
if TRACE_LIGHT: logger_debug('ScanSummaryLegacy:process_codebase')
summarize_codebase(codebase, keep_details=False, legacy=True, **kwargs)


class SummaryWithDetailsDeprecationWarning(DeprecationWarning):
Expand Down Expand Up @@ -119,29 +145,38 @@ def process_codebase(self, codebase, summary_with_details, **kwargs):
)
codebase_header = codebase.get_or_create_current_header()
codebase_header.warnings.append(deprecation_message)
summarize_codebase(codebase, keep_details=True, **kwargs)
summarize_codebase(codebase, keep_details=True, legacy=True, **kwargs)


def summarize_codebase(codebase, keep_details, **kwargs):
def summarize_codebase(codebase, keep_details, legacy=False, **kwargs):
"""
Summarize a scan at the codebase level for available scans.
If `keep_details` is True, also keep file and directory details in the
`summary` file attribute for every file and directory.
If `legacy` is True, summarize copyrights, authors, programming languages,
and packages.
"""
from summarycode.copyright_summary import author_summarizer
from summarycode.copyright_summary import copyright_summarizer
from summarycode.copyright_summary import holder_summarizer

attrib_summarizers = [
('license_expressions', license_summarizer),
('copyrights', copyright_summarizer),
('holders', holder_summarizer),
('authors', author_summarizer),
('programming_language', language_summarizer),
('packages', package_summarizer),
]

if legacy:
from summarycode.copyright_summary import author_summarizer
from summarycode.copyright_summary import copyright_summarizer

attrib_summarizers.extend([
('copyrights', copyright_summarizer),
('authors', author_summarizer),
('programming_language', language_summarizer),
('packages', package_summarizer),
])


# find which attributes are available for summarization by checking the root
# resource
root = codebase.root
Expand Down
5 changes: 3 additions & 2 deletions tests/summarycode/data/classify/cli.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"--json-pp": "<file>"
},
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"output_format_version": "1.0.0",
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"spdx_license_list_version": "3.14",
"spdx_license_list_version": "3.16",
"files_count": 8
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/summarycode/data/facet/cli.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"--json-pp": "<file>"
},
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"output_format_version": "1.0.0",
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"spdx_license_list_version": "3.14",
"spdx_license_list_version": "3.16",
"files_count": 56
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/summarycode/data/generated/cli.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"--json-pp": "<file>"
},
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"output_format_version": "1.0.0",
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"spdx_license_list_version": "3.14",
"spdx_license_list_version": "3.16",
"files_count": 7
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.16",
"files_count": 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.16",
"files_count": 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"output_format_version": null,
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"files_count": 2183
}
Expand All @@ -36,8 +37,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 2183
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 3
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.16",
"files_count": 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.16",
"files_count": 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.16",
"files_count": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 4
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 4
}
}
Expand Down
6 changes: 5 additions & 1 deletion tests/summarycode/data/plugin_consolidate/zlib-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"output_format_version": null,
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"files_count": 253
}
Expand All @@ -36,8 +37,11 @@
"output_format_version": "2.0.0",
"message": null,
"errors": [],
"warnings": [
"The --consolidate option will be deprecated in a future version of scancode-toolkit."
],
"extra_data": {
"spdx_license_list_version": "3.15",
"spdx_license_list_version": "3.16",
"files_count": 253
}
}
Expand Down
Loading

0 comments on commit de4c250

Please sign in to comment.