Skip to content

Commit 6a46119

Browse files
committed
Merge branch 'develop'
2 parents a25edcc + acff29a commit 6a46119

35 files changed

+822
-214
lines changed

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
1+
Copyright (c) 2013-2020 nexB Inc. http://www.nexb.com/ - All rights reserved.
22
Licensed under the Apache License, Version 2.0 (the "License");
33
you may not use this file except in compliance with the License.
44
You may obtain a copy of the License at

REFERENCE.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ gen
151151

152152
::
153153

154+
--android Generate MODULE_LICENSE_XXX (XXX will be
155+
replaced by license key) and NOTICE as the same
156+
design as from Android.
157+
154158
--fetch-license api_url api_key Fetch licenses data from DejaCode License
155159
Library and create <license>.LICENSE
156160
side-by-side with the generated .ABOUT file.
@@ -178,6 +182,17 @@ Options
178182

179183
::
180184

185+
--android
186+
187+
Create an empty file named `MODULE_LICENSE_XXX` where `XXX` is the license
188+
key and create a NOTICE file which these two files follow the design from
189+
Android Open Source Project.
190+
191+
The input **must** have the license key information as this is needed to
192+
create the empty MODULE_LICENSE_XXX
193+
194+
$ about gen --android LOCATION OUTPUT
195+
181196
--fetch-license
182197

183198
Fetch licenses text from a DejaCode API. and create <license>.LICENSE side-by-side
@@ -324,7 +339,7 @@ Options
324339
Show configuration file format help and exit.
325340
This option will print out examples of the the YAML configuration file.
326341
327-
Keys configuration are: `column_renamings`, `required_columns` and `column_filters`
342+
Keys configuration are: `field_renamings`, `required_fields` and `field_filters`
328343

329344
$ about transform --help-format
330345

@@ -335,5 +350,5 @@ Options
335350

336351
Special Notes
337352
=============
338-
When using the `column_filters` configuration, all the standard required columns
339-
(`about_resource` and `name`) and the user defined `required_columns` need to be included.
353+
When using the `field_filters` configuration, all the standard required columns
354+
(`about_resource` and `name`) and the user defined `required_fields` need to be included.

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: 4.0.2
3+
version: 5.0.0
44
author: Jillian Daguil, Chin Yeung Li, Philippe Ombredanne, Thomas Druez
55
copyright: Copyright (c) 2013-2020 nexB Inc.
66
description: |

