From 7a296eb5d760264e2624617824d38aee40daf644 Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 19:01:40 +0900 Subject: [PATCH 1/3] Add implementation and testing for new CLI-option Option: '--format-html' --- piplicenses.py | 21 +++++++++++++++++---- test_piplicenses.py | 12 +++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/piplicenses.py b/piplicenses.py index 8f001f3..46075cd 100644 --- a/piplicenses.py +++ b/piplicenses.py @@ -188,6 +188,17 @@ def get_sortby(args): return 'Name' +def create_output_string(args): + table = create_licenses_table(args) + output_fields = get_output_fields(args) + sortby = get_sortby(args) + + if args.format_html: + return table.get_html_string(fields=output_fields, sortby=sortby) + else: + return table.get_string(fields=output_fields, sortby=sortby) + + def create_parser(): parser = argparse.ArgumentParser( description=__summary__) @@ -229,6 +240,10 @@ def create_parser(): action='store_true', default=False, help='dump as reST style') + parser.add_argument('--format-html', + action='store_true', + default=False, + help='dump as html style') return parser @@ -237,10 +252,8 @@ def main(): # pragma: no cover parser = create_parser() args = parser.parse_args() - table = create_licenses_table(args) - output_fields = get_output_fields(args) - sortby = get_sortby(args) - print(table.get_string(fields=output_fields, sortby=sortby)) + output_string = create_output_string(args) + print(output_string) if __name__ == '__main__': # pragma: no cover diff --git a/test_piplicenses.py b/test_piplicenses.py index 38b1010..7b58b31 100644 --- a/test_piplicenses.py +++ b/test_piplicenses.py @@ -8,7 +8,7 @@ from piplicenses import (__pkgname__, create_parser, create_licenses_table, get_output_fields, get_sortby, factory_styled_table_with_args, - find_license_from_classifier, + find_license_from_classifier, create_output_string, DEFAULT_OUTPUT_FIELDS, SYSTEM_PACKAGES, LICENSE_UNKNOWN) @@ -70,6 +70,9 @@ def test_with_empty_args(self): sortby = get_sortby(args) self.assertEquals('Name', sortby) + output_string = create_output_string(args) + self.assertNotIn('', output_string) + def test_from_classifier(self): from_classifier_args = ['--from-classifier'] args = self.parser.parse_args(from_classifier_args) @@ -192,5 +195,12 @@ def test_format_rst(self): self.assertEquals('+', table.junction_char) self.assertEquals(RULE_ALL, table.hrules) + def test_format_html(self): + format_html_args = ['--format-html'] + args = self.parser.parse_args(format_html_args) + output_string = create_output_string(args) + + self.assertIn('
', output_string) + def tearDown(self): pass From f2401659e071e038b5304b949b505aaa726be360 Mon Sep 17 00:00:00 2001 From: raimon Date: Sun, 11 Feb 2018 19:03:56 +0900 Subject: [PATCH 2/3] Add section of '--format-html' option in README --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 2d01701..f0dc8c4 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Dump the software license list of Python packages installed with pip. * [Option: order](#option-order) * [Option: format\-markdown](#option-format-markdown) * [Option: format\-rst](#option-format-rst) + * [Option: format\-html](#option-format-html) * [More Information](#more-information) * [License](#license) * [Dependencies](#dependencies) @@ -178,6 +179,31 @@ When executed with the `--format-rst` option, you can output list in "[Grid tabl +--------+---------+---------+ ``` +### Option: format-html + +When executed with the `--format-html` option, you can output list in HTML table format. + +```bash +(venv) $ pip-licenses --format-html +
+ + + + + + + + + + + + + + + +
NameVersionLicense
Django2.0.2BSD
pytz2017.3MIT
+``` + ### More Information Other, please make sure to execute the `--help` option. From a67903729a2ace0ab78145c6119d68c81d846a9d Mon Sep 17 00:00:00 2001 From: raimon Date: Sun, 11 Feb 2018 19:07:13 +0900 Subject: [PATCH 3/3] Bump version to 1.6.0 --- CHANGELOG.md | 4 ++++ piplicenses.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a0f484..f52d9ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### 1.6.0 + +* Implement new option `--format-html` + ### 1.5.0 * Implement new option `--format-rst` diff --git a/piplicenses.py b/piplicenses.py index 46075cd..e3772c2 100644 --- a/piplicenses.py +++ b/piplicenses.py @@ -38,7 +38,7 @@ from prettytable.prettytable import HEADER as RULE_HEADER, ALL as RULE_ALL __pkgname__ = 'pip-licenses' -__version__ = '1.5.0' +__version__ = '1.6.0' __author__ = 'raimon' __license__ = 'MIT License' __summary__ = ('Dump the software license list of '