Skip to content

Commit 9a49600

Browse files
Fix from-file bug for codebase packages
Here `from-file` attributes were being assigned after creation of top level packages so we had them empty. Adds a temporary fix to this. Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 3f78833 commit 9a49600

File tree

87 files changed

+390
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+390
-380
lines changed

src/packagedcode/plugin_package.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from licensedcode.cache import build_spdx_license_expression
2626
from licensedcode.cache import get_cache
2727
from licensedcode.detection import DetectionRule
28+
from licensedcode.detection import populate_matches_with_path
2829
from packagedcode import get_package_handler
2930
from packagedcode.licensing import add_referenced_license_matches_for_package
3031
from packagedcode.licensing import add_referenced_license_detection_from_package
3132
from packagedcode.licensing import add_license_from_sibling_file
32-
from packagedcode.licensing import get_license_detection_mappings
3333
from packagedcode.licensing import get_license_expression_from_detection_mappings
3434
from packagedcode.models import add_to_package
3535
from packagedcode.models import Dependency
@@ -328,7 +328,17 @@ def create_package_and_deps(codebase, package_adder=add_to_package, strip_root=F
328328
strip_root=strip_root,
329329
**kwargs
330330
)
331-
codebase.attributes.packages.extend(pkg.to_dict() for pkg in packages)
331+
332+
package_mappings = []
333+
for package in packages:
334+
for detection in package.license_detections:
335+
populate_matches_with_path(
336+
matches=detection["matches"],
337+
path=package.datafile_paths[0],
338+
)
339+
package_mappings.append(package.to_dict())
340+
341+
codebase.attributes.packages.extend(package_mappings)
332342
codebase.attributes.dependencies.extend(dep.to_dict() for dep in dependencies)
333343

334344

tests/formattedcode/data/common/manifests-expected.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"score": 100.0,
3535
"start_line": 1,
3636
"end_line": 1,
37-
"from_file": null,
37+
"from_file": "manifests/maven/persistence-api-1.0.pom",
3838
"matched_length": 8,
3939
"match_coverage": 100.0,
4040
"matcher": "2-aho",
@@ -48,7 +48,7 @@
4848
"score": 100.0,
4949
"start_line": 2,
5050
"end_line": 2,
51-
"from_file": null,
51+
"from_file": "manifests/maven/persistence-api-1.0.pom",
5252
"matched_length": 7,
5353
"match_coverage": 100.0,
5454
"matcher": "2-aho",
@@ -127,7 +127,7 @@
127127
"score": 100.0,
128128
"start_line": 1,
129129
"end_line": 1,
130-
"from_file": null,
130+
"from_file": "manifests/npm-license-mapping/package.json",
131131
"matched_length": 3,
132132
"match_coverage": 100.0,
133133
"matcher": "1-hash",
@@ -147,7 +147,7 @@
147147
"score": 100.0,
148148
"start_line": 1,
149149
"end_line": 1,
150-
"from_file": null,
150+
"from_file": "manifests/npm-license-mapping/package.json",
151151
"matched_length": 3,
152152
"match_coverage": 100.0,
153153
"matcher": "1-hash",
@@ -222,7 +222,7 @@
222222
"score": 100.0,
223223
"start_line": 1,
224224
"end_line": 1,
225-
"from_file": null,
225+
"from_file": "manifests/npm-license-string/package.json",
226226
"matched_length": 1,
227227
"match_coverage": 100.0,
228228
"matcher": "1-spdx-id",