docs/CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2020-08-11
2+
Release 5.0.0
3+
4+
* Enhance the `transform` to also work with JSON file
5+
* Update transform code (See #427 and #428)
6+
* Fixed #431 - Error handling for empty "_file" fields
7+
* Fixed #432 - Handled UTF-8 variant invented by Microsoft
8+
* Fixed #433 - problem was caused by the different multi-lic file format between json and CSV (CSV with '\n' line break)
9+
* Fixed #436 - issue about copy with the `--reference` option
10+
* Fixed #396 - support for alternative output for Android
11+
112
2020-05-05
213
Release 4.0.2
314

docs/UsingAboutCodetoDocumentYourSoftwareAssets.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,22 @@ A transform configuration file is used to describe which transformations and val
245245

246246
The attributes that can be set in a configuration file are:
247247

248-
* column_renamings:
248+
* field_renamings:
249249
An optional map of source CSV column name to target CSV new column name that
250250
is used to rename CSV columns.
251251

252252
For instance with this configuration the columns "Directory/Location" will be
253253
renamed to "about_resource" and "foo" to "bar":
254254

255-
column_renamings:
256-
'Directory/Location' : about_resource
257-
foo : bar
255+
field_renamings:
256+
about_resource : 'Directory/Location'
257+
bar : foo
258258

259259
The renaming is always applied first before other transforms and checks. All
260260
other column names referenced below are these that exist AFTER the renaming
261261
have been applied to the existing column names.
262262

263-
* required_columns:
263+
* required_fields:
264264
An optional list of required column names that must have a value, beyond the
265265
standard columns names. If a source CSV does not have such a column or a row is
266266
missing a value for a required column, an error is reported.
@@ -269,11 +269,11 @@ For instance with this configuration an error will be reported if the columns
269269
"name" and "version" are missing or if any row does not have a value set for
270270
these columns:
271271

272-
required_columns:
272+
required_fields:
273273
- name
274274
- version
275275

276-
* column_filters:
276+
* field_filters:
277277
An optional list of column names that should be kept in the transformed CSV. If
278278
this list is provided, all the columns from the source CSV that should be kept
279279
in the target CSV must be listed be even if they are standard or required
@@ -283,10 +283,24 @@ transformed target CSV.
283283
For instance with this configuration the target CSV will only contains the "name"
284284
and "version" columns and no other column:
285285

286-
column_filters:
286+
field_filters:
287287
- name
288288
- version
289289

290+
* exclude_fields:
291+
An optional list of field names that should be excluded in the transformed CSV/JSON. If
292+
this list is provided, all the fields from the source CSV/JSON that should be excluded
293+
in the target CSV/JSON must be listed. Excluding standard or required fields will cause
294+
an error. If this list is not provided, all source CSV/JSON fields are kept in the
295+
transformed target CSV/JSON.
296+
297+
For instance with this configuration the target CSV/JSON will not contain the "type"
298+
and "temp" fields:
299+
300+
exclude_fields:
301+
- type
302+
- temp
303+
290304

291305
## <a name="RungentoGenerateAboutCodeToolkitFiles">Run gen to Generate AboutCode Toolkit Files</a>
292306

-4.05 KB
Binary file not shown.

etc/scripts/irc-notify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def appveyor_vars():
139139
response = line.split()
140140

141141
if response[0] == 'PING':
142-
irc_file.send('PONG {}\r\n'.format(reponse[1]).encode())
142+
irc_file.send('PONG {}\r\n'.format(response[1]).encode())
143143

144144
elif response[1] == '433':
145145
irc_sock.send('NICK {}\r\n'.format(irc_nick).encode())

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def read(*names, **kwargs):
2424

2525
setup(
2626
name='aboutcode-toolkit',
27-
version='4.0.2',
27+
version='5.0.0',
2828
license='Apache-2.0',
2929
description=(
3030
'AboutCode-toolkit is a tool to document the provenance (origin and license) of '
@@ -69,7 +69,7 @@ def read(*names, **kwargs):
6969
install_requires=[
7070
'jinja2 >= 2.9, < 3.0',
7171

72-
'click >= 6.7, < 7.0',
72+
'click',
7373

7474
"backports.csv ; python_version<'3.6'",
7575

src/attributecode/__init__.py

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

3232
import saneyaml
3333

34-
__version__ = '4.0.2'
34+
__version__ = '5.0.0'
3535

3636
__about_spec_version__ = '3.1.4'
3737

src/attributecode/cmd.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2013-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2013-2020 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -46,7 +46,7 @@
4646

4747

4848
__copyright__ = """
49-
Copyright (c) 2013-2019 nexB Inc and others. All rights reserved.
49+
Copyright (c) 2013-2020 nexB Inc and others. All rights reserved.
5050
Licensed under the Apache License, Version 2.0 (the "License");
5151
you may not use this file except in compliance with the License.
5252
You may obtain a copy of the License at
@@ -210,6 +210,11 @@ def inventory(location, output, format, quiet, verbose): # NOQA
210210
metavar='OUTPUT',
211211
type=click.Path(exists=True, file_okay=False, writable=True, resolve_path=True))
212212

213+
@click.option('--android',
214+
is_flag=True,
215+
help='Generate MODULE_LICENSE_XXX (XXX will be replaced by license key) and NOTICE '
216+
'as the same design as from Android.')
217+
213218
# FIXME: the CLI UX should be improved with two separate options for API key and URL
214219
@click.option('--fetch-license',
215220
nargs=2,
@@ -233,7 +238,7 @@ def inventory(location, output, format, quiet, verbose): # NOQA
233238

234239
@click.help_option('-h', '--help')
235240

236-
def gen(location, output, fetch_license, reference, quiet, verbose):
241+
def gen(location, output, android, fetch_license, reference, quiet, verbose):
237242
"""
238243
Generate .ABOUT files in OUTPUT from an inventory of .ABOUT files at LOCATION.
239244
@@ -245,12 +250,14 @@ def gen(location, output, fetch_license, reference, quiet, verbose):
245250
print_version()
246251
click.echo('Generating .ABOUT files...')
247252

253+
#FIXME: This should be checked in the `click`
248254
if not location.endswith(('.csv', '.json',)):
249255
raise click.UsageError('ERROR: Invalid input file extension: must be one .csv or .json.')
250256

251257
errors, abouts = generate_about_files(
252258
location=location,
253259
base_dir=output,
260+
android=android,
254261
reference_dir=reference,
255262
fetch_license=fetch_license,
256263
)
@@ -401,17 +408,17 @@ def print_config_help(ctx, param, value):
401408

402409

403410
@about.command(cls=AboutCommand,
404-
short_help='Transform a CSV by applying renamings, filters and checks.')
411+
short_help='Transform a CSV/JSON by applying renamings, filters and checks.')
405412

406413
@click.argument('location',
407414
required=True,
408-
callback=partial(validate_extensions, extensions=('.csv',)),
415+
callback=partial(validate_extensions, extensions=('.csv', '.json',)),
409416
metavar='LOCATION',
410417
type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True))
411418

412419
@click.argument('output',
413420
required=True,
414-
callback=partial(validate_extensions, extensions=('.csv',)),
421+
callback=partial(validate_extensions, extensions=('.csv', '.json',)),
415422
metavar='OUTPUT',
416423
type=click.Path(exists=False, dir_okay=False, writable=True, resolve_path=True))
417424

@@ -438,30 +445,39 @@ def print_config_help(ctx, param, value):
438445

439446
def transform(location, output, configuration, quiet, verbose): # NOQA
440447
"""
441-
Transform the CSV file at LOCATION by applying renamings, filters and checks
442-
and write a new CSV to OUTPUT.
448+
Transform the CSV/JSON file at LOCATION by applying renamings, filters and checks
449+
and write a new CSV/JSON to OUTPUT.
443450
444-
LOCATION: Path to a CSV file.
451+
LOCATION: Path to a CSV/JSON file.
445452
446-
OUTPUT: Path to CSV inventory file to create.
453+
OUTPUT: Path to CSV/JSON inventory file to create.
447454
"""
448455
from attributecode.transform import transform_csv_to_csv
456+
from attributecode.transform import transform_json_to_json
449457
from attributecode.transform import Transformer
450458

451-
if not quiet:
452-
print_version()
453-
click.echo('Transforming CSV...')
454459

455460
if not configuration:
456461
transformer = Transformer.default()
457462
else:
458463
transformer = Transformer.from_file(configuration)
459464

460-
errors = transform_csv_to_csv(location, output, transformer)
465+
if location.endswith('.csv') and output.endswith('.csv'):
466+
errors = transform_csv_to_csv(location, output, transformer)
467+
elif location.endswith('.json') and output.endswith('.json'):
468+
errors = transform_json_to_json(location, output, transformer)
469+
else:
470+
msg = 'Extension for the input and output need to be the same.'
471+
click.echo(msg)
472+
sys.exit()
473+
474+
if not quiet:
475+
print_version()
476+
click.echo('Transforming...')
461477

462478
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
463479
if not quiet and not errors:
464-
msg = 'Transformed CSV written to {output}.'.format(**locals())
480+
msg = 'Transformed file written to {output}.'.format(**locals())
465481
click.echo(msg)
466482
sys.exit(errors_count)
467483

0 commit comments

Comments
 (0)