Skip to content

Commit a1493a1

Browse files
committed
Update Consolidation attributes
* Remove plugin specific gitignore from project level gitignore * Update tests Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent bb1d846 commit a1493a1

11 files changed

Lines changed: 124 additions & 89 deletions

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,3 @@ pyvenv.cfg
7878
/.pytest_cache/
7979
lib64
8080
tcl
81-
82-
# Nested ScanCode plugins
83-
*build*
84-
*dist*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build/
2+
/dist/

plugins/scancode-consolidate-scan/src/plugin_consolidate/__init__.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,37 @@ class Consolidation(object):
7474
"""
7575
# TODO: Add file counts for proper accounting
7676
identifier = attr.ib(default=None)
77+
consolidated_license_expression = attr.ib(default=None)
78+
consolidated_holders = attr.ib(default=attr.Factory(list))
79+
consolidated_copyright = attr.ib(default=None)
7780
core_license_expression = attr.ib(default=None)
78-
other_license_expression = attr.ib(default=None)
79-
consolidated_core_copyright = attr.ib(default=None)
80-
consolidated_other_copyright = attr.ib(default=None)
8181
core_holders = attr.ib(default=attr.Factory(list))
82+
other_license_expression = attr.ib(default=None)
8283
other_holders = attr.ib(default=attr.Factory(list))
84+
resources_count = attr.ib(default=None)
8385
resources = attr.ib(default=attr.Factory(list))
8486

8587
def to_dict(self, **kwargs):
8688
def dict_fields(attr, value):
8789
if attr.name in ('resources', ):
8890
return False
8991
return True
90-
self.consolidated_core_copyright = self.consolidate_core_copyright()
91-
self.consolidated_other_copyright = self.consolidate_other_copyright()
92+
license_expressions_to_consolidate = []
93+
if self.core_license_expression:
94+
license_expressions_to_consolidate.append(self.core_license_expression)
95+
if self.other_license_expression:
96+
license_expressions_to_consolidate.append(self.other_license_expression)
97+
if license_expressions_to_consolidate:
98+
self.consolidated_license_expression = combine_expressions(license_expressions_to_consolidate)
99+
self.consolidated_copyright = self.consolidate_copyright()
92100
return attr.asdict(self, filter=dict_fields, dict_factory=OrderedDict)
93101

94-
def consolidate_core_copyright(self):
95-
# TODO: Verify and test that we are generating detectable copyrights
96-
holders = list(self.core_holders) + list(self.other_holders)
97-
if holders:
98-
return 'Copyright (c) {}'.format(', '.join(holders))
99-
100-
def consolidate_other_copyright(self):
102+
def consolidate_copyright(self):
101103
# TODO: Verify and test that we are generating detectable copyrights
102-
other_holders = list(self.other_holders)
103-
if other_holders:
104-
return 'Copyright (c) {}'.format(', '.join(other_holders))
104+
if not self.consolidated_holders:
105+
self.consolidated_holders = sorted(set(list(self.core_holders) + list(self.other_holders)))
106+
else:
107+
return 'Copyright (c) {}'.format(', '.join(self.consolidated_holders))
105108

106109

107110
@attr.s
@@ -259,9 +262,10 @@ def get_consolidated_packages(codebase):
259262

260263
c = Consolidation(
261264
core_license_expression=package_license_expression,
262-
other_license_expression=simplified_discovered_license_expression,
263265
core_holders=sorted(set(package_holders)),
266+
other_license_expression=simplified_discovered_license_expression,
264267
other_holders=sorted(set(discovered_holders)),
268+
resources_count=len(package_resources),
265269
resources=package_resources,
266270
)
267271
yield ConsolidatedPackage(
@@ -375,6 +379,7 @@ def create_license_holders_consolidated_component(resource, codebase):
375379
c = Consolidation(
376380
core_license_expression=license_expression,
377381
core_holders=holders,
382+
resources_count=len(component_resources),
378383
resources=component_resources,
379384
)
380385
return ConsolidatedComponent(
@@ -427,6 +432,7 @@ def combine_license_holders_consolidated_components(components):
427432
c = Consolidation(
428433
core_license_expression=component_license_expression,
429434
core_holders=component_holders,
435+
resources_count=len(component_resources),
430436
resources=component_resources,
431437
)
432438
yield ConsolidatedComponent(

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/clear-summary-expected.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323
{
2424
"type": "license-holders",
2525
"identifier": "the_apache_software_foundation_1",
26+
"consolidated_license_expression": "apache-2.0",
27+
"consolidated_holders": [
28+
"The Apache Software Foundation"
29+
],
30+
"consolidated_copyright": null,
2631
"core_license_expression": "apache-2.0",
27-
"other_license_expression": null,
28-
"consolidated_core_copyright": "Copyright (c) The Apache Software Foundation",
29-
"consolidated_other_copyright": null,
3032
"core_holders": [
3133
"The Apache Software Foundation"
3234
],
33-
"other_holders": []
35+
"other_license_expression": null,
36+
"other_holders": [],
37+
"resources_count": 4
3438
}
3539
],
3640
"consolidated_packages": [],

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/component-package-expected.json

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
{
44
"tool_name": "scancode-toolkit",
55
"options": {
6-
"input": [
7-
"plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/component-package"
8-
],
6+
"input": "<path>",
7+
"--consolidate": true,
98
"--copyright": true,
109
"--info": true,
11-
"--json-pp": "plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/component-package.json",
10+
"--json": "<file>",
1211
"--license": true,
1312
"--package": true
1413
},
@@ -18,37 +17,24 @@
1817
"extra_data": {
1918
"files_count": 7
2019
}
21-
},
22-
{
23-
"tool_name": "scancode-toolkit",
24-
"options": {
25-
"input": "<path>",
26-
"--consolidate": true,
27-
"--from-json": [
28-
true
29-
],
30-
"--json": "<file>"
31-
},
32-
"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.",
33-
"message": null,
34-
"errors": [],
35-
"extra_data": {
36-
"files_count": 7
37-
}
3820
}
3921
],
4022
"consolidated_components": [
4123
{
4224
"type": "license-holders",
4325
"identifier": "the_apache_software_foundation_1",
26+
"consolidated_license_expression": "apache-2.0",
27+
"consolidated_holders": [
28+
"The Apache Software Foundation"
29+
],
30+
"consolidated_copyright": null,
4431
"core_license_expression": "apache-2.0",
45-
"other_license_expression": null,
46-
"consolidated_core_copyright": "Copyright (c) The Apache Software Foundation",
47-
"consolidated_other_copyright": null,
4832
"core_holders": [
4933
"The Apache Software Foundation"
5034
],
51-
"other_holders": []
35+
"other_license_expression": null,
36+
"other_holders": [],
37+
"resources_count": 4
5238
}
5339
],
5440
"consolidated_packages": [
@@ -89,16 +75,22 @@
8975
"repository_download_url": "https://registry.npmjs.org/test-package/-/test-package-0.0.1.tgz",
9076
"api_data_url": "https://registry.npmjs.org/test-package/0.0.1",
9177
"identifier": "pkg_npm_test_package_0_0_1_1",
78+
"consolidated_license_expression": "apache-2.0 AND (apache-2.0 AND gpl-1.0-plus AND unknown)",
79+
"consolidated_holders": [
80+
"IBM Corp.",
81+
"The Apache Software",
82+
"The Apache Software Foundation"
83+
],
84+
"consolidated_copyright": null,
9285
"core_license_expression": "apache-2.0",
93-
"other_license_expression": "apache-2.0 AND gpl-1.0-plus AND unknown",
94-
"consolidated_core_copyright": "Copyright (c) IBM Corp., The Apache Software, The Apache Software Foundation",
95-
"consolidated_other_copyright": "Copyright (c) IBM Corp., The Apache Software, The Apache Software Foundation",
9686
"core_holders": [],
87+
"other_license_expression": "apache-2.0 AND gpl-1.0-plus AND unknown",
9788
"other_holders": [
9889
"IBM Corp.",
9990
"The Apache Software",
10091
"The Apache Software Foundation"
101-
]
92+
],
93+
"resources_count": 4
10294
}
10395
],
10496
"files": [

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/license-holder-rollup-expected.json

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,50 @@
2323
{
2424
"type": "license-holders",
2525
"identifier": "ibm_corp__1",
26+
"consolidated_license_expression": "gpl-1.0-plus AND gpl-2.0",
27+
"consolidated_holders": [
28+
"IBM Corp."
29+
],
30+
"consolidated_copyright": null,
2631
"core_license_expression": "gpl-1.0-plus AND gpl-2.0",
27-
"other_license_expression": null,
28-
"consolidated_core_copyright": "Copyright (c) IBM Corp.",
29-
"consolidated_other_copyright": null,
3032
"core_holders": [
3133
"IBM Corp."
3234
],
33-
"other_holders": []
35+
"other_license_expression": null,
36+
"other_holders": [],
37+
"resources_count": 2
3438
},
3539
{
3640
"type": "license-holders",
3741
"identifier": "oracle_corp__2",
42+
"consolidated_license_expression": "unknown AND apache-2.0",
43+
"consolidated_holders": [
44+
"Oracle Corp."
45+
],
46+
"consolidated_copyright": null,
3847
"core_license_expression": "unknown AND apache-2.0",
39-
"other_license_expression": null,
40-
"consolidated_core_copyright": "Copyright (c) Oracle Corp.",
41-
"consolidated_other_copyright": null,
4248
"core_holders": [
4349
"Oracle Corp."
4450
],
45-
"other_holders": []
51+
"other_license_expression": null,
52+
"other_holders": [],
53+
"resources_count": 2
4654
},
4755
{
4856
"type": "license-holders",
4957
"identifier": "omega_com_3",
58+
"consolidated_license_expression": "gpl-1.0-plus AND gpl-2.0",
59+
"consolidated_holders": [
60+
"omega.com"
61+
],
62+
"consolidated_copyright": null,
5063
"core_license_expression": "gpl-1.0-plus AND gpl-2.0",
51-
"other_license_expression": null,
52-
"consolidated_core_copyright": "Copyright (c) omega.com",
53-
"consolidated_other_copyright": null,
5464
"core_holders": [
5565
"omega.com"
5666
],
57-
"other_holders": []
67+
"other_license_expression": null,
68+
"other_holders": [],
69+
"resources_count": 3
5870
}
5971
],
6072
"consolidated_packages": [],

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/multiple-same-holder-and-license-expected.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
{
2424
"type": "license-holders",
2525
"identifier": "ibm_corp__ibm_corp__1",
26+
"consolidated_license_expression": "gpl-2.0",
27+
"consolidated_holders": [
28+
"IBM Corp."
29+
],
30+
"consolidated_copyright": null,
2631
"core_license_expression": "gpl-2.0",
27-
"other_license_expression": null,
28-
"consolidated_core_copyright": "Copyright (c) IBM Corp., IBM Corp.",
29-
"consolidated_other_copyright": null,
3032
"core_holders": [
3133
"IBM Corp.",
3234
"IBM Corp."
3335
],
34-
"other_holders": []
36+
"other_license_expression": null,
37+
"other_holders": [],
38+
"resources_count": 3
3539
}
3640
],
3741
"consolidated_packages": [],

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/package-files-not-counted-in-license-holders-expected.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@
5858
"repository_download_url": "https://registry.npmjs.org/test-package/-/test-package-0.0.1.tgz",
5959
"api_data_url": "https://registry.npmjs.org/test-package/0.0.1",
6060
"identifier": "pkg_npm_test_package_0_0_1_1",
61+
"consolidated_license_expression": "apache-2.0",
62+
"consolidated_holders": [
63+
"The Apache Software",
64+
"The Apache Software Foundation"
65+
],
66+
"consolidated_copyright": null,
6167
"core_license_expression": "apache-2.0",
62-
"other_license_expression": "apache-2.0",
63-
"consolidated_core_copyright": "Copyright (c) The Apache Software, The Apache Software Foundation",
64-
"consolidated_other_copyright": "Copyright (c) The Apache Software, The Apache Software Foundation",
6568
"core_holders": [],
69+
"other_license_expression": "apache-2.0",
6670
"other_holders": [
6771
"The Apache Software",
6872
"The Apache Software Foundation"
69-
]
73+
],
74+
"resources_count": 5
7075
}
7176
],
7277
"files": [

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/package-fileset-expected.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@
5858
"repository_download_url": "https://registry.npmjs.org/test-package/-/test-package-0.0.1.tgz",
5959
"api_data_url": "https://registry.npmjs.org/test-package/0.0.1",
6060
"identifier": "pkg_npm_test_package_0_0_1_1",
61+
"consolidated_license_expression": "apache-2.0",
62+
"consolidated_holders": [
63+
"The Apache Software Foundation"
64+
],
65+
"consolidated_copyright": null,
6166
"core_license_expression": "apache-2.0",
62-
"other_license_expression": "apache-2.0",
63-
"consolidated_core_copyright": "Copyright (c) The Apache Software Foundation",
64-
"consolidated_other_copyright": "Copyright (c) The Apache Software Foundation",
6567
"core_holders": [],
68+
"other_license_expression": "apache-2.0",
6669
"other_holders": [
6770
"The Apache Software Foundation"
68-
]
71+
],
72+
"resources_count": 5
6973
}
7074
],
7175
"files": [

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/package-manifest-expected.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@
5858
"repository_download_url": "https://registry.npmjs.org/test-package/-/test-package-0.0.1.tgz",
5959
"api_data_url": "https://registry.npmjs.org/test-package/0.0.1",
6060
"identifier": "pkg_npm_test_package_0_0_1_1",
61+
"consolidated_license_expression": "apache-2.0",
62+
"consolidated_holders": [],
63+
"consolidated_copyright": null,
6164
"core_license_expression": "apache-2.0",
62-
"other_license_expression": "apache-2.0",
63-
"consolidated_core_copyright": null,
64-
"consolidated_other_copyright": null,
6565
"core_holders": [],
66-
"other_holders": []
66+
"other_license_expression": "apache-2.0",
67+
"other_holders": [],
68+
"resources_count": 2
6769
}
6870
],
6971
"files": [

0 commit comments

Comments
 (0)