Skip to content

Commit

Permalink
Merge pull request #52 from jayvdb/prettytable
Browse files Browse the repository at this point in the history
Allow using prettytable
  • Loading branch information
raimon49 authored Dec 22, 2019
2 parents aa574f4 + cbc5b99 commit 2362a8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 17 additions & 3 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,22 @@
except ImportError:
from pip import get_installed_distributions
from prettytable import PrettyTable
from prettytable.prettytable import (FRAME as RULE_FRAME, ALL as RULE_ALL,
HEADER as RULE_HEADER, NONE as RULE_NONE)
try:
from prettytable.prettytable import (
ALL as RULE_ALL,
FRAME as RULE_FRAME,
HEADER as RULE_HEADER,
NONE as RULE_NONE,
)
PTABLE = True
except ImportError: # pragma: no cover
from prettytable import (
ALL as RULE_ALL,
FRAME as RULE_FRAME,
HEADER as RULE_HEADER,
NONE as RULE_NONE,
)
PTABLE = False

__pkgname__ = 'pip-licenses'
__version__ = '1.17.0'
Expand Down Expand Up @@ -102,7 +116,7 @@
SYSTEM_PACKAGES = (
__pkgname__,
'pip',
'PTable',
'PTable' if PTABLE else 'prettytable',
'setuptools',
'wheel',
)
Expand Down
8 changes: 5 additions & 3 deletions test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import unittest
from email import message_from_string

from prettytable.prettytable import (FRAME as RULE_FRAME, ALL as RULE_ALL,
HEADER as RULE_HEADER, NONE as RULE_NONE)
from piplicenses import (__pkgname__, create_parser, output_colored,
create_licenses_table, get_output_fields, get_sortby,
factory_styled_table_with_args, create_warn_string,
find_license_from_classifier, create_output_string,
select_license_by_source, save_if_needs,
RULE_ALL, RULE_FRAME, RULE_HEADER, RULE_NONE,
DEFAULT_OUTPUT_FIELDS, SYSTEM_PACKAGES,
LICENSE_UNKNOWN)

Expand Down Expand Up @@ -219,7 +218,10 @@ def test_with_license_file_warning(self):
self.assertIn('best paired with --format=json', warn_string)

def test_ignore_packages(self):
ignore_pkg_name = 'PTable'
if 'PTable' in SYSTEM_PACKAGES:
ignore_pkg_name = 'PTable'
else:
ignore_pkg_name = 'prettytable'
ignore_packages_args = ['--ignore-package=' + ignore_pkg_name]
args = self.parser.parse_args(ignore_packages_args)
table = create_licenses_table(args)
Expand Down

0 comments on commit 2362a8a

Please sign in to comment.