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` diff --git a/README.md b/README.md index d2e30e9..2d01701 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) @@ -34,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 install -U pip-licenses ``` ## Usage @@ -54,7 +56,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 +75,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 +92,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 +103,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 +114,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 +134,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 +144,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,6 +163,21 @@ When inserted in a markdown document, it is rendered as follows: | Django | 2.0.2 | BSD | | pytz | 2017.3 | MIT | +### 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. + +```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. diff --git a/piplicenses.py b/piplicenses.py index 123be5b..8f001f3 100644 --- a/piplicenses.py +++ b/piplicenses.py @@ -35,10 +35,10 @@ 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' +__version__ = '1.5.0' __author__ = 'raimon' __license__ = 'MIT License' __summary__ = ('Dump the software license list of ' @@ -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