Skip to content

Commit 323bb38

Browse files
committed
retire license category reporting
1 parent e9cdf8e commit 323bb38

9 files changed

Lines changed: 124 additions & 179 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Score,Factors,Path,Name,Type,Size,Old Path
2-
70,modified license info added copyleft added copyright info added,path.txt,path.txt,file,300,
2+
70,modified license info added copyright info added,path.txt,path.txt,file,300,

etc/scripts/testdata/json2csv/copyright_and_license_info_added.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
33
"deltacode_options": {
4-
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_new.json",
5-
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_old.json",
4+
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_new.json",
5+
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_old.json",
66
"--all-delta-types": false
77
},
88
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Score,Factors,Path,Name,Type,Size,Old Path
2-
70,modified license info added copyleft added copyright info removed,path.txt,path.txt,file,300,
2+
70,modified license info added copyright info removed,path.txt,path.txt,file,300,

etc/scripts/testdata/json2csv/license_info_added_copyright_info_removed.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
33
"deltacode_options": {
4-
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_new.json",
5-
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_old.json",
4+
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_new.json",
5+
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_old.json",
66
"--all-delta-types": false
77
},
88
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Score,Factors,Path,Name,Type,Size,Old Path
2+
50,modified license change,some/path/a/a1.py,a1.py,file,300,
23
20,modified,some/path/c/c1.py,c1.py,file,300,
34
30,modified license change,some/path/b/b1.py,b1.py,file,300,
4-
50,modified license change copyleft added,some/path/a/a1.py,a1.py,file,300,

