Skip to content

Commit 6fe7856

Browse files
committed
Fixed #534 - fixed licenses group issue
* update changelog and reference.rst Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 27b3068 commit 6fe7856

File tree

7 files changed

+211
-53
lines changed

7 files changed

+211
-53
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
Changelog
33

44
2023-xx-xx
5-
Release 10.0.1
5+
Release 10.1.0
66

77
* Fixed `transform` with nested list #531
88
* Added curl dependency in Dockerfile #532
99
* Introduce spdx_license_expression
1010
* Ability to transform spdx license key from spdx_license_expression to
11-
license_expression
11+
license_expression (i.e. Generate attribution with
12+
spdx_license_expression) #513
13+
* Ability to configure the proxy settings #533
14+
* Fixed licenses issue #534
1215

1316
2023-08-20
1417
Release 10.0.0

docs/source/reference.rst

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Options
8383
Purpose
8484
-------
8585

86-
Generate an attribution file which contains license information
87-
from the INPUT along with the license text.
86+
Generate an attribution file which contains license information from the INPUT
87+
along with the license text.
8888

8989
Assume the following:
9090

@@ -421,6 +421,60 @@ Details
421421
This option tells the tool to show all errors found.
422422
The default behavior will only show 'CRITICAL', 'ERROR', and 'WARNING'
423423
424+
Special Notes
425+
-------------
426+
If the input contains values for license_file, the tool will attempt to
427+
associate the license_file with the corresponding license_key.
428+
429+
sample.csv
430+
431+
+----------------+------+---------------------+--------------+
432+
| about_resource | name | license_expression | license_file |
433+
+================+======+=====================+==============+
434+
| /project/test.c| test.c | mit AND custom | custom.txt |
435+
+----------------+------+---------------------+--------------+
436+
437+
If the user does not utilize the **--fetch-license** option, the input will
438+
contain two license keys and one license file. In this scenario, the tool cannot
439+
determine which license key the license file is referencing. As a result, the
440+
license_file will be saved separately.
441+
442+
i.e.
443+
444+
.. code-block:: none
445+
446+
about_resource: test.c
447+
name: test.c
448+
license_expression: mit AND custom
449+
licenses:
450+
- key: mit
451+
name: mit
452+
- key: custom
453+
name: custom
454+
- file: custom.txt
455+
456+
On the other hand, if the user generates ABOUT files using the
457+
**--fetch-license** option, the MIT license will be retrieved. This will result
458+
in having one license key and one license file. In such cases, the tool will
459+
consider it a successful match.
460+
461+
i.e.
462+
463+
.. code-block:: none
464+
465+
about_resource: test.c
466+
name: test.c
467+
license_expression: mit AND custom
468+
licenses:
469+
- key: mit
470+
name: MIT License
471+
file: mit.LICENSE
472+
url: https://scancode-licensedb.aboutcode.org/mit.LICENSE
473+
spdx_license_key: MIT
474+
- key: custom
475+
name: custom
476+
file: custom.txt
477+
424478
gen_license
425479
===========
426480

@@ -780,3 +834,20 @@ version 32.0.0 or later. If you are using an earlier version of Scancode Toolkit
780834
specifically version 31 or older, it will only be compatible with prior versions
781835
of AboutCode Toolkit.
782836

837+
838+
Configure proxy
839+
---------------
840+
The `requests` library is used since AboutCode Toolkit version 10.1.0. To do the
841+
http request, users can set the standard environment variables **http_proxy**,
842+
**https_proxy**, **no_proxy**, **all_proxy** with the export statement
843+
844+
i.e.
845+
846+
.. code-block:: none
847+
848+
$ export HTTP_PROXY="http://10.10.1.10:3128"
849+
$ export HTTPS_PROXY="http://10.10.1.10:1080"
850+
$ export ALL_PROXY="socks5://10.10.1.10:3434"
851+
852+
See https://requests.readthedocs.io/en/latest/user/advanced/#proxies for
853+
references

src/attributecode/attrib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def generate_and_save(abouts, is_about_input, license_dict, output_location, sca
323323
)
324324

