Skip to content

Commit

Permalink
Move license match functions to licensing
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
  • Loading branch information
AyanSinhaMahapatra committed Aug 19, 2021
1 parent 1cfce87 commit 4330a73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/packagedcode/debian_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from licensedcode.cache import get_index
from licensedcode.match import set_lines
from packagedcode.utils import combine_expressions
from packagedcode.licensing import get_license_matches
from packagedcode.licensing import get_license_expression_from_matches
from textcode.analysis import unicode_text

"""
Expand Down Expand Up @@ -1129,19 +1131,6 @@ def copyright_detector(location):
return copyrights


def get_license_matches(location=None, query_string=None):
"""
Returns a sequence of LicenseMatch objects wit license detections for the
`query_string` or the file at `location`.
"""
if not query_string:
return []
from licensedcode import cache

idx = cache.get_index()
return idx.match(location=location, query_string=query_string)


def filter_duplicate_strings(strings):
"""
Given a list of strings, return only the unique strings, preserving order.
Expand Down Expand Up @@ -1253,14 +1242,6 @@ def clean_expression(text):
return cleaned_text


def get_license_expression_from_matches(license_matches):
"""
Craft a license expression from a list of LicenseMatch objects.
"""
license_expressions = [match.rule.license_expression for match in license_matches]
return combine_expressions(license_expressions, unique=False)


def remove_known_license_intros(license_matches):
"""
Returns a list of LicenseMatch objects after removing unknown license intros
Expand Down
23 changes: 23 additions & 0 deletions src/packagedcode/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ def logger_debug(*args):
for a in args))


def get_license_matches(location=None, query_string=None):
"""
Returns a sequence of LicenseMatch objects wit license detections for the
`query_string` or the file at `location`.
"""
if not query_string:
return []
from licensedcode import cache

idx = cache.get_index()
return idx.match(location=location, query_string=query_string)


def get_license_expression_from_matches(license_matches):
"""
Craft a license expression from a list of LicenseMatch objects.
"""
from packagedcode.utils import combine_expressions

license_expressions = [match.rule.license_expression for match in license_matches]
return combine_expressions(license_expressions, unique=False)


def matches_have_unknown(matches, licensing):
"""
Return True if any of the LicenseMatch in `matches` has an unknown license.
Expand Down

0 comments on commit 4330a73

Please sign in to comment.