Skip to content

Commit cb074fc

Browse files
Add license_matches property for strucutred files
Adds license_matches property to get the LicenseMatch objects out of LicenseDetection objects directly as a property. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 3fc73dc commit cb074fc

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/packagedcode/debian_copyright.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
from os import environ
1313
from os import path
14+
from itertools import chain
1415

1516
import attr
1617

@@ -200,6 +201,15 @@ def from_file(cls, location, check_consistency=False):
200201

201202
return dc
202203

204+
@property
205+
def license_matches(self):
206+
matches = (
207+
ld.license_matches
208+
for ld in self.license_detections
209+
if ld.license_matches
210+
)
211+
return chain.from_iterable(matches)
212+
203213
def get_declared_license(
204214
self, filter_licenses=False, skip_debian_packaging=False, *args, **kwargs
205215
):

tests/packagedcode/test_debian_copyright.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import saneyaml
1919

2020
from packagedcode import debian_copyright
21-
from itertools import chain
2221

2322

2423
def check_expected_parse_copyright_file(
@@ -59,18 +58,8 @@ def check_expected_parse_copyright_file(
5958
)
6059

6160
parsed = declared_license, license_expression, copyright
62-
63-
if isinstance(dc, debian_copyright.UnstructuredCopyrightProcessor):
64-
matches = dc.license_matches
65-
66-
elif isinstance(dc, debian_copyright.StructuredCopyrightProcessor):
67-
matches = (
68-
ld.license_matches
69-
for ld in dc.license_detections
70-
if ld.license_matches
71-
)
72-
matches = chain.from_iterable(matches)
7361

62+
matches = dc.license_matches
7463
matches = [lm for lm in matches if 'unknown-license-reference' == lm.rule.license_expression]
7564
match_details = list(map(get_match_details, matches))
7665

0 commit comments

Comments
 (0)