Skip to content

Commit 949376c

Browse files
AyanSinhaMahapatrapombredanne
authored andcommitted
Move license match functions to licensing
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent e09f952 commit 949376c

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/packagedcode/debian_copyright.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from licensedcode.cache import get_index
2828
from licensedcode.match import set_lines
2929
from packagedcode.utils import combine_expressions
30+
from packagedcode.licensing import get_license_matches
31+
from packagedcode.licensing import get_license_expression_from_matches
3032
from textcode.analysis import unicode_text
3133

3234
"""
@@ -1129,19 +1131,6 @@ def copyright_detector(location):
11291131
return copyrights
11301132

11311133

1132-
def get_license_matches(location=None, query_string=None):
1133-
"""
1134-
Returns a sequence of LicenseMatch objects wit license detections for the
1135-
`query_string` or the file at `location`.
1136-
"""
1137-
if not query_string:
1138-
return []
1139-
from licensedcode import cache
1140-
1141-
idx = cache.get_index()
1142-
return idx.match(location=location, query_string=query_string)
1143-
1144-
11451134
def filter_duplicate_strings(strings):
11461135
"""
11471136
Given a list of strings, return only the unique strings, preserving order.
@@ -1253,14 +1242,6 @@ def clean_expression(text):
12531242
return cleaned_text
12541243

12551244

1256-
def get_license_expression_from_matches(license_matches):
1257-
"""
1258-
Craft a license expression from a list of LicenseMatch objects.
1259-
"""
1260-
license_expressions = [match.rule.license_expression for match in license_matches]
1261-
return combine_expressions(license_expressions, unique=False)
1262-
1263-
12641245
def remove_known_license_intros(license_matches):
12651246
"""
12661247
Returns a list of LicenseMatch objects after removing unknown license intros

src/packagedcode/licensing.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ def logger_debug(*args):
3636
for a in args))
3737

3838

39+
def get_license_matches(location=None, query_string=None):
40+
"""
41+
Returns a sequence of LicenseMatch objects wit license detections for the
42+
`query_string` or the file at `location`.
43+
"""
44+
if not query_string:
45+
return []
46+
from licensedcode import cache
47+
48+
idx = cache.get_index()
49+
return idx.match(location=location, query_string=query_string)
50+
51+
52+
def get_license_expression_from_matches(license_matches):
53+
"""
54+
Craft a license expression from a list of LicenseMatch objects.
55+
"""
56+
from packagedcode.utils import combine_expressions
57+
58+
license_expressions = [match.rule.license_expression for match in license_matches]
59+
return combine_expressions(license_expressions, unique=False)
60+
61+
3962
def matches_have_unknown(matches, licensing):
4063
"""
4164
Return True if any of the LicenseMatch in `matches` has an unknown license.

0 commit comments

Comments
 (0)