Skip to content

Commit dbffe43

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 <ayansmahapatra@gmail.com>
1 parent 3f78833 commit dbffe43

File tree

93 files changed

+401
-383
lines changed

Some content is hidden

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

93 files changed

+401
-383
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/additional_licenses/additional_license_combined_test.expected.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
"score": 100.0,
337337
"start_line": 1,
338338
"end_line": 1,
339+
"from_file": "additional_license_combined_test.txt",
339340
"matched_length": 11,
340341
"match_coverage": 100.0,
341342
"matcher": "2-aho",
@@ -348,6 +349,7 @@
348349
"score": 100.0,
349350
"start_line": 3,
350351
"end_line": 3,
352+
"from_file": "additional_license_combined_test.txt",
351353
"matched_length": 12,
352354
"match_coverage": 100.0,
353355
"matcher": "2-aho",
@@ -360,6 +362,7 @@
360362
"score": 100.0,
361363
"start_line": 5,
362364
"end_line": 5,
365+
"from_file": "additional_license_combined_test.txt",
363366
"matched_length": 9,
364367
"match_coverage": 100.0,
365368
"matcher": "2-aho",
@@ -372,6 +375,7 @@
372375
"score": 100.0,
373376
"start_line": 5,
374377
"end_line": 9,
378+
"from_file": "additional_license_combined_test.txt",
375379
"matched_length": 69,
376380
"match_coverage": 100.0,
377381
"matcher": "2-aho",
@@ -384,6 +388,7 @@
384388
"score": 100.0,
385389
"start_line": 12,
386390
"end_line": 12,
391+
"from_file": "additional_license_combined_test.txt",
387392
"matched_length": 4,
388393
"match_coverage": 100.0,
389394
"matcher": "2-aho",

tests/licensedcode/data/additional_licenses/additional_license_directory_test.expected.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"score": 100.0,
145145
"start_line": 1,
146146
"end_line": 1,
147+
"from_file": "additional_license_directory_test.txt",
147148
"matched_length": 9,
148149
"match_coverage": 100.0,
149150
"matcher": "2-aho",
@@ -156,6 +157,7 @@
156157
"score": 100.0,
157158
"start_line": 1,
158159
"end_line": 5,
160+
"from_file": "additional_license_directory_test.txt",
159161
"matched_length": 69,
160162
"match_coverage": 100.0,
161163
"matcher": "2-aho",

tests/licensedcode/data/additional_licenses/additional_license_plugin_test.expected.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"score": 100.0,
8585
"start_line": 1,
8686
"end_line": 1,
87+
"from_file": "additional_license_plugin_test.txt",
8788
"matched_length": 11,
8889
"match_coverage": 100.0,
8990
"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",

0 commit comments

Comments
 (0)