tests/formattedcode/data/common/manifests-expected.jsonlines

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"score": 100.0,
6767
"start_line": 1,
6868
"end_line": 1,
69-
"from_file": null,
69+
"from_file": "manifests/maven/persistence-api-1.0.pom",
7070
"matched_length": 8,
7171
"match_coverage": 100.0,
7272
"matcher": "2-aho",
@@ -80,7 +80,7 @@
8080
"score": 100.0,
8181
"start_line": 2,
8282
"end_line": 2,
83-
"from_file": null,
83+
"from_file": "manifests/maven/persistence-api-1.0.pom",
8484
"matched_length": 7,
8585
"match_coverage": 100.0,
8686
"matcher": "2-aho",
@@ -159,7 +159,7 @@
159159
"score": 100.0,
160160
"start_line": 1,
161161
"end_line": 1,
162-
"from_file": null,
162+
"from_file": "manifests/npm-license-mapping/package.json",
163163
"matched_length": 3,
164164
"match_coverage": 100.0,
165165
"matcher": "1-hash",
@@ -179,7 +179,7 @@
179179
"score": 100.0,
180180
"start_line": 1,
181181
"end_line": 1,
182-
"from_file": null,
182+
"from_file": "manifests/npm-license-mapping/package.json",
183183
"matched_length": 3,
184184
"match_coverage": 100.0,
185185
"matcher": "1-hash",
@@ -254,7 +254,7 @@
254254
"score": 100.0,
255255
"start_line": 1,
256256
"end_line": 1,
257-
"from_file": null,
257+
"from_file": "manifests/npm-license-string/package.json",
258258
"matched_length": 1,
259259
"match_coverage": 100.0,
260260
"matcher": "1-spdx-id",

tests/formattedcode/data/common/manifests-expected.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ packages:
9696
- score: '100.0'
9797
start_line: 1
9898
end_line: 1
99-
from_file:
99+
from_file: manifests/maven/persistence-api-1.0.pom
100100
matched_length: 8
101101
match_coverage: '100.0'
102102
matcher: 2-aho
@@ -108,7 +108,7 @@ packages:
108108
- score: '100.0'
109109
start_line: 2
110110
end_line: 2
111-
from_file:
111+
from_file: manifests/maven/persistence-api-1.0.pom
112112
matched_length: 7
113113
match_coverage: '100.0'
114114
matcher: 2-aho
@@ -174,7 +174,7 @@ packages:
174174
- score: '100.0'
175175
start_line: 1
176176
end_line: 1
177-
from_file:
177+
from_file: manifests/npm-license-mapping/package.json
178178
matched_length: 3
179179
match_coverage: '100.0'
180180
matcher: 1-hash
@@ -189,7 +189,7 @@ packages:
189189
- score: '100.0'
190190
start_line: 1
191191
end_line: 1
192-
from_file:
192+
from_file: manifests/npm-license-mapping/package.json
193193
matched_length: 3
194194
match_coverage: '100.0'
195195
matcher: 1-hash
@@ -254,7 +254,7 @@ packages:
254254
- score: '100.0'
255255
start_line: 1
256256
end_line: 1
257-
from_file:
257+
from_file: manifests/npm-license-string/package.json
258258
matched_length: 1
259259
match_coverage: '100.0'
260260
matcher: 1-spdx-id

tests/formattedcode/data/yaml/package-and-licenses-expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ packages:
9292
- score: '100.0'
9393
start_line: 1
9494
end_line: 1
95-
from_file:
95+
from_file: package-and-licenses/setup.cfg
9696
matched_length: 3
9797
match_coverage: '100.0'
9898
matcher: 1-hash

tests/licensedcode/data/licenses_reference_reporting/scan-matched-text-with-reference.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"score": 100.0,
4848
"start_line": 1,
4949
"end_line": 1,
50-
"from_file": null,
50+
"from_file": "scan/package.json",
5151
"matched_length": 5,
5252
"match_coverage": 100.0,
5353
"matcher": "1-spdx-id",

tests/licensedcode/data/licenses_reference_reporting/scan-with-reference.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"score": 100.0,
4848
"start_line": 1,
4949
"end_line": 1,
50-
"from_file": null,
50+
"from_file": "scan/package.json",
5151
"matched_length": 5,
5252
"match_coverage": 100.0,
5353
"matcher": "1-spdx-id",

tests/packagedcode/data/about/aboutfiles.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"score": 100.0,
4343
"start_line": 1,
4444
"end_line": 1,
45-
"from_file": null,
45+
"from_file": "aboutfiles/apipkg.ABOUT",
4646
"matched_length": 1,
4747
"match_coverage": 100.0,
4848
"matcher": "1-spdx-id",
@@ -117,7 +117,7 @@
117117
"score": 100.0,
118118
"start_line": 1,
119119
"end_line": 1,
120-
"from_file": null,
120+
"from_file": "aboutfiles/appdirs.ABOUT",
121121
"matched_length": 1,
122122
"match_coverage": 100.0,
123123
"matcher": "1-spdx-id",

