Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using prettytable #52

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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