325325
if rendering_error:
326-
errors.extend(rendering_error)
326+
errors.append(rendering_error)
327327

328328
if rendered:
329329
output_location = add_unc(output_location)

src/attributecode/model.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,13 @@ def dumps(self, licenses_dict=None):
12241224
else:
12251225
if field.value:
12261226
data[field.name] = field.value
1227+
# If there is no license_key value, parse the license_expression
1228+
# and get the parsed license key
1229+
if 'license_expression' in data:
1230+
if not license_key and data['license_expression']:
1231+
_spec_char, lic_list = parse_license_expression(
1232+
data['license_expression'])
1233+
license_key = lic_list
12271234

12281235
# Group the same license information in a list
12291236
# This `licenses_dict` is a dictionary with license key as the key and the
@@ -1246,20 +1253,35 @@ def dumps(self, licenses_dict=None):
12461253
lic_dict['spdx_license_key'] = spdx_lic_key
12471254

12481255
# Remove the license information if it has been handled
1249-
lic_key_copy.remove(lic_key)
1250-
if lic_name in license_name:
1251-
license_name.remove(lic_name)
1252-
if lic_url in license_url:
1253-
license_url.remove(lic_url)
1254-
if lic_filename in license_file:
1255-
license_file.remove(lic_filename)
1256-
if spdx_lic_key in spdx_license_key:
1257-
spdx_license_key.remove(spdx_lic_key)
1258-
lic_dict_list.append(lic_dict)
1256+
# The following condition is to check if license information
1257+
# has been fetched, the license key is invalid or custom if
1258+
# no value for lic_name
1259+
if lic_name:
1260+
lic_key_copy.remove(lic_key)
1261+
if lic_name in license_name:
1262+
license_name.remove(lic_name)
1263+
if lic_url in license_url:
1264+
license_url.remove(lic_url)
1265+
if lic_filename in license_file:
1266+
license_file.remove(lic_filename)
1267+
if spdx_lic_key in spdx_license_key:
1268+
spdx_license_key.remove(spdx_lic_key)
1269+
lic_dict_list.append(lic_dict)
12591270

12601271
# Handle license information that have not been handled.
1261-
license_group = list(zip_longest(
1262-
lic_key_copy, license_name, license_file, license_url, spdx_license_key))
1272+
# If the len of the lic_key is the same as the lic_file, the tool should
1273+
# assume the lic_file (custom license) is referring this specific lic_key
1274+
# otherwise, the tool shouldn't group them
1275+
if len(lic_key_copy) == len(license_file):
1276+
license_group = list(zip_longest(
1277+
lic_key_copy, license_name, license_file, license_url, spdx_license_key))
1278+
else:
1279+
license_group = list(zip_longest(
1280+
lic_key_copy, license_name, [], license_url, spdx_license_key))
1281+
# Add the unhandled_lic_file if any
1282+
if license_file:
1283+
for lic_file in license_file:
1284+
license_group.append((None, None, lic_file, None, None))
12631285

12641286
for lic_group in license_group:
12651287
lic_dict = {}
@@ -1280,15 +1302,15 @@ def dumps(self, licenses_dict=None):
12801302
lic_dict_list.append(lic_dict)
12811303

12821304
# Format the license information in the same order of the license expression
1283-
if license_key:
1284-
for key in license_key:
1285-
for lic_dict in lic_dict_list:
1286-
if key == lic_dict['key']:
1287-
data.setdefault('licenses', []).append(lic_dict)
1288-
break
1289-
else:
1305+
for key in license_key:
12901306
for lic_dict in lic_dict_list:
1291-
data.setdefault('licenses', []).append(lic_dict)
1307+
if key == lic_dict['key']:
1308+
data.setdefault('licenses', []).append(lic_dict)
1309+
lic_dict_list.remove(lic_dict)
1310+
break
1311+
1312+
for lic_dict in lic_dict_list:
1313+
data.setdefault('licenses', []).append(lic_dict)
12921314

12931315
return saneyaml.dump(data)
12941316

0 commit comments

Comments
 (0)