tests/packagedcode/data/alpine/alpine-container-layer.tar.xz-get-installed-expected.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"score": 100.0,
4444
"start_line": 1,
4545
"end_line": 1,
46-
"from_file": null,
46+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
4747
"matched_length": 4,
4848
"match_coverage": 100.0,
4949
"matcher": "1-hash",
@@ -253,7 +253,7 @@
253253
"score": 100.0,
254254
"start_line": 1,
255255
"end_line": 1,
256-
"from_file": null,
256+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
257257
"matched_length": 1,
258258
"match_coverage": 100.0,
259259
"matcher": "1-spdx-id",
@@ -355,7 +355,7 @@
355355
"score": 100.0,
356356
"start_line": 1,
357357
"end_line": 1,
358-
"from_file": null,
358+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
359359
"matched_length": 4,
360360
"match_coverage": 100.0,
361361
"matcher": "1-hash",
@@ -502,7 +502,7 @@
502502
"score": 100.0,
503503
"start_line": 1,
504504
"end_line": 1,
505-
"from_file": null,
505+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
506506
"matched_length": 4,
507507
"match_coverage": 100.0,
508508
"matcher": "1-hash",
@@ -712,7 +712,7 @@
712712
"score": 100.0,
713713
"start_line": 1,
714714
"end_line": 1,
715-
"from_file": null,
715+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
716716
"matched_length": 1,
717717
"match_coverage": 100.0,
718718
"matcher": "1-spdx-id",
@@ -1165,7 +1165,7 @@
11651165
"score": 100.0,
11661166
"start_line": 1,
11671167
"end_line": 1,
1168-
"from_file": null,
1168+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
11691169
"matched_length": 5,
11701170
"match_coverage": 100.0,
11711171
"matcher": "1-spdx-id",
@@ -1267,7 +1267,7 @@
12671267
"score": 100.0,
12681268
"start_line": 1,
12691269
"end_line": 1,
1270-
"from_file": null,
1270+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
12711271
"matched_length": 1,
12721272
"match_coverage": 100.0,
12731273
"matcher": "1-spdx-id",
@@ -1459,7 +1459,7 @@
14591459
"score": 100.0,
14601460
"start_line": 1,
14611461
"end_line": 1,
1462-
"from_file": null,
1462+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
14631463
"matched_length": 1,
14641464
"match_coverage": 100.0,
14651465
"matcher": "1-spdx-id",
@@ -1561,7 +1561,7 @@
15611561
"score": 100.0,
15621562
"start_line": 1,
15631563
"end_line": 1,
1564-
"from_file": null,
1564+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
15651565
"matched_length": 4,
15661566
"match_coverage": 100.0,
15671567
"matcher": "1-hash",
@@ -1651,7 +1651,7 @@
16511651
"score": 100.0,
16521652
"start_line": 1,
16531653
"end_line": 1,
1654-
"from_file": null,
1654+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
16551655
"matched_length": 1,
16561656
"match_coverage": 100.0,
16571657
"matcher": "1-spdx-id",
@@ -1753,7 +1753,7 @@
17531753
"score": 100.0,
17541754
"start_line": 1,
17551755
"end_line": 1,
1756-
"from_file": null,
1756+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
17571757
"matched_length": 4,
17581758
"match_coverage": 100.0,
17591759
"matcher": "1-hash",
@@ -1852,7 +1852,7 @@
18521852
"score": 100.0,
18531853
"start_line": 1,
18541854
"end_line": 1,
1855-
"from_file": null,
1855+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
18561856
"matched_length": 4,
18571857
"match_coverage": 100.0,
18581858
"matcher": "1-hash",
@@ -1942,7 +1942,7 @@
19421942
"score": 100.0,
19431943
"start_line": 1,
19441944
"end_line": 1,
1945-
"from_file": null,
1945+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
19461946
"matched_length": 11,
19471947
"match_coverage": 100.0,
19481948
"matcher": "1-spdx-id",
@@ -2068,7 +2068,7 @@
20682068
"score": 100.0,
20692069
"start_line": 1,
20702070
"end_line": 1,
2071-
"from_file": null,
2071+
"from_file": "alpine-container-layer.tar.xz/lib/apk/db/installed",
20722072
"matched_length": 7,
20732073
"match_coverage": 100.0,
20742074
"matcher": "1-spdx-id",

0 commit comments

Comments
 (0)