Skip to content

Commit 9c0cd59

Browse files
committed
Potential release of 7.2.1
* stripped empty newline/spaces for about_resource * catch invalid license_expression Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 3d1d18e commit 9c0cd59

File tree

8 files changed

+161
-61
lines changed

8 files changed

+161
-61
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Changelog
66
* Fix the syntax for setup's python_requires since newer version of
77
setuptools (with newer packaging) versions do not accept star in the
88
Python version spec.
9+
* Stipped empty newline/spaces for about_resource fields
10+
* Catch invalid license_expression
911

1012

1113
2022-10-24

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.2.0
3+
version: 7.2.1
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.2.0'
23+
__version__ = '7.2.1'
2424

2525
__about_spec_version__ = '3.2.3'
2626

src/attributecode/attrib.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
DEFAULT_LICENSE_SCORE = 100
4141

42+
4243
def generate(abouts, is_about_input, license_dict, scancode, min_license_score, template=None, vartext=None):
4344
"""
4445
Generate an attribution text from an `abouts` list of About objects, a
@@ -55,7 +56,8 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
5556
lineno, message = template_error
5657
error = Error(
5758
CRITICAL,
58-
'Template validation error at line: {lineno}: "{message}"'.format(**locals())
59+
'Template validation error at line: {lineno}: "{message}"'.format(
60+
**locals())
5961
)
6062
errors.append(error)
6163
return error, None
@@ -87,10 +89,11 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
8789
filename = list(about.license_file.value.keys())[index]
8890
text = list(about.license_file.value.values())[index]
8991
else:
90-
error = Error(CRITICAL, 'No license file found for ' + name)
92+
error = Error(
93+
CRITICAL, 'No license file found for ' + name)
9194
errors.append(error)
9295
break
93-
if about.license_url.value:
96+
if about.license_url.value:
9497
url = about.license_url.value[index]
9598
else:
9699
url = ''
@@ -106,7 +109,6 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
106109
license_object = License(key, name, filename, url, text)
107110
licenses_list.append(license_object)
108111

109-
110112
# We need special treatment for scancode input.
111113
# Each about_object may have duplicated license key and same/different license score
112114
# We will only keep the unique license key with the highest license score.
@@ -145,14 +147,18 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
145147
current_score = lic_score[index]
146148
if current_score > previous_score:
147149
if matched_text_exist:
148-
updated_dict[key] = (lic_score[index], lic_name[index], matched_text[index])
150+
updated_dict[key] = (
151+
lic_score[index], lic_name[index], matched_text[index])
149152
else:
150-
updated_dict[key] = (lic_score[index], lic_name[index])
153+
updated_dict[key] = (
154+
lic_score[index], lic_name[index])
151155
else:
152156
if matched_text_exist:
153-
updated_dict[key] = (lic_score[index], lic_name[index], matched_text[index])
157+
updated_dict[key] = (
158+
lic_score[index], lic_name[index], matched_text[index])
154159
else:
155-
updated_dict[key] = (lic_score[index], lic_name[index])
160+
updated_dict[key] = (
161+
lic_score[index], lic_name[index])
156162
index = index + 1
157163
updated_lic_key = []
158164
updated_lic_name = []
@@ -200,7 +206,8 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
200206
lic_name_expression = ' '.join(lic_name_expression_list)
201207

202208
# Add the license name expression string into the about object as a custom field
203-
custom_field = StringField(name='license_name_expression', value=lic_name_expression, present=True)
209+
custom_field = StringField(
210+
name='license_name_expression', value=lic_name_expression, present=True)
204211
setattr(about, 'license_name_expression', custom_field)
205212

206213
# Sort the about objects by name
@@ -219,6 +226,7 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
219226

220227
return errors, rendered
221228

229+
222230
def get_license_file_key(license_text_name):
223231
if license_text_name.endswith('.LICENSE'):
224232
# See https://github.com/nexB/aboutcode-toolkit/issues/439
@@ -274,11 +282,16 @@ def generate_and_save(abouts, is_about_input, license_dict, output_location, sca
274282
for about in abouts:
275283
if not about.license_expression.value:
276284
continue
277-
special_char_in_expression, lic_list = parse_license_expression(about.license_expression.value)
285+
special_char_in_expression, lic_list, invalid_lic_exp = parse_license_expression(
286+
about.license_expression.value)
278287
if special_char_in_expression:
279288
msg = (u"The following character(s) cannot be in the license_expression: " +
280289
str(special_char_in_expression))
281290
errors.append(Error(ERROR, msg))
291+
if invalid_lic_exp:
292+
msg = (about.about_file_path + u": The following license_expression is invalid: " +
293+
invalid_lic_exp)
294+
errors.append(Error(ERROR, msg))
282295
rendering_error, rendered = generate_from_file(
283296
abouts,
284297
is_about_input,

src/attributecode/gen.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from attributecode.util import UNC_PREFIX_POSIX
3737
from attributecode.util import unique
3838
from attributecode.util import load_scancode_json, load_csv, load_json, load_excel
39+
from attributecode.util import strip_inventory_value
3940

4041

4142
def check_duplicated_columns(location):
@@ -131,6 +132,7 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
131132
"""
132133
errors = []
133134
abouts = []
135+
is_spreadsheet = False
134136

135137
if base_dir:
136138
base_dir = util.to_posix(base_dir)
@@ -143,8 +145,10 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
143145
errors.extend(dup_cols_err)
144146
return errors, abouts
145147
inventory = load_csv(location)
148+
is_spreadsheet = True
146149
elif location.endswith('.xlsx'):
147150
dup_cols_err, inventory = load_excel(location)
151+
is_spreadsheet = True
148152
if dup_cols_err:
149153
errors.extend(dup_cols_err)
150154
return errors, abouts
@@ -154,7 +158,14 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
154158
try:
155159
arp_list = []
156160
errors = []
157-
for component in inventory:
161+
162+
if is_spreadsheet:
163+
# Only the .csv and .xlsx may have newline issue
164+
stripped_inv = strip_inventory_value(inventory)
165+
else:
166+
stripped_inv = inventory
167+
168+
for component in stripped_inv:
158169
if not from_attrib:
159170
arp = component['about_resource']
160171
dup_err = check_duplicated_about_resource(arp, arp_list)
@@ -174,13 +185,15 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
174185
if errors:
175186
return errors, abouts
176187
except Exception as e:
188+
print("!!!!!!!!!!!!!!!!")
189+
print(str(e))
177190
# TODO: why catch ALL Exception
178191
msg = "The essential field 'about_resource' is not found in the <input>"
179192
errors.append(Error(CRITICAL, msg))
180193
return errors, abouts
181194

182195
custom_fields_list = []
183-
for fields in inventory:
196+
for fields in stripped_inv:
184197
# check does the input contains the required fields
185198
required_fields = model.About.required_fields
186199

0 commit comments

Comments
 (0)