Skip to content

Commit a35a8ce

Browse files
committed
Fixed #511 - Improve check performance
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent a05078d commit a35a8ce

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
==============================
22
Changelog
33
==============================
4-
2022-08-23
5-
Release 7.0.3
4+
2022-09-21
5+
Release 7.1.0
66

7-
* Fixed version mismatch in v7.0.2 (https://github.com/nexB/aboutcode-toolkit/issues/510)
7+
* Fixed version mismatch (https://github.com/nexB/aboutcode-toolkit/issues/510)
8+
* Improve `check` performance (https://github.com/nexB/aboutcode-toolkit/issues/511)
89

910

1011
2022-03-21

about.ABOUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
about_resource: .
22
name: AboutCode-toolkit
3-
version: 7.0.3
3+
version: 7.1.0
44
author: Jillian Daguil, Chin Yeung Li, Philippe Ombredanne, Thomas Druez
55
copyright: Copyright (c) nexB Inc.
66
description: |

src/attributecode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import saneyaml
2222

23-
__version__ = '7.0.3'
23+
__version__ = '7.1.0'
2424

2525
__about_spec_version__ = '3.2.3'
2626

src/attributecode/cmd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def gen_license(location, output, djc, scancode, verbose):
351351
if not key in lic_dict_output:
352352
lic_filename = license_dict[key][1]
353353
lic_context = license_dict[key][2]
354-
lic_dict_output[lic_filename] = lic_context
354+
lic_dict_output[lic_filename] = lic_context
355355

356356
write_errors = write_licenses(lic_dict_output, output)
357357
if write_errors:
@@ -419,7 +419,7 @@ def validate_template(ctx, param, value):
419419
@click.option('--reference',
420420
metavar='DIR',
421421
type=click.Path(exists=True, file_okay=False, readable=True, resolve_path=True),
422-
help='Path to a directory with reference files where "license_file" and/or "notice_file"'
422+
help='Path to a directory with reference files where "license_file" and/or "notice_file"'
423423
' located.')
424424

425425
@click.option('--template',
@@ -710,7 +710,8 @@ def check(location, djc, log, verbose):
710710
errors, abouts = collect_inventory(location)
711711

712712
# Validate license_expression
713-
_key_text_dict, errs = pre_process_and_fetch_license_dict(abouts, api_url, api_key)
713+
from_check = True
714+
_key_text_dict, errs = pre_process_and_fetch_license_dict(abouts, from_check, api_url, api_key)
714715
for e in errs:
715716
errors.append(e)
716717

src/attributecode/model.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ def save_as_excel(location, about_dicts):
16431643
formatted_list = util.format_about_dict_output(about_dicts)
16441644
write_excel(location, formatted_list)
16451645

1646-
def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scancode=False, reference=None):
1646+
def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, api_key=None, scancode=False, reference=None):
16471647
"""
16481648
Return a dictionary containing the license information (key, name, text, url)
16491649
fetched from the ScanCode LicenseDB or DejaCode API.
@@ -1710,9 +1710,13 @@ def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scanc
17101710
if msg == "Invalid '--api_url'. License generation is skipped.":
17111711
errors.extend(errs)
17121712
return key_text_dict, errors
1713-
for severity, message in errs:
1713+
for severity, message in errs:
17141714
msg = (about.about_file_path + ": " + message)
17151715
errors.append(Error(severity, msg))
1716+
# We don't want to actually get the license information from the
1717+
# check utility
1718+
if from_check:
1719+
continue
17161720
if not license_data:
17171721
continue
17181722
license_name = license_data.get('short_name', '')
@@ -1725,6 +1729,10 @@ def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scanc
17251729
license_text_url = url + lic_key + '.LICENSE'
17261730
try:
17271731
json_url = urlopen(license_url)
1732+
# We don't want to actually get the license information from the
1733+
# check utility
1734+
if from_check:
1735+
continue
17281736
data = json.loads(json_url.read())
17291737
license_name = data['short_name']
17301738
license_text = urllib.request.urlopen(license_text_url).read().decode('utf-8')
@@ -1738,12 +1746,13 @@ def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scanc
17381746
msg = u"Invalid 'license': " + lic_key
17391747
errors.append(Error(ERROR, msg))
17401748
continue
1741-
detail_list.append(license_name)
1742-
detail_list.append(license_filename)
1743-
detail_list.append(license_text)
1744-
detail_list.append(lic_url)
1745-
detail_list.append(spdx_license_key)
1746-
key_text_dict[lic_key] = detail_list
1749+
if not from_check:
1750+
detail_list.append(license_name)
1751+
detail_list.append(license_filename)
1752+
detail_list.append(license_text)
1753+
detail_list.append(lic_url)
1754+
detail_list.append(spdx_license_key)
1755+
key_text_dict[lic_key] = detail_list
17471756
if not about.license_key.value:
17481757
about.license_key.value = lic_list
17491758

0 commit comments

Comments
 (0)