Skip to content

Commit

Permalink
Merge pull request #4 from raimon49/implement-output-rst
Browse files Browse the repository at this point in the history
Implement output reST
  • Loading branch information
raimon49 authored Feb 10, 2018
2 parents 5af890f + fceaaa5 commit 62f1350
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### 1.5.0

* Implement new option `--format-rst`

### 1.4.0

* Implement new option `--format-markdown`
Expand Down
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 62f1350

Please sign in to comment.