From 68bf05ef7747ace1cf66f8193ba24b32e74f366a Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 15:53:46 +0900 Subject: [PATCH 1/8] Add implementation and testing for new CLI-option Option: '--format-rst' --- piplicenses.py | 12 +++++++++--- test_piplicenses.py | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/piplicenses.py b/piplicenses.py index 123be5b..88a0229 100644 --- a/piplicenses.py +++ b/piplicenses.py @@ -35,7 +35,7 @@ import pip from prettytable import PrettyTable -from prettytable.prettytable import HEADER as RULE_HEADER +from prettytable.prettytable import HEADER as RULE_HEADER, ALL as RULE_ALL __pkgname__ = 'pip-licenses' __version__ = '1.4.0' @@ -140,13 +140,15 @@ def factory_styled_table_with_args(args): table = PrettyTable() table.field_names = FIELD_NAMES table.align = 'l' - table.border = args.format_markdown + table.border = (args.format_markdown or args.format_rst) table.header = True if args.format_markdown: - table.border = True table.junction_char = '|' table.hrules = RULE_HEADER + elif args.format_rst: + table.junction_char = '+' + table.hrules = RULE_ALL return table @@ -223,6 +225,10 @@ def create_parser(): action='store_true', default=False, help='dump as markdown style') + parser.add_argument('-r', '--format-rst', + action='store_true', + default=False, + help='dump as reST style') return parser diff --git a/test_piplicenses.py b/test_piplicenses.py index 941d486..38b1010 100644 --- a/test_piplicenses.py +++ b/test_piplicenses.py @@ -3,8 +3,8 @@ import unittest from email import message_from_string -from prettytable.prettytable import (HEADER as RULE_HEADER, - FRAME as RULE_FRAME) +from prettytable.prettytable import (FRAME as RULE_FRAME, ALL as RULE_ALL, + HEADER as RULE_HEADER) from piplicenses import (__pkgname__, create_parser, create_licenses_table, get_output_fields, get_sortby, factory_styled_table_with_args, @@ -181,5 +181,16 @@ def test_format_markdown(self): self.assertEquals('|', table.junction_char) self.assertEquals(RULE_HEADER, table.hrules) + def test_format_rst(self): + format_rst_args = ['--format-rst'] + args = self.parser.parse_args(format_rst_args) + table = factory_styled_table_with_args(args) + + self.assertIn('l', table.align.values()) + self.assertTrue(table.border) + self.assertTrue(table.header) + self.assertEquals('+', table.junction_char) + self.assertEquals(RULE_ALL, table.hrules) + def tearDown(self): pass From f279db55864c5f6f889f8b8c8c39833de77702fa Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 16:15:04 +0900 Subject: [PATCH 2/8] Add section of '--format-rst' option in README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index d2e30e9..f904582 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,21 @@ When inserted in a markdown document, it is rendered as follows: | Django | 2.0.2 | BSD | | pytz | 2017.3 | MIT | +### --format-rst + +When executed with the `--format-rst` option, you can output list in "[Grid tables](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables)" of reStructuredText format. + +```bash +(venv) $ pip-licenses --format-rst ++--------+---------+---------+ +| Name | Version | License | ++--------+---------+---------+ +| Django | 2.0.2 | BSD | ++--------+---------+---------+ +| pytz | 2017.3 | MIT | ++--------+---------+---------+ +``` + ### More Information Other, please make sure to execute the `--help` option. From 6a7de2a7e764479c58c35929880d326df67eaa40 Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 16:30:17 +0900 Subject: [PATCH 3/8] Add prefix 'Option: ' in header of CLI-option --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f904582..458a4fc 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ Dump the software license list of Python packages installed with pip. * [Installation](#installation) * [Usage](#usage) * [Command\-Line Options](#command-line-options) - * [\-\-from\-classifier](#--from-classifier) - * [\-\-with\-system](#--with-system) - * [\-\-with\-authors](#--with-authors) - * [\-\-with\-urls](#--with-urls) - * [\-\-ignore\-packages](#--ignore-packages) - * [\-\-order](#--order) - * [\-\-format\-markdown](#--format-markdown) + * [Option: \-\-from\-classifier](#option---from-classifier) + * [Option: \-\-with\-system](#option---with-system) + * [Option: \-\-with\-authors](#option---with-authors) + * [Option: \-\-with\-urls](#option---with-urls) + * [Option: \-\-ignore\-packages](#option---ignore-packages) + * [Option: \-\-order](#option---order) + * [Option: \-\-format\-markdown](#option---format-markdown) + * [Option: \-\-format\-rst](#option---format-rst) * [More Information](#more-information) * [License](#license) * [Dependencies](#dependencies) @@ -54,7 +55,7 @@ Execute the command with your venv (or virtualenv) environment. ## Command-Line Options -### --from-classifier +### Option: --from-classifier By default, this tool finds the license from package Metadata. However, depending on the type of package, it does not declare a license only in the Classifiers. @@ -73,7 +74,7 @@ If you want to refer to the license declared in Classifiers, use the `--from-cla setuptools 38.5.0 MIT License ``` -### --with-system +### Option: --with-system By default, system packages such as `pip` and `setuptools` are ignored. @@ -90,7 +91,7 @@ If you want to output all including system package, use the `--with-system` opti setuptools 38.5.0 UNKNOWN ``` -### --with-authors +### Option: --with-authors When executed with the `--with-authors` option, output with author of the package. @@ -101,7 +102,7 @@ When executed with the `--with-authors` option, output with author of the packag pytz 2017.3 MIT Stuart Bishop ``` -### --with-urls +### Option: --with-urls For packages without Metadata, the license is output as `UNKNOWN`. To get more package information, use the `--with-urls` option. @@ -112,7 +113,7 @@ For packages without Metadata, the license is output as `UNKNOWN`. To get more p pytz 2017.3 MIT http://pythonhosted.org/pytz ``` -### --ignore-packages +### Option: --ignore-packages When executed with the `--ignore-packages` option, ignore the package specified by argument from list output. @@ -132,7 +133,7 @@ Package names of arguments can be separated by spaces. setuptools 38.5.0 UNKNOWN ``` -### --order +### Option: --order By default, it is ordered by package name. @@ -142,7 +143,7 @@ If you give arguments to the `--order option`, you can output in other sorted or (venv) $ pip-licenses --order=license ``` -### --format-markdown +### Option: --format-markdown When executed with the `--format-markdown` option, you can output list in markdown format. @@ -161,7 +162,7 @@ When inserted in a markdown document, it is rendered as follows: | Django | 2.0.2 | BSD | | pytz | 2017.3 | MIT | -### --format-rst +### Option: --format-rst When executed with the `--format-rst` option, you can output list in "[Grid tables](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables)" of reStructuredText format. From 29c65f0564c01813c2783ec1c9b594a6cfcda1a2 Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 16:50:11 +0900 Subject: [PATCH 4/8] Add a option of '--upgrade' to pip install command --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 458a4fc..7f0af8e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ https://getcomposer.org/doc/03-cli.md#licenses Install it via PyPI using `pip` command. ```bash -$ pip install pip-licenses +# Install or Upgrade to newest available version +$ pip -U install pip-licenses ``` ## Usage From 4143cf8eb32b0ff93ce1291fa933b40513142bc9 Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 16:51:25 +0900 Subject: [PATCH 5/8] Move position of upgrade option --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f0af8e..a7e5d25 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Install it via PyPI using `pip` command. ```bash # Install or Upgrade to newest available version -$ pip -U install pip-licenses +$ pip install -U pip-licenses ``` ## Usage From b5657f71a7dbf4fc2d3a0c66323a92872d36dcae Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 18:18:19 +0900 Subject: [PATCH 6/8] Bump version to 1.5.0 --- piplicenses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piplicenses.py b/piplicenses.py index 88a0229..8f001f3 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.4.0' +__version__ = '1.5.0' __author__ = 'raimon' __license__ = 'MIT License' __summary__ = ('Dump the software license list of ' From 76e176c1cf85a62e6cb0ec00ed104ef196a5484b Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 18:22:12 +0900 Subject: [PATCH 7/8] Use more simply internal link to header --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a7e5d25..2d01701 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ Dump the software license list of Python packages installed with pip. * [Installation](#installation) * [Usage](#usage) * [Command\-Line Options](#command-line-options) - * [Option: \-\-from\-classifier](#option---from-classifier) - * [Option: \-\-with\-system](#option---with-system) - * [Option: \-\-with\-authors](#option---with-authors) - * [Option: \-\-with\-urls](#option---with-urls) - * [Option: \-\-ignore\-packages](#option---ignore-packages) - * [Option: \-\-order](#option---order) - * [Option: \-\-format\-markdown](#option---format-markdown) - * [Option: \-\-format\-rst](#option---format-rst) + * [Option: from\-classifier](#option-from-classifier) + * [Option: with\-system](#option-with-system) + * [Option: with\-authors](#option-with-authors) + * [Option: with\-urls](#option-with-urls) + * [Option: ignore\-packages](#option-ignore-packages) + * [Option: order](#option-order) + * [Option: format\-markdown](#option-format-markdown) + * [Option: format\-rst](#option-format-rst) * [More Information](#more-information) * [License](#license) * [Dependencies](#dependencies) @@ -56,7 +56,7 @@ Execute the command with your venv (or virtualenv) environment. ## Command-Line Options -### Option: --from-classifier +### Option: from-classifier By default, this tool finds the license from package Metadata. However, depending on the type of package, it does not declare a license only in the Classifiers. @@ -75,7 +75,7 @@ If you want to refer to the license declared in Classifiers, use the `--from-cla setuptools 38.5.0 MIT License ``` -### Option: --with-system +### Option: with-system By default, system packages such as `pip` and `setuptools` are ignored. @@ -92,7 +92,7 @@ If you want to output all including system package, use the `--with-system` opti setuptools 38.5.0 UNKNOWN ``` -### Option: --with-authors +### Option: with-authors When executed with the `--with-authors` option, output with author of the package. @@ -103,7 +103,7 @@ When executed with the `--with-authors` option, output with author of the packag pytz 2017.3 MIT Stuart Bishop ``` -### Option: --with-urls +### Option: with-urls For packages without Metadata, the license is output as `UNKNOWN`. To get more package information, use the `--with-urls` option. @@ -114,7 +114,7 @@ For packages without Metadata, the license is output as `UNKNOWN`. To get more p pytz 2017.3 MIT http://pythonhosted.org/pytz ``` -### Option: --ignore-packages +### Option: ignore-packages When executed with the `--ignore-packages` option, ignore the package specified by argument from list output. @@ -134,7 +134,7 @@ Package names of arguments can be separated by spaces. setuptools 38.5.0 UNKNOWN ``` -### Option: --order +### Option: order By default, it is ordered by package name. @@ -144,7 +144,7 @@ If you give arguments to the `--order option`, you can output in other sorted or (venv) $ pip-licenses --order=license ``` -### Option: --format-markdown +### Option: format-markdown When executed with the `--format-markdown` option, you can output list in markdown format. @@ -163,7 +163,7 @@ When inserted in a markdown document, it is rendered as follows: | Django | 2.0.2 | BSD | | pytz | 2017.3 | MIT | -### Option: --format-rst +### Option: format-rst When executed with the `--format-rst` option, you can output list in "[Grid tables](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables)" of reStructuredText format. From fceaaa548d0025546043e8fdd186013ee1816ddf Mon Sep 17 00:00:00 2001 From: raimon Date: Sat, 10 Feb 2018 18:25:26 +0900 Subject: [PATCH 8/8] Add a information about version of 1.5.0 [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d4c252..0a0f484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### 1.5.0 + +* Implement new option `--format-rst` + ### 1.4.0 * Implement new option `--format-markdown`