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

Update prettytable to 3.12.0 #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Package names of arguments can be separated by spaces.
```bash
(venv) $ pip-licenses --with-system --ignore-packages django pip pip-licenses
Name Version License
prettytable 3.5.0 BSD License
prettytable 3.12.0 BSD License
pytz 2017.3 MIT
setuptools 38.5.0 UNKNOWN
wcwidth 0.2.5 MIT License
Expand All @@ -376,7 +376,7 @@ Packages can also be specified with a version, only ignoring that specific versi
```bash
(venv) $ pip-licenses --with-system --ignore-packages django pytz:2017.3
Name Version License
prettytable 3.5.0 BSD License
prettytable 3.12.0 BSD License
setuptools 38.5.0 UNKNOWN
wcwidth 0.2.5 MIT License
```
Expand All @@ -396,7 +396,7 @@ Package names of arguments can be separated by spaces.
```bash
(venv) $ pip-licenses --with-system --packages prettytable pytz
Name Version License
prettytable 3.5.0 BSD License
prettytable 3.12.0 BSD License
pytz 2017.3 MIT
```

Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ platformdirs==2.6.0
# via black
pluggy==1.0.0
# via pytest
prettytable==3.9.0
prettytable==3.12.0
# via -r requirements.in
py==1.11.0
# via pytest-pycodestyle
Expand Down
51 changes: 19 additions & 32 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
from typing import TYPE_CHECKING, Iterable, List, Type, cast

import tomli
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
from prettytable import PrettyTable
from prettytable import HRuleStyle, PrettyTable, RowType

if TYPE_CHECKING:
from email.message import Message
Expand Down Expand Up @@ -206,7 +202,7 @@ def get_pkg_included_file(
lambda file: pattern.match(file.name), pkg_files
)
for rel_path in matched_rel_paths:
abs_path = Path(pkg.locate_file(rel_path))
abs_path = Path(str(pkg.locate_file(rel_path)))
if not abs_path.is_file():
continue
included_file = str(abs_path)
Expand Down Expand Up @@ -362,7 +358,7 @@ def get_python_sys_path(executable: str) -> list[str]:

def create_licenses_table(
args: CustomNamespace,
output_fields: Iterable[str] = DEFAULT_OUTPUT_FIELDS,
output_fields: Sequence[str] = DEFAULT_OUTPUT_FIELDS,
) -> PrettyTable:
table = factory_styled_table_with_args(args, output_fields)

Expand Down Expand Up @@ -452,8 +448,8 @@ def case_insensitive_set_diff(set_a, set_b):
class JsonPrettyTable(PrettyTable):
"""PrettyTable-like class exporting to JSON"""

def _format_row(self, row: Iterable[str]) -> dict[str, str | list[str]]:
resrow: dict[str, str | List[str]] = {}
def format_row(self, row: RowType) -> dict[str, str | list[str]]:
resrow: dict[str, str | list[str]] = {}
for field, value in zip(self._field_names, row):
resrow[field] = value

Expand All @@ -467,17 +463,12 @@ def get_string(self, **kwargs: str | list[str]) -> str:

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

lines = []
for row in formatted_rows:
lines.append(row)

lines = [self.format_row(row) for row in rows]
return json.dumps(lines, indent=2, sort_keys=True)


class JsonLicenseFinderTable(JsonPrettyTable):
def _format_row(self, row: Iterable[str]) -> dict[str, str | list[str]]:
def format_row(self, row: RowType) -> dict[str, str | list[str]]:
resrow: dict[str, str | List[str]] = {}
for field, value in zip(self._field_names, row):
if field == "Name":
Expand All @@ -499,12 +490,7 @@ def get_string(self, **kwargs: str | list[str]) -> str:

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

lines = []
for row in formatted_rows:
lines.append(row)

lines = [self.format_row(row) for row in rows]
return json.dumps(lines, sort_keys=True)


Expand All @@ -530,16 +516,17 @@ def esc_quotes(val: bytes | str) -> str:
rows = self._get_rows(options)
formatted_rows = self._format_rows(rows)

lines = []
lines: list[str] = []
formatted_header = ",".join(
['"%s"' % (esc_quotes(val),) for val in self._field_names]
)
lines.append(formatted_header)
for row in formatted_rows:
formatted_row = ",".join(
['"%s"' % (esc_quotes(val),) for val in row]
)
lines.append(formatted_row)
lines.extend(
[
",".join(['"%s"' % (esc_quotes(val),) for val in row])
for row in formatted_rows
]
)

return "\n".join(lines)

Expand All @@ -566,7 +553,7 @@ def get_string(self, **kwargs: str | list[str]) -> str:

def factory_styled_table_with_args(
args: CustomNamespace,
output_fields: Iterable[str] = DEFAULT_OUTPUT_FIELDS,
output_fields: Sequence[str] = DEFAULT_OUTPUT_FIELDS,
) -> PrettyTable:
table = PrettyTable()
table.field_names = output_fields # type: ignore[assignment]
Expand All @@ -581,13 +568,13 @@ def factory_styled_table_with_args(

if args.format_ == FormatArg.MARKDOWN:
table.junction_char = "|"
table.hrules = RULE_HEADER
table.hrules = HRuleStyle.HEADER
elif args.format_ == FormatArg.RST:
table.junction_char = "+"
table.hrules = RULE_ALL
table.hrules = HRuleStyle.ALL
elif args.format_ == FormatArg.CONFLUENCE:
table.junction_char = "|"
table.hrules = RULE_NONE
table.hrules = HRuleStyle.NONE
elif args.format_ == FormatArg.JSON:
table = JsonPrettyTable(table.field_names)
elif args.format_ == FormatArg.JSON_LICENSE_FINDER:
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
"Typing :: Typed"
]
dependencies = [
"prettytable >= 2.3.0",
"prettytable >= 3.12.0",
"tomli >= 2"
]

Expand Down Expand Up @@ -75,7 +75,6 @@ known_first_party = ["piplicenses"]
profile = "black"

[tool.mypy]
mypy_path = "stubs/"
exclude = ["venv"]

[tool.coverage.run]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile --output-file=requirements.txt pyproject.toml
#
prettytable==3.9.0
prettytable==3.12.0
# via pip-licenses (pyproject.toml)
tomli==2.0.1
# via pip-licenses (pyproject.toml)
Expand Down
5 changes: 0 additions & 5 deletions stubs/prettytable/__init__.pyi

This file was deleted.

53 changes: 0 additions & 53 deletions stubs/prettytable/prettytable.pyi

This file was deleted.

17 changes: 7 additions & 10 deletions test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
from piplicenses import (
DEFAULT_OUTPUT_FIELDS,
LICENSE_UNKNOWN,
RULE_ALL,
RULE_FRAME,
RULE_HEADER,
RULE_NONE,
SYSTEM_PACKAGES,
CompatibleArgumentParser,
FromArg,
Expand All @@ -56,6 +52,7 @@
select_license_by_source,
value_to_enum_key,
)
from prettytable import HRuleStyle

if TYPE_CHECKING:
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -156,7 +153,7 @@ def test_with_empty_args(self) -> None:
self.assertFalse(table.border)
self.assertTrue(table.header)
self.assertEqual("+", table.junction_char)
self.assertEqual(RULE_FRAME, table.hrules)
self.assertEqual(HRuleStyle.FRAME, table.hrules)

output_fields = get_output_fields(args)
self.assertEqual(
Expand Down Expand Up @@ -542,7 +539,7 @@ def test_format_plain(self) -> None:
self.assertFalse(table.border)
self.assertTrue(table.header)
self.assertEqual("+", table.junction_char)
self.assertEqual(RULE_FRAME, table.hrules)
self.assertEqual(HRuleStyle.FRAME, table.hrules)

def test_format_plain_vertical(self) -> None:
format_plain_args = ["--format=plain-vertical", "--from=classifier"]
Expand All @@ -561,7 +558,7 @@ def test_format_markdown(self) -> None:
self.assertTrue(table.border)
self.assertTrue(table.header)
self.assertEqual("|", table.junction_char)
self.assertEqual(RULE_HEADER, table.hrules)
self.assertEqual(HRuleStyle.HEADER, table.hrules)

@unittest.skipIf(
sys.version_info < (3, 6, 0),
Expand All @@ -579,7 +576,7 @@ def test_format_rst_without_filter(self) -> None:
self.assertTrue(table.border)
self.assertTrue(table.header)
self.assertEqual("+", table.junction_char)
self.assertEqual(RULE_ALL, table.hrules)
self.assertEqual(HRuleStyle.ALL, table.hrules)
piplicenses.importlib_metadata.distributions = (
importlib_metadata_distributions_orig
)
Expand All @@ -596,7 +593,7 @@ def test_format_rst_default_filter(self) -> None:
self.assertTrue(table.border)
self.assertTrue(table.header)
self.assertEqual("+", table.junction_char)
self.assertEqual(RULE_ALL, table.hrules)
self.assertEqual(HRuleStyle.ALL, table.hrules)
self.check_rst(str(table))
piplicenses.importlib_metadata.distributions = (
importlib_metadata_distributions_orig
Expand All @@ -611,7 +608,7 @@ def test_format_confluence(self) -> None:
self.assertTrue(table.border)
self.assertTrue(table.header)
self.assertEqual("|", table.junction_char)
self.assertEqual(RULE_NONE, table.hrules)
self.assertEqual(HRuleStyle.NONE, table.hrules)

def test_format_html(self) -> None:
format_html_args = ["--format=html", "--with-authors"]
Expand Down