etc/scripts/testdata/json2csv/new_license_added.json

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
{
22
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
33
"deltacode_options": {
4-
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_new_license_added.json",
5-
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_old_license_added.json",
4+
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_new_license_added.json",
5+
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_old_license_added.json",
66
"--all-delta-types": false
77
},
88
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
99
"deltacode_errors": [],
1010
"deltas": [
1111
{
1212
"factors": [
13-
"modified"
13+
"modified",
14+
"license change"
1415
],
15-
"score": 20,
16+
"score": 50,
1617
"new": {
17-
"path": "some/path/c/c1.py",
18+
"path": "some/path/a/a1.py",
1819
"type": "file",
19-
"name": "c1.py",
20+
"name": "a1.py",
2021
"size": 300,
2122
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
22-
"original_path": "some/path/c/c1.py",
23+
"original_path": "some/path/a/a1.py",
2324
"licenses": [
25+
{
26+
"key": "apache-2.0",
27+
"score": 80.0,
28+
"short_name": "Apache 2.0",
29+
"category": "Permissive",
30+
"owner": null
31+
},
32+
{
33+
"key": "agpl-2.0",
34+
"score": 70.0,
35+
"short_name": "AGPL 2.0",
36+
"category": "Copyleft",
37+
"owner": null
38+
},
39+
{
40+
"key": "bsd-simplified",
41+
"score": 100.0,
42+
"short_name": "BSD-Simplified",
43+
"category": "Permissive",
44+
"owner": null
45+
},
2446
{
2547
"key": "mit",
2648
"score": 100.0,
@@ -32,17 +54,30 @@
3254
"copyrights": []
3355
},
3456
"old": {
35-
"path": "some/path/c/c1.py",
57+
"path": "some/path/a/a1.py",
3658
"type": "file",
37-
"name": "c1.py",
59+
"name": "a1.py",
3860
"size": 300,
3961
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
40-
"original_path": "some/path/c/c1.py",
62+
"original_path": "some/path/a/a1.py",
4163
"licenses": [
64+
{"key": "apache-2.0",
65+
"score": 80.0,
66+
"short_name": "Apache 2.0",
67+
"category": "Permissive",
68+
"owner": null
69+
},
4270
{
43-
"key": "mit",
71+
"key": "public-domain",
72+
"score": 10.0,
73+
"short_name": "Public Domain",
74+
"category": "Public Domain",
75+
"owner": null
76+
},
77+
{
78+
"key": "bsd-simplified",
4479
"score": 100.0,
45-
"short_name": "MIT License",
80+
"short_name": "BSD-Simplified",
4681
"category": "Permissive",
4782
"owner": null
4883
}
@@ -52,8 +87,7 @@
5287
},
5388
{
5489
"factors": [
55-
"modified",
56-
"license change"
90+
"modified"
5791
],
5892
"score": 30,
5993
"new": {
@@ -64,27 +98,6 @@
6498
"sha1": "111647771481d39dd3a53f6dc210c26abac37748",
6599
"original_path": "some/path/b/b1.py",
66100
"licenses": [
67-
{
68-
"key": "apache-2.0",
69-
"score": 80.0,
70-
"short_name": "Apache 2.0",
71-
"category": "Permissive",
72-
"owner": null
73-
},
74-
{
75-
"key": "gpl-2.0",
76-
"score": 60.0,
77-
"short_name": "GPL 2.0",
78-
"category": "Copyleft",
79-
"owner": null
80-
},
81-
{
82-
"key": "bsd-simplified",
83-
"score": 100.0,
84-
"short_name": "BSD-Simplified",
85-
"category": "Permissive",
86-
"owner": null
87-
},
88101
{
89102
"key": "mit",
90103
"score": 100.0,
@@ -104,23 +117,9 @@
104117
"original_path": "some/path/b/b1.py",
105118
"licenses": [
106119
{
107-
"key": "mpl-2.0",
108-
"score": 90.0,
109-
"short_name": "MPL 2.0",
110-
"category": "Copyleft Limited",
111-
"owner": null
112-
},
113-
{
114-
"key": "public-domain",
115-
"score": 10.0,
116-
"short_name": "Public Domain",
117-
"category": "Public Domain",
118-
"owner": null
119-
},
120-
{
121-
"key": "bsd-simplified",
120+
"key": "mit",
122121
"score": 100.0,
123-
"short_name": "BSD-Simplified",
122+
"short_name": "MIT-License",
124123
"category": "Permissive",
125124
"owner": null
126125
}
@@ -136,12 +135,12 @@
136135
],
137136
"score": 50,
138137
"new": {
139-
"path": "some/path/a/a1.py",
138+
"path": "some/path/c/c1.py",
140139
"type": "file",
141-
"name": "a1.py",
140+
"name": "c1.py",
142141
"size": 300,
143142
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
144-
"original_path": "some/path/a/a1.py",
143+
"original_path": "some/path/c/c1.py",
145144
"licenses": [
146145
{
147146
"key": "apache-2.0",
@@ -175,12 +174,12 @@
175174
"copyrights": []
176175
},
177176
"old": {
178-
"path": "some/path/a/a1.py",
177+
"path": "some/path/c/c1.py",
179178
"type": "file",
180-
"name": "a1.py",
179+
"name": "c1.py",
181180
"size": 200,
182181
"sha1": "84b647771481d39dd3a53f6dc210c26abac37748",
183-
"original_path": "some/path/a/a1.py",
182+
"original_path": "some/path/c/c1.py",
184183
"licenses": [
185184
{
186185
"key": "apache-2.0",

src/deltacode/utils.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535

3636
def update_from_license_info(delta, unique_categories):
3737
"""
38-
Increase an 'added' or 'modified' Delta object's 'score' attribute and add
39-
one or more appropriate categories to its 'factors' attribute if there has
40-
been a license change and depending on the nature of that change.
38+
Increase an 'added' or 'modified' Delta object's 'score' attribute and
39+
annotate its 'factors' attribute if there has been a license change and
40+
depending on the nature of that change.
4141
"""
4242
if delta.is_added():
4343
update_added_from_license_info(delta, unique_categories)
@@ -48,70 +48,71 @@ def update_from_license_info(delta, unique_categories):
4848

4949
def update_added_from_license_info(delta, unique_categories):
5050
"""
51-
Increase an 'added' Delta object's 'score' attribute and add
52-
one or more categories to its 'factors' attribute if there has
53-
been a license change.
51+
Increase an 'added' Delta object's 'score' attribute and annotate its
52+
'factors' attribute if there has been a license change.
5453
"""
5554
new_licenses = delta.new_file.licenses or []
5655
new_categories = set(license.category for license in new_licenses)
5756

5857
if delta.new_file.has_licenses():
59-
delta.update(20, 'license info added')
60-
61-
for category in new_categories:
62-
# no license ==> 'Copyleft Limited'or higher
63-
if category in unique_categories:
64-
delta.update(20, category.lower() + ' added')
65-
# no license ==> 'Permissive' or 'Public Domain'
66-
else:
67-
delta.update(0, category.lower() + ' added')
58+
# delta.update(20, 'license info added')
59+
#
60+
# for category in new_categories:
61+
# # no license ==> 'Copyleft Limited'or higher
62+
# if category in unique_categories:
63+
# delta.update(20, category.lower() + ' added')
64+
# # no license ==> 'Permissive' or 'Public Domain'
65+
# else:
66+
# delta.update(0, category.lower() + ' added')
67+
delta.update(score=20, factor='license info added')
6868
return
6969

7070

7171
def update_modified_from_license_info(delta, unique_categories):
7272
"""
73-
Increase a 'modified' Delta object's 'score' attribute and add
74-
one or more categories to its 'factors' attribute if there has
75-
been a license change.
73+
Increase a 'modified' Delta object's 'score' attribute and annotate its
74+
'factors' attribute if there has been a license change.
7675
"""
7776
if not delta.new_file.has_licenses() and delta.old_file.has_licenses():
78-
delta.update(15, 'license info removed')
77+
delta.update(score=15, factor='license info removed')
7978
return
8079

8180
new_licenses = delta.new_file.licenses or []
8281
old_licenses = delta.old_file.licenses or []
8382

84-
new_categories = set(license.category for license in new_licenses)
85-
old_categories = set(license.category for license in old_licenses)
83+
# new_categories = set(license.category for license in new_licenses)
84+
# old_categories = set(license.category for license in old_licenses)
8685

8786
if delta.new_file.has_licenses() and not delta.old_file.has_licenses():
88-
delta.update(20, 'license info added')
89-
90-
for category in new_categories:
91-
# no license ==> 'Copyleft Limited'or higher
92-
if category in unique_categories:
93-
delta.update(20, category.lower() + ' added')
94-
# no license ==> 'Permissive' or 'Public Domain'
95-
else:
96-
delta.update(0, category.lower() + ' added')
97-
return
87+
# delta.update(20, 'license info added')
88+
#
89+
# for category in new_categories:
90+
# # no license ==> 'Copyleft Limited'or higher
91+
# if category in unique_categories:
92+
# delta.update(20, category.lower() + ' added')
93+
# # no license ==> 'Permissive' or 'Public Domain'
94+
# else:
95+
# delta.update(0, category.lower() + ' added')
96+
delta.update(score=20, factor='license info added')
97+
return
9898

9999
new_keys = set(license.key for license in new_licenses)
100100
old_keys = set(license.key for license in old_licenses)
101101

102102
if new_keys != old_keys:
103-
delta.update(10, 'license change')
104-
for category in new_categories - old_categories:
105-
unique_categories_in_old_file = len(old_categories & unique_categories)
106-
# 'Permissive' or 'Public Domain' ==> 'Copyleft Limited' or higher
107-
if unique_categories_in_old_file == 0 and category in unique_categories:
108-
delta.update(20, category.lower() + ' added')
109-
# at least 1 category in the old file was 'Copyleft Limited' or higher ==> 'Copyleft Limited' or higher
110-
elif unique_categories_in_old_file != 0 and category in unique_categories:
111-
delta.update(10, category.lower() + ' added')
112-
# 'Permissive' or 'Public Domain' ==> 'Permissive' or 'Public Domain' if not in old_categories
113-
elif category not in unique_categories:
114-
delta.update(0, category.lower() + ' added')
103+
# delta.update(10, 'license change')
104+
# for category in new_categories - old_categories:
105+
# unique_categories_in_old_file = len(old_categories & unique_categories)
106+
# # 'Permissive' or 'Public Domain' ==> 'Copyleft Limited' or higher
107+
# if unique_categories_in_old_file == 0 and category in unique_categories:
108+
# delta.update(20, category.lower() + ' added')
109+
# # at least 1 category in the old file was 'Copyleft Limited' or higher ==> 'Copyleft Limited' or higher
110+
# elif unique_categories_in_old_file != 0 and category in unique_categories:
111+
# delta.update(10, category.lower() + ' added')
112+
# # 'Permissive' or 'Public Domain' ==> 'Permissive' or 'Public Domain' if not in old_categories
113+
# elif category not in unique_categories:
114+
# delta.update(0, category.lower() + ' added')
115+
delta.update(score=10, factor='license change')
115116

116117

117118
def update_from_copyright_info(delta):

0 commit comments

Comments
 (0)