Skip to content

Commit

Permalink
Migration from PTable to prettytable #82 #119 #120
Browse files Browse the repository at this point in the history
* Complete migration of table output library from PTable to prettytable
* Remove compatibility to work with either PTable or prettytable
* Fix failing tests with prettytable #120
  • Loading branch information
raimon49 committed Oct 27, 2022
1 parent 715a9f8 commit 2615388
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
15 changes: 9 additions & 6 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ autopep8==1.7.0
# via -r dev-requirements.in
bleach==5.0.1
# via readme-renderer
build==0.8.0
build==0.9.0
# via pip-tools
certifi==2022.9.24
# via requests
Expand Down Expand Up @@ -44,7 +44,7 @@ iniconfig==1.1.1
# via pytest
isort==5.10.1
# via -r dev-requirements.in
jaraco.classes==3.2.3
jaraco-classes==3.2.3
# via keyring
jeepney==0.8.0
# via
Expand All @@ -53,7 +53,7 @@ jeepney==0.8.0
keyring==23.9.3
# via twine
more-itertools==9.0.0
# via jaraco.classes
# via jaraco-classes
packaging==21.3
# via
# build
Expand All @@ -66,7 +66,7 @@ pkginfo==1.8.3
# via twine
pluggy==1.0.0
# via pytest
ptable==0.9.2
prettytable==3.4.1
# via -r requirements.in
py==1.11.0
# via pytest
Expand All @@ -86,6 +86,7 @@ pyparsing==3.0.9
# via packaging
pytest==7.1.3
# via
# -r dev-requirements.in
# pytest-cov
# pytest-pycodestyle
pytest-cov==4.0.0
Expand All @@ -101,7 +102,7 @@ requests==2.28.1
# codecov
# requests-toolbelt
# twine
requests-toolbelt==0.10.0
requests-toolbelt==0.10.1
# via twine
rfc3986==2.0.0
# via twine
Expand All @@ -127,13 +128,15 @@ urllib3==1.26.12
# via
# requests
# twine
wcwidth==0.2.5
# via prettytable
webencodings==0.5.1
# via bleach
wheel==0.37.1
# via
# -r dev-requirements.in
# pip-tools
zipp==3.9.0
zipp==3.10.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
Expand Down
36 changes: 12 additions & 24 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,14 @@
from collections import Counter
from enum import Enum, auto
from functools import partial
from importlib import metadata as importlib_metadata
from typing import List, Optional, Sequence, Text

from prettytable import PrettyTable

try:
from prettytable.prettytable import ALL as RULE_ALL
from prettytable.prettytable import FRAME as RULE_FRAME
from prettytable.prettytable import HEADER as RULE_HEADER
from prettytable.prettytable import NONE as RULE_NONE
PTABLE = True
except ImportError: # pragma: no cover
from prettytable import ALL as RULE_ALL
from prettytable import FRAME as RULE_FRAME
from prettytable import HEADER as RULE_HEADER
from prettytable import NONE as RULE_NONE
PTABLE = False

from importlib import metadata as importlib_metadata
from prettytable import ALL as RULE_ALL
from prettytable import FRAME as RULE_FRAME
from prettytable import HEADER as RULE_HEADER
from prettytable import NONE as RULE_NONE

open = open # allow monkey patching

Expand Down Expand Up @@ -115,7 +105,8 @@
SYSTEM_PACKAGES = (
__pkgname__,
'pip',
'PTable' if PTABLE else 'prettytable',
'prettytable',
'wcwidth',
'setuptools',
'wheel',
)
Expand Down Expand Up @@ -294,12 +285,9 @@ def create_summary_table(args: "CustomNamespace"):
class JsonPrettyTable(PrettyTable):
"""PrettyTable-like class exporting to JSON"""

def _format_row(self, row, options):
def _format_row(self, row):
resrow = {}
for (field, value) in zip(self._field_names, row):
if field not in options["fields"]:
continue

resrow[field] = value

return resrow
Expand All @@ -312,7 +300,7 @@ def get_string(self, **kwargs):

options = self._get_options(kwargs)
rows = self._get_rows(options)
formatted_rows = self._format_rows(rows, options)
formatted_rows = self._format_rows(rows)

lines = []
for row in formatted_rows:
Expand All @@ -322,7 +310,7 @@ def get_string(self, **kwargs):


class JsonLicenseFinderTable(JsonPrettyTable):
def _format_row(self, row, options):
def _format_row(self, row):
resrow = {}
for (field, value) in zip(self._field_names, row):
if field == 'Name':
Expand All @@ -344,7 +332,7 @@ def get_string(self, **kwargs):

options = self._get_options(kwargs)
rows = self._get_rows(options)
formatted_rows = self._format_rows(rows, options)
formatted_rows = self._format_rows(rows)

lines = []
for row in formatted_rows:
Expand Down Expand Up @@ -372,7 +360,7 @@ def esc_quotes(val):

options = self._get_options(kwargs)
rows = self._get_rows(options)
formatted_rows = self._format_rows(rows, options)
formatted_rows = self._format_rows(rows)

lines = []
formatted_header = ','.join(['"%s"' % (esc_quotes(val), )
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PTable
prettytable
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
# pip-compile requirements.in
#
ptable==0.9.2
prettytable==3.4.1
# via -r requirements.in
wcwidth==0.2.5
# via prettytable
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ setup_requires =
setuptools >= 40.9.0
pytest-runner
install_requires =
PTable
prettytable
tests_require =
docutils
pytest-cov
Expand Down

0 comments on commit 2615388

Please sign in to comment.