Skip to content

Commit 5de2744

Browse files
Add rule_url and update scancode URLs
* add a new attribute `rule_url` to LicenseMatch results. * deleted License attributes 'scancode_data_url' and 'scancode_text_url' and replaced them with a single License attribute 'scancode_url' * regen test expectations accordingly Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent f0213ec commit 5de2744

File tree

766 files changed

+9604
-10317
lines changed

Some content is hidden

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

766 files changed

+9604
-10317
lines changed

src/licensedcode/match.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,10 @@ def get_mapping(
777777
else:
778778
matched_text = self.matched_text(whole_lines=False, highlight=False)
779779

780-
SCANCODE_BASE_URL = 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses'
781-
SCANCODE_LICENSE_TEXT_URL = SCANCODE_BASE_URL + '/{}.LICENSE'
782-
SCANCODE_LICENSE_DATA_URL = SCANCODE_BASE_URL + '/{}.yml'
780+
SCANCODE_DATA_BASE_URL = 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data'
781+
SCANCODE_LICENSE_URL = SCANCODE_DATA_BASE_URL + '/licenses/{}.LICENSE'
782+
SCANCODE_LICENSE_RULE_URL = SCANCODE_DATA_BASE_URL + '/licenses/{}'
783+
SCANCODE_RULE_URL = SCANCODE_DATA_BASE_URL + '/rules/{}'
783784

784785
result = {}
785786

@@ -794,6 +795,13 @@ def get_mapping(
794795
# LicenseDB Level Information (Rule that was matched)
795796
result['license_expression'] = self.rule.license_expression
796797
result['rule_identifier'] = self.rule.identifier
798+
if self.matcher == "1-spdx-id":
799+
result['rule_url'] = None
800+
elif self.rule.is_from_license:
801+
result['rule_url'] = SCANCODE_LICENSE_RULE_URL.format(self.rule.identifier)
802+
else:
803+
result['rule_url'] = SCANCODE_RULE_URL.format(self.rule.identifier)
804+
797805
result['referenced_filenames'] = self.rule.referenced_filenames
798806
result['is_license_text'] = self.rule.is_license_text
799807
result['is_license_notice'] = self.rule.is_license_notice
@@ -823,22 +831,21 @@ def get_mapping(
823831
detected_license['homepage_url'] = lic.homepage_url
824832
detected_license['text_url'] = lic.text_urls[0] if lic.text_urls else ''
825833
detected_license['reference_url'] = license_url_template.format(lic.key)
826-
detected_license['scancode_text_url'] = SCANCODE_LICENSE_TEXT_URL.format(lic.key)
827-
detected_license['scancode_data_url'] = SCANCODE_LICENSE_DATA_URL.format(lic.key)
834+
detected_license['scancode_url'] = SCANCODE_LICENSE_URL.format(lic.key)
828835

829836
spdx_key = lic.spdx_license_key
830837
detected_license['spdx_license_key'] = spdx_key
831838

832839
if spdx_key:
833840
is_license_ref = spdx_key.lower().startswith('licenseref-')
834841
if is_license_ref:
835-
spdx_url = SCANCODE_LICENSE_TEXT_URL.format(lic.key)
842+
spdx_url = SCANCODE_LICENSE_URL.format(lic.key)
836843
else:
837844
# TODO: Is this replacing spdx_key???
838845
spdx_key = lic.spdx_license_key.rstrip('+')
839846
spdx_url = spdx_license_url.format(spdx_key)
840847
else:
841-
spdx_url = ''
848+
spdx_url = None
842849
detected_license['spdx_url'] = spdx_url
843850

844851
return result

tests/cluecode/data/plugin_filter_clues/filtered-expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"matcher": "3-seq",
3838
"license_expression": "apache-1.1",
3939
"rule_identifier": "apache-1.1_63.RULE",
40+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-1.1_63.RULE",
4041
"referenced_filenames": [],
4142
"is_license_text": true,
4243
"is_license_notice": false,
@@ -57,8 +58,7 @@
5758
"homepage_url": "http://www.apache.org/licenses/",
5859
"text_url": "http://apache.org/licenses/LICENSE-1.1",
5960
"reference_url": "https://scancode-licensedb.aboutcode.org/apache-1.1",
60-
"scancode_text_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/apache-1.1.LICENSE",
61-
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/apache-1.1.yml",
61+
"scancode_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/apache-1.1.LICENSE",
6262
"spdx_license_key": "Apache-1.1",
6363
"spdx_url": "https://spdx.org/licenses/Apache-1.1"
6464
}

tests/cluecode/data/plugin_filter_clues/filtered-expected2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"matcher": "2-aho",
3838
"license_expression": "pygres-2.2",
3939
"rule_identifier": "pygres-2.2_2.RULE",
40+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/pygres-2.2_2.RULE",
4041
"referenced_filenames": [],
4142
"is_license_text": true,
4243
"is_license_notice": false,
@@ -57,8 +58,7 @@
5758
"homepage_url": null,
5859
"text_url": "http://shell.vex.net/viewvc.cgi/pygresql/trunk/module/pgmodule.c?view=markup&pathrev=431",
5960
"reference_url": "https://scancode-licensedb.aboutcode.org/pygres-2.2",
60-
"scancode_text_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pygres-2.2.LICENSE",
61-
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pygres-2.2.yml",
61+
"scancode_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pygres-2.2.LICENSE",
6262
"spdx_license_key": "LicenseRef-scancode-pygres-2.2",
6363
"spdx_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pygres-2.2.LICENSE"
6464
}

tests/cluecode/data/plugin_filter_clues/filtered-expected3.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"matcher": "1-hash",
3838
"license_expression": "pcre",
3939
"rule_identifier": "pcre.LICENSE",
40+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.LICENSE",
4041
"referenced_filenames": [],
4142
"is_license_text": true,
4243
"is_license_notice": false,
@@ -57,8 +58,7 @@
5758
"homepage_url": "http://www.pcre.org/licence.txt",
5859
"text_url": "http://www.pcre.org/licence.txt",
5960
"reference_url": "https://scancode-licensedb.aboutcode.org/pcre",
60-
"scancode_text_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.LICENSE",
61-
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.yml",
61+
"scancode_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.LICENSE",
6262
"spdx_license_key": "LicenseRef-scancode-pcre",
6363
"spdx_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/pcre.LICENSE"
6464
}

0 commit comments

Comments
 (0)