prettytable 3.12.0__tar.gz → 3.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {prettytable-3.12.0 → prettytable-3.13.0}/.coveragerc +4 -0
  2. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/labels.yml +4 -3
  3. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/lint.yml +10 -6
  4. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/release-drafter.yml +0 -3
  5. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/release.yml +2 -2
  6. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/require-pr-label.yml +8 -3
  7. {prettytable-3.12.0 → prettytable-3.13.0}/.github/workflows/test.yml +4 -6
  8. {prettytable-3.12.0 → prettytable-3.13.0}/.pre-commit-config.yaml +14 -8
  9. {prettytable-3.12.0 → prettytable-3.13.0}/PKG-INFO +14 -5
  10. {prettytable-3.12.0 → prettytable-3.13.0}/README.md +11 -2
  11. {prettytable-3.12.0 → prettytable-3.13.0}/pyproject.toml +12 -10
  12. prettytable-3.13.0/src/prettytable/__main__.py +47 -0
  13. {prettytable-3.12.0 → prettytable-3.13.0}/src/prettytable/_version.py +2 -2
  14. {prettytable-3.12.0 → prettytable-3.13.0}/src/prettytable/prettytable.py +42 -31
  15. {prettytable-3.12.0 → prettytable-3.13.0}/tests/test_prettytable.py +254 -0
  16. {prettytable-3.12.0 → prettytable-3.13.0}/tox.ini +2 -2
  17. {prettytable-3.12.0 → prettytable-3.13.0}/.github/FUNDING.yml +0 -0
  18. {prettytable-3.12.0 → prettytable-3.13.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  19. {prettytable-3.12.0 → prettytable-3.13.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  20. {prettytable-3.12.0 → prettytable-3.13.0}/.github/SECURITY.md +0 -0
  21. {prettytable-3.12.0 → prettytable-3.13.0}/.github/dependabot.yml +0 -0
  22. {prettytable-3.12.0 → prettytable-3.13.0}/.github/labels.yml +0 -0
  23. {prettytable-3.12.0 → prettytable-3.13.0}/.github/release-drafter.yml +0 -0
  24. {prettytable-3.12.0 → prettytable-3.13.0}/.gitignore +0 -0
  25. {prettytable-3.12.0 → prettytable-3.13.0}/CHANGELOG.md +0 -0
  26. {prettytable-3.12.0 → prettytable-3.13.0}/LICENSE +0 -0
  27. {prettytable-3.12.0 → prettytable-3.13.0}/RELEASING.md +0 -0
  28. {prettytable-3.12.0 → prettytable-3.13.0}/src/prettytable/__init__.py +2 -2
  29. {prettytable-3.12.0 → prettytable-3.13.0}/src/prettytable/colortable.py +0 -0
  30. {prettytable-3.12.0 → prettytable-3.13.0}/src/prettytable/py.typed +0 -0
  31. {prettytable-3.12.0 → prettytable-3.13.0}/tests/test_colortable.py +0 -0
@@ -7,3 +7,7 @@ exclude_also =
7
7
  if 0:
8
8
  if __name__ == .__main__.:
9
9
  def main()
10
+
11
+ [run]
12
+ omit =
13
+ **/__main__.py
@@ -1,8 +1,5 @@
1
1
  name: Sync labels
2
2
 
3
- permissions:
4
- pull-requests: write
5
-
6
3
  on:
7
4
  push:
8
5
  branches:
@@ -13,9 +10,13 @@ on:
13
10
 
14
11
  jobs:
15
12
  sync:
13
+ permissions:
14
+ pull-requests: write
16
15
  runs-on: ubuntu-latest
17
16
  steps:
18
17
  - uses: actions/checkout@v4
18
+ with:
19
+ persist-credentials: false
19
20
  - uses: micnncim/action-label-syncer@v1
20
21
  with:
21
22
  prune: false
@@ -4,10 +4,8 @@ on: [push, pull_request, workflow_dispatch]
4
4
 
5
5
  env:
6
6
  FORCE_COLOR: 1
7
- PIP_DISABLE_PIP_VERSION_CHECK: 1
8
7
 
9
- permissions:
10
- contents: read
8
+ permissions: {}
11
9
 
12
10
  jobs:
13
11
  lint:
@@ -15,18 +13,24 @@ jobs:
15
13
 
16
14
  steps:
17
15
  - uses: actions/checkout@v4
16
+ with:
17
+ persist-credentials: false
18
18
  - uses: actions/setup-python@v5
19
19
  with:
20
20
  python-version: "3.x"
21
- cache: pip
22
- - uses: pre-commit/action@v3.0.1
21
+ - uses: tox-dev/action-pre-commit-uv@v1
23
22
 
24
23
  mypy:
25
24
  runs-on: ubuntu-latest
26
25
 
27
26
  steps:
28
27
  - uses: actions/checkout@v4
28
+ with:
29
+ persist-credentials: false
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: "3.x"
29
33
  - name: Install uv
30
- uses: hynek/setup-cached-uv@v2
34
+ uses: astral-sh/setup-uv@v5
31
35
  - name: Mypy
32
36
  run: uvx --with tox-uv tox -e mypy
@@ -14,9 +14,6 @@ on:
14
14
  # types: [opened, reopened, synchronize]
15
15
  workflow_dispatch:
16
16
 
17
- permissions:
18
- contents: read
19
-
20
17
  jobs:
21
18
  update_release_draft:
22
19
  if: github.repository_owner == 'prettytable'
@@ -8,8 +8,7 @@ on:
8
8
  - published
9
9
  workflow_dispatch:
10
10
 
11
- permissions:
12
- contents: read
11
+ permissions: {}
13
12
 
14
13
  env:
15
14
  FORCE_COLOR: 1
@@ -24,6 +23,7 @@ jobs:
24
23
  - uses: actions/checkout@v4
25
24
  with:
26
25
  fetch-depth: 0
26
+ persist-credentials: false
27
27
 
28
28
  - uses: hynek/build-and-inspect-python-package@v2
29
29
 
@@ -17,6 +17,11 @@ jobs:
17
17
  with:
18
18
  mode: minimum
19
19
  count: 1
20
- labels:
21
- "changelog: Added, changelog: Changed, changelog: Deprecated, changelog:
22
- Fixed, changelog: Removed, changelog: Security, changelog: skip"
20
+ labels: |
21
+ changelog: Added
22
+ changelog: Changed
23
+ changelog: Deprecated
24
+ changelog: Fixed
25
+ changelog: Removed
26
+ changelog: Security
27
+ changelog: skip
@@ -2,8 +2,7 @@ name: Test
2
2
 
3
3
  on: [push, pull_request, workflow_dispatch]
4
4
 
5
- permissions:
6
- contents: read
5
+ permissions: {}
7
6
 
8
7
  env:
9
8
  FORCE_COLOR: 1
@@ -14,7 +13,7 @@ jobs:
14
13
  strategy:
15
14
  fail-fast: false
16
15
  matrix:
17
- python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13"]
16
+ python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
18
17
  os: [windows-latest, macos-latest, ubuntu-latest]
19
18
 
20
19
  steps:
@@ -29,18 +28,17 @@ jobs:
29
28
  allow-prereleases: true
30
29
 
31
30
  - name: Install uv
32
- uses: hynek/setup-cached-uv@v2
31
+ uses: astral-sh/setup-uv@v5
33
32
 
34
33
  - name: Tox tests
35
34
  run: |
36
35
  uvx --with tox-uv tox -e py
37
36
 
38
37
  - name: Upload coverage
39
- uses: codecov/codecov-action@v4
38
+ uses: codecov/codecov-action@v5
40
39
  with:
41
40
  flags: ${{ matrix.os }}
42
41
  name: ${{ matrix.os }} Python ${{ matrix.python-version }}
43
- token: ${{ secrets.CODECOV_TOKEN }}
44
42
 
45
43
  success:
46
44
  needs: test
@@ -1,12 +1,12 @@
1
1
  repos:
2
2
  - repo: https://github.com/astral-sh/ruff-pre-commit
3
- rev: v0.6.9
3
+ rev: v0.9.2
4
4
  hooks:
5
5
  - id: ruff
6
6
  args: [--exit-non-zero-on-fix]
7
7
 
8
8
  - repo: https://github.com/psf/black-pre-commit-mirror
9
- rev: 24.8.0
9
+ rev: 24.10.0
10
10
  hooks:
11
11
  - id: black
12
12
 
@@ -25,32 +25,38 @@ repos:
25
25
  exclude: .github/ISSUE_TEMPLATE/bug_report.md|tests/test_prettytable.py
26
26
 
27
27
  - repo: https://github.com/python-jsonschema/check-jsonschema
28
- rev: 0.29.3
28
+ rev: 0.31.0
29
29
  hooks:
30
+ - id: check-dependabot
30
31
  - id: check-github-workflows
31
32
 
32
33
  - repo: https://github.com/rhysd/actionlint
33
- rev: v1.7.3
34
+ rev: v1.7.7
34
35
  hooks:
35
36
  - id: actionlint
36
37
 
38
+ - repo: https://github.com/woodruffw/zizmor-pre-commit
39
+ rev: v1.2.2
40
+ hooks:
41
+ - id: zizmor
42
+
37
43
  - repo: https://github.com/tox-dev/pyproject-fmt
38
- rev: 2.2.4
44
+ rev: v2.5.0
39
45
  hooks:
40
46
  - id: pyproject-fmt
41
47
 
42
48
  - repo: https://github.com/abravalheri/validate-pyproject
43
- rev: v0.21
49
+ rev: v0.23
44
50
  hooks:
45
51
  - id: validate-pyproject
46
52
 
47
53
  - repo: https://github.com/tox-dev/tox-ini-fmt
48
- rev: 1.4.1
54
+ rev: 1.5.0
49
55
  hooks:
50
56
  - id: tox-ini-fmt
51
57
 
52
58
  - repo: https://github.com/rbubley/mirrors-prettier
53
- rev: v3.3.3
59
+ rev: v3.4.2
54
60
  hooks:
55
61
  - id: prettier
56
62
  args: [--prose-wrap=always, --print-width=88]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: prettytable
3
- Version: 3.12.0
3
+ Version: 3.13.0
4
4
  Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
5
5
  Project-URL: Changelog, https://github.com/prettytable/prettytable/releases
6
6
  Project-URL: Funding, https://tidelift.com/subscription/pkg/pypi-prettytable?utm_source=pypi-prettytable&utm_medium=pypi
@@ -10,7 +10,6 @@ Author-email: Luke Maurits <luke@maurits.id.au>
10
10
  Maintainer: Hugo van Kemenade
11
11
  License-Expression: BSD-3-Clause
12
12
  License-File: LICENSE
13
- Classifier: License :: OSI Approved :: BSD License
14
13
  Classifier: Programming Language :: Python
15
14
  Classifier: Programming Language :: Python :: 3 :: Only
16
15
  Classifier: Programming Language :: Python :: 3.9
@@ -18,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
21
  Classifier: Programming Language :: Python :: Implementation :: CPython
22
22
  Classifier: Programming Language :: Python :: Implementation :: PyPy
23
23
  Classifier: Topic :: Text Processing
@@ -70,6 +70,14 @@ Or from `requirements.txt`:
70
70
 
71
71
  -e git://github.com/prettytable/prettytable.git#egg=prettytable
72
72
 
73
+ ## Demo
74
+
75
+ To see demo output, run:
76
+
77
+ ```bash
78
+ python3 -m prettytable
79
+ ```
80
+
73
81
  ## Tutorial on how to use the PrettyTable API
74
82
 
75
83
  ### Getting your data into (and out of) the table
@@ -464,8 +472,9 @@ You can set the style for your table using the `set_style` method before any cal
464
472
  `print` or `get_string`. Here's how to print a table in Markdown format:
465
473
 
466
474
  ```python
467
- from prettytable import MARKDOWN
468
- table.set_style(MARKDOWN)
475
+ from prettytable import TableStyle
476
+
477
+ table.set_style(TableStyle.MARKDOWN)
469
478
  print(table)
470
479
  ```
471
480
 
@@ -38,6 +38,14 @@ Or from `requirements.txt`:
38
38
 
39
39
  -e git://github.com/prettytable/prettytable.git#egg=prettytable
40
40
 
41
+ ## Demo
42
+
43
+ To see demo output, run:
44
+
45
+ ```bash
46
+ python3 -m prettytable
47
+ ```
48
+
41
49
  ## Tutorial on how to use the PrettyTable API
42
50
 
43
51
  ### Getting your data into (and out of) the table
@@ -432,8 +440,9 @@ You can set the style for your table using the `set_style` method before any cal
432
440
  `print` or `get_string`. Here's how to print a table in Markdown format:
433
441
 
434
442
  ```python
435
- from prettytable import MARKDOWN
436
- table.set_style(MARKDOWN)
443
+ from prettytable import TableStyle
444
+
445
+ table.set_style(TableStyle.MARKDOWN)
437
446
  print(table)
438
447
  ```
439
448
 
@@ -2,7 +2,7 @@
2
2
  build-backend = "hatchling.build"
3
3
  requires = [
4
4
  "hatch-vcs",
5
- "hatchling",
5
+ "hatchling>=1.27",
6
6
  ]
7
7
 
8
8
  [project]
@@ -10,11 +10,11 @@ name = "prettytable"
10
10
  description = "A simple Python library for easily displaying tabular data in a visually appealing ASCII table format"
11
11
  readme = "README.md"
12
12
  license = "BSD-3-Clause"
13
+ license-files = [ "LICENSE" ]
13
14
  maintainers = [ { name = "Hugo van Kemenade" } ]
14
15
  authors = [ { name = "Luke Maurits", email = "luke@maurits.id.au" } ]
15
16
  requires-python = ">=3.9"
16
17
  classifiers = [
17
- "License :: OSI Approved :: BSD License",
18
18
  "Programming Language :: Python",
19
19
  "Programming Language :: Python :: 3 :: Only",
20
20
  "Programming Language :: Python :: 3.9",
@@ -22,6 +22,7 @@ classifiers = [
22
22
  "Programming Language :: Python :: 3.11",
23
23
  "Programming Language :: Python :: 3.12",
24
24
  "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
25
26
  "Programming Language :: Python :: Implementation :: CPython",
26
27
  "Programming Language :: Python :: Implementation :: PyPy",
27
28
  "Topic :: Text Processing",
@@ -55,9 +56,9 @@ fix = true
55
56
 
56
57
  lint.select = [
57
58
  "C4", # flake8-comprehensions
58
- "E", # pycodestyle errors
59
+ "E", # pycodestyle
59
60
  "EM", # flake8-errmsg
60
- "F", # pyflakes errors
61
+ "F", # pyflakes
61
62
  "I", # isort
62
63
  "ICN", # flake8-import-conventions
63
64
  "ISC", # flake8-implicit-str-concat
@@ -67,14 +68,15 @@ lint.select = [
67
68
  "RUF022", # unsorted-dunder-all
68
69
  "RUF100", # unused noqa (yesqa)
69
70
  "UP", # pyupgrade
70
- "W", # pycodestyle warnings
71
+ "W", # pycodestyle
71
72
  "YTT", # flake8-2020
72
73
  ]
73
74
  lint.ignore = [
74
- "E203", # Whitespace before ':'
75
- "E221", # Multiple spaces before operator
76
- "E226", # Missing whitespace around arithmetic operator
77
- "E241", # Multiple spaces after ','
75
+ "E203", # Whitespace before ':'
76
+ "E221", # Multiple spaces before operator
77
+ "E226", # Missing whitespace around arithmetic operator
78
+ "E241", # Multiple spaces after ','
79
+ "UP038", # Makes code slower and more verbose
78
80
  ]
79
81
  lint.flake8-import-conventions.aliases.datetime = "dt"
80
82
  lint.flake8-import-conventions.banned-from = [ "datetime" ]
@@ -82,7 +84,7 @@ lint.isort.known-first-party = [ "prettytable" ]
82
84
  lint.isort.required-imports = [ "from __future__ import annotations" ]
83
85
 
84
86
  [tool.pyproject-fmt]
85
- max_supported_python = "3.13"
87
+ max_supported_python = "3.14"
86
88
 
87
89
  [tool.pytest.ini_options]
88
90
  filterwarnings = [
@@ -0,0 +1,47 @@
1
+ from __future__ import annotations
2
+
3
+ from prettytable import PrettyTable, TableStyle
4
+ from prettytable.colortable import ColorTable, Theme, Themes
5
+
6
+ FIELD_NAMES = ["City name", "Area", "Population", "Annual Rainfall"]
7
+ ROWS = [
8
+ ["Adelaide", 1295, 1158259, 600.5],
9
+ ["Brisbane", 5905, 1857594, 1146.4],
10
+ ["Darwin", 112, 120900, 1714.7],
11
+ ["Hobart", 1357, 205556, 619.5],
12
+ ["Melbourne", 1566, 3806092, 646.9],
13
+ ["Perth", 5386, 1554769, 869.4],
14
+ ["Sydney", 2058, 4336374, 1214.8],
15
+ ]
16
+
17
+ if __name__ == "__main__":
18
+ table = PrettyTable()
19
+ table.field_names = FIELD_NAMES
20
+ for row in ROWS:
21
+ if row[0] == "Hobart":
22
+ table.add_row(row, divider=True)
23
+ else:
24
+ table.add_row(row)
25
+
26
+ for style in TableStyle:
27
+ print("PrettyTable style:", style.name)
28
+ print()
29
+ table.set_style(style)
30
+ print(table)
31
+ print()
32
+
33
+ table = ColorTable()
34
+ table.field_names = FIELD_NAMES
35
+ for row in ROWS:
36
+ if row[0] == "Hobart":
37
+ table.add_row(row, divider=True)
38
+ else:
39
+ table.add_row(row)
40
+
41
+ for name, theme in vars(Themes).items():
42
+ if isinstance(theme, Theme):
43
+ print("ColorTable theme:", name)
44
+ print()
45
+ table.theme = theme
46
+ print(table)
47
+ print()
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.12.0'
16
- __version_tuple__ = version_tuple = (3, 12, 0)
15
+ __version__ = version = '3.13.0'
16
+ __version_tuple__ = version_tuple = (3, 13, 0)
@@ -276,11 +276,6 @@ class PrettyTable:
276
276
  self.custom_format = {}
277
277
  self._style = None
278
278
 
279
- if field_names:
280
- self.field_names = field_names
281
- else:
282
- self._widths: list[int] = []
283
-
284
279
  # Options
285
280
  self._options = [
286
281
  "title",
@@ -329,11 +324,16 @@ class PrettyTable:
329
324
  "escape_header",
330
325
  "escape_data",
331
326
  ]
327
+
328
+ self._kwargs = {}
332
329
  for option in self._options:
333
330
  if option in kwargs:
334
331
  self._validate_option(option, kwargs[option])
332
+ self._kwargs[option] = kwargs[option]
333
+
335
334
  else:
336
335
  kwargs[option] = None
336
+ self._kwargs[option] = None
337
337
 
338
338
  self._title = kwargs["title"] or None
339
339
  self._start = kwargs["start"] or 0
@@ -372,15 +372,13 @@ class PrettyTable:
372
372
  self._escape_header = kwargs["escape_header"]
373
373
  else:
374
374
  self._escape_header = True
375
- # Column specific arguments, use property.setters
376
- self.align = kwargs["align"] or {}
377
- self.valign = kwargs["valign"] or {}
378
- self.max_width = kwargs["max_width"] or {}
379
- self.min_width = kwargs["min_width"] or {}
380
- self.int_format = kwargs["int_format"] or {}
381
- self.float_format = kwargs["float_format"] or {}
382
- self.custom_format = kwargs["custom_format"] or {}
383
- self.none_format = kwargs["none_format"] or {}
375
+
376
+ if field_names:
377
+ self.field_names = field_names
378
+ else:
379
+ self._widths: list[int] = []
380
+
381
+ self._column_specific_args()
384
382
 
385
383
  self._min_table_width = kwargs["min_table_width"] or None
386
384
  self._max_table_width = kwargs["max_table_width"] or None
@@ -416,6 +414,17 @@ class PrettyTable:
416
414
  self._xhtml = kwargs["xhtml"] or False
417
415
  self._attributes = kwargs["attributes"] or {}
418
416
 
417
+ def _column_specific_args(self):
418
+ # Column specific arguments, use property.setters
419
+ self.align = self._kwargs["align"] or {}
420
+ self.valign = self._kwargs["valign"] or {}
421
+ self.max_width = self._kwargs["max_width"] or {}
422
+ self.min_width = self._kwargs["min_width"] or {}
423
+ self.int_format = self._kwargs["int_format"] or {}
424
+ self.float_format = self._kwargs["float_format"] or {}
425
+ self.custom_format = self._kwargs["custom_format"] or {}
426
+ self.none_format = self._kwargs["none_format"] or {}
427
+
419
428
  def _justify(self, text: str, width: int, align: AlignType) -> str:
420
429
  excess = width - _str_block_width(text)
421
430
  if align == "l":
@@ -761,6 +770,9 @@ class PrettyTable:
761
770
  if self._field_names:
762
771
  old_names = self._field_names[:]
763
772
  self._field_names = val
773
+
774
+ self._column_specific_args()
775
+
764
776
  if self._align and old_names:
765
777
  for old_name, new_name in zip(old_names, val):
766
778
  self._align[new_name] = self._align[old_name]
@@ -1441,10 +1453,9 @@ class PrettyTable:
1441
1453
  ##############################
1442
1454
 
1443
1455
  def set_style(self, style: TableStyle) -> None:
1456
+ self._set_default_style()
1444
1457
  self._style = style
1445
- if style == TableStyle.DEFAULT:
1446
- self._set_default_style()
1447
- elif style == TableStyle.MSWORD_FRIENDLY:
1458
+ if style == TableStyle.MSWORD_FRIENDLY:
1448
1459
  self._set_msword_style()
1449
1460
  elif style == TableStyle.PLAIN_COLUMNS:
1450
1461
  self._set_columns_style()
@@ -1458,12 +1469,11 @@ class PrettyTable:
1458
1469
  self._set_single_border_style()
1459
1470
  elif style == TableStyle.RANDOM:
1460
1471
  self._set_random_style()
1461
- else:
1472
+ elif style != TableStyle.DEFAULT:
1462
1473
  msg = "Invalid pre-set style"
1463
1474
  raise ValueError(msg)
1464
1475
 
1465
1476
  def _set_orgmode_style(self) -> None:
1466
- self._set_default_style()
1467
1477
  self.orgmode = True
1468
1478
 
1469
1479
  def _set_markdown_style(self) -> None:
@@ -1646,8 +1656,8 @@ class PrettyTable:
1646
1656
  Arguments:
1647
1657
  fieldname - name of the field to contain the new column of data"""
1648
1658
  self._field_names.insert(0, fieldname)
1649
- self._align[fieldname] = self.align
1650
- self._valign[fieldname] = self.valign
1659
+ self._align[fieldname] = self._kwargs["align"] or "c"
1660
+ self._valign[fieldname] = self._kwargs["valign"] or "t"
1651
1661
  for i, row in enumerate(self._rows):
1652
1662
  row.insert(0, i + 1)
1653
1663
 
@@ -2506,9 +2516,12 @@ class PrettyTable:
2506
2516
  if options["escape_header"]:
2507
2517
  field = escape(field)
2508
2518
 
2519
+ content = field.replace("\n", linebreak)
2509
2520
  lines.append(
2510
- ' <th style="padding-left: %dem; padding-right: %dem; text-align: center">%s</th>' # noqa: E501
2511
- % (lpad, rpad, field.replace("\n", linebreak))
2521
+ f' <th style="'
2522
+ f"padding-left: {lpad}em; "
2523
+ f"padding-right: {rpad}em; "
2524
+ f'text-align: center">{content}</th>'
2512
2525
  )
2513
2526
  lines.append(" </tr>")
2514
2527
  lines.append(" </thead>")
@@ -2536,15 +2549,13 @@ class PrettyTable:
2536
2549
  if options["escape_data"]:
2537
2550
  datum = escape(datum)
2538
2551
 
2552
+ content = datum.replace("\n", linebreak)
2539
2553
  lines.append(
2540
- ' <td style="padding-left: %dem; padding-right: %dem; text-align: %s; vertical-align: %s">%s</td>' # noqa: E501
2541
- % (
2542
- lpad,
2543
- rpad,
2544
- align,
2545
- valign,
2546
- datum.replace("\n", linebreak),
2547
- )
2554
+ f' <td style="'
2555
+ f"padding-left: {lpad}em; "
2556
+ f"padding-right: {rpad}em; "
2557
+ f"text-align: {align}; "
2558
+ f'vertical-align: {valign}">{content}</td>'
2548
2559
  )
2549
2560
  lines.append(" </tr>")
2550
2561
  lines.append(" </tbody>")
@@ -1712,6 +1712,134 @@ class TestStyle:
1712
1712
  with pytest.raises(ValueError):
1713
1713
  t.set_style(HRuleStyle.ALL) # type: ignore[arg-type]
1714
1714
 
1715
+ @pytest.mark.parametrize(
1716
+ "original_style,style, expected",
1717
+ [
1718
+ pytest.param(
1719
+ TableStyle.MARKDOWN,
1720
+ TableStyle.DEFAULT,
1721
+ """
1722
+ +---+---------+---------+---------+
1723
+ | | Field 1 | Field 2 | Field 3 |
1724
+ +---+---------+---------+---------+
1725
+ | 1 | value 1 | value2 | value3 |
1726
+ | 4 | value 4 | value5 | value6 |
1727
+ | 7 | value 7 | value8 | value9 |
1728
+ +---+---------+---------+---------+
1729
+ """,
1730
+ id="DEFAULT",
1731
+ ),
1732
+ pytest.param(
1733
+ TableStyle.MSWORD_FRIENDLY,
1734
+ TableStyle.MARKDOWN,
1735
+ """
1736
+ | | Field 1 | Field 2 | Field 3 |
1737
+ | :-: | :-----: | :-----: | :-----: |
1738
+ | 1 | value 1 | value2 | value3 |
1739
+ | 4 | value 4 | value5 | value6 |
1740
+ | 7 | value 7 | value8 | value9 |
1741
+ """,
1742
+ id="MARKDOWN",
1743
+ ),
1744
+ pytest.param(
1745
+ TableStyle.MARKDOWN,
1746
+ TableStyle.MSWORD_FRIENDLY,
1747
+ """
1748
+ | | Field 1 | Field 2 | Field 3 |
1749
+ | 1 | value 1 | value2 | value3 |
1750
+ | 4 | value 4 | value5 | value6 |
1751
+ | 7 | value 7 | value8 | value9 |
1752
+ """,
1753
+ id="MSWORD_FRIENDLY",
1754
+ ),
1755
+ pytest.param(
1756
+ TableStyle.MARKDOWN,
1757
+ TableStyle.ORGMODE,
1758
+ """
1759
+ |---+---------+---------+---------|
1760
+ | | Field 1 | Field 2 | Field 3 |
1761
+ |---+---------+---------+---------|
1762
+ | 1 | value 1 | value2 | value3 |
1763
+ | 4 | value 4 | value5 | value6 |
1764
+ | 7 | value 7 | value8 | value9 |
1765
+ |---+---------+---------+---------|
1766
+ """,
1767
+ id="ORGMODE",
1768
+ ),
1769
+ pytest.param(
1770
+ TableStyle.MARKDOWN,
1771
+ TableStyle.PLAIN_COLUMNS,
1772
+ """
1773
+ Field 1 Field 2 Field 3
1774
+ 1 value 1 value2 value3
1775
+ 4 value 4 value5 value6
1776
+ 7 value 7 value8 value9
1777
+ """, # noqa: W291
1778
+ id="PLAIN_COLUMNS",
1779
+ ),
1780
+ pytest.param(
1781
+ TableStyle.MARKDOWN,
1782
+ TableStyle.RANDOM,
1783
+ """
1784
+ '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
1785
+ % 1 value 1 value2 value3%
1786
+ % 4 value 4 value5 value6%
1787
+ % 7 value 7 value8 value9%
1788
+ '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
1789
+ """,
1790
+ id="RANDOM",
1791
+ ),
1792
+ pytest.param(
1793
+ TableStyle.MARKDOWN,
1794
+ TableStyle.DOUBLE_BORDER,
1795
+ """
1796
+ ╔═══╦═════════╦═════════╦═════════╗
1797
+ ║ ║ Field 1 ║ Field 2 ║ Field 3 ║
1798
+ ╠═══╬═════════╬═════════╬═════════╣
1799
+ ║ 1 ║ value 1 ║ value2 ║ value3 ║
1800
+ ║ 4 ║ value 4 ║ value5 ║ value6 ║
1801
+ ║ 7 ║ value 7 ║ value8 ║ value9 ║
1802
+ ╚═══╩═════════╩═════════╩═════════╝
1803
+ """,
1804
+ id="DOUBLE_BORDER",
1805
+ ),
1806
+ pytest.param(
1807
+ TableStyle.MARKDOWN,
1808
+ TableStyle.SINGLE_BORDER,
1809
+ """
1810
+ ┌───┬─────────┬─────────┬─────────┐
1811
+ │ │ Field 1 │ Field 2 │ Field 3 │
1812
+ ├───┼─────────┼─────────┼─────────┤
1813
+ │ 1 │ value 1 │ value2 │ value3 │
1814
+ │ 4 │ value 4 │ value5 │ value6 │
1815
+ │ 7 │ value 7 │ value8 │ value9 │
1816
+ └───┴─────────┴─────────┴─────────┘
1817
+ """,
1818
+ id="SINGLE_BORDER",
1819
+ ),
1820
+ ],
1821
+ )
1822
+ def test_style_reset(self, original_style, style, expected) -> None:
1823
+ """
1824
+ Testing to ensure that default styling is reset between changes
1825
+ of styles on a PrettyTable
1826
+
1827
+ Args:
1828
+ style (str): Style to be used (Default, markdown, etc)
1829
+ expected (str): The expected format of style as a string representation
1830
+ """
1831
+ # Arrange
1832
+ t = helper_table()
1833
+ random.seed(1234)
1834
+
1835
+ # Act
1836
+ t.set_style(original_style)
1837
+ t.set_style(style)
1838
+
1839
+ # Assert
1840
+ result = t.get_string()
1841
+ assert result.strip() == expected.strip()
1842
+
1715
1843
  @pytest.mark.parametrize(
1716
1844
  "style, expected",
1717
1845
  [
@@ -2354,6 +2482,132 @@ class TestMaxTableWidth:
2354
2482
  +---+-----------------+---+-----------------+---+-----------------+""".strip()
2355
2483
  )
2356
2484
 
2485
+ def test_table_width_on_init_wo_columns(self) -> None:
2486
+ """See also #272"""
2487
+ table = PrettyTable(max_width=10)
2488
+ table.add_row(
2489
+ [
2490
+ "Lorem",
2491
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2492
+ "ipsum",
2493
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2494
+ "dolor",
2495
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2496
+ ]
2497
+ )
2498
+
2499
+ assert (
2500
+ table.get_string().strip()
2501
+ == """
2502
+ +---------+------------+---------+------------+---------+------------+
2503
+ | Field 1 | Field 2 | Field 3 | Field 4 | Field 5 | Field 6 |
2504
+ +---------+------------+---------+------------+---------+------------+
2505
+ | Lorem | Lorem | ipsum | Lorem | dolor | Lorem |
2506
+ | | ipsum | | ipsum | | ipsum |
2507
+ | | dolor sit | | dolor sit | | dolor sit |
2508
+ | | amet, | | amet, | | amet, |
2509
+ | | consetetur | | consetetur | | consetetur |
2510
+ | | sadipscing | | sadipscing | | sadipscing |
2511
+ | | elitr, sed | | elitr, sed | | elitr, sed |
2512
+ | | diam | | diam | | diam |
2513
+ +---------+------------+---------+------------+---------+------------+""".strip()
2514
+ )
2515
+
2516
+ def test_table_width_on_init_with_columns(self) -> None:
2517
+ """See also #272"""
2518
+ table = PrettyTable(
2519
+ ["Field 1", "Field 2", "Field 3", "Field 4", "Field 5", "Field 6"],
2520
+ max_width=10,
2521
+ )
2522
+ table.add_row(
2523
+ [
2524
+ "Lorem",
2525
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2526
+ "ipsum",
2527
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2528
+ "dolor",
2529
+ "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ",
2530
+ ]
2531
+ )
2532
+
2533
+ assert (
2534
+ table.get_string().strip()
2535
+ == """
2536
+ +---------+------------+---------+------------+---------+------------+
2537
+ | Field 1 | Field 2 | Field 3 | Field 4 | Field 5 | Field 6 |
2538
+ +---------+------------+---------+------------+---------+------------+
2539
+ | Lorem | Lorem | ipsum | Lorem | dolor | Lorem |
2540
+ | | ipsum | | ipsum | | ipsum |
2541
+ | | dolor sit | | dolor sit | | dolor sit |
2542
+ | | amet, | | amet, | | amet, |
2543
+ | | consetetur | | consetetur | | consetetur |
2544
+ | | sadipscing | | sadipscing | | sadipscing |
2545
+ | | elitr, sed | | elitr, sed | | elitr, sed |
2546
+ | | diam | | diam | | diam |
2547
+ +---------+------------+---------+------------+---------+------------+""".strip()
2548
+ )
2549
+
2550
+ def test_table_float_formatting_on_init_wo_columns(self) -> None:
2551
+ """See also #243"""
2552
+ table = prettytable.PrettyTable(float_format="10.2")
2553
+ table.field_names = ["Metric", "Initial sol.", "Best sol."]
2554
+ table.add_rows([["foo", 1.0 / 3.0, 1.0 / 3.0]])
2555
+
2556
+ assert (
2557
+ table.get_string().strip()
2558
+ == """
2559
+ +--------+--------------+------------+
2560
+ | Metric | Initial sol. | Best sol. |
2561
+ +--------+--------------+------------+
2562
+ | foo | 0.33 | 0.33 |
2563
+ +--------+--------------+------------+""".strip()
2564
+ )
2565
+
2566
+ def test_table_formatted_html_autoindex(self) -> None:
2567
+ """See also #199"""
2568
+ table = PrettyTable(["Field 1", "Field 2", "Field 3"])
2569
+ for row in range(1, 3 * 3, 3):
2570
+ table.add_row(
2571
+ [f"value {row*100}", f"value {row+1*100}", f"value {row+2*100}"]
2572
+ )
2573
+ table.format = True
2574
+ table.add_autoindex("I")
2575
+
2576
+ assert (
2577
+ table.get_html_string().strip()
2578
+ == """
2579
+ <table frame="box" rules="cols">
2580
+ <thead>
2581
+ <tr>
2582
+ <th style="padding-left: 1em; padding-right: 1em; text-align: center">I</th>
2583
+ <th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 1</th>
2584
+ <th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 2</th>
2585
+ <th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 3</th>
2586
+ </tr>
2587
+ </thead>
2588
+ <tbody>
2589
+ <tr>
2590
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">1</td>
2591
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 100</td>
2592
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 101</td>
2593
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 201</td>
2594
+ </tr>
2595
+ <tr>
2596
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">2</td>
2597
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 400</td>
2598
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 104</td>
2599
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 204</td>
2600
+ </tr>
2601
+ <tr>
2602
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">3</td>
2603
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 700</td>
2604
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 107</td>
2605
+ <td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 207</td>
2606
+ </tr>
2607
+ </tbody>
2608
+ </table>""".strip() # noqa: E501
2609
+ )
2610
+
2357
2611
  def test_max_table_width_wide_vrules_frame(self) -> None:
2358
2612
  table = PrettyTable()
2359
2613
  table.max_table_width = 52
@@ -4,7 +4,7 @@ requires =
4
4
  env_list =
5
5
  lint
6
6
  mypy
7
- py{py3, 313, 312, 311, 310, 39}
7
+ py{py3, 314, 313, 312, 311, 310, 39}
8
8
 
9
9
  [testenv]
10
10
  extras =
@@ -23,7 +23,7 @@ commands =
23
23
  [testenv:lint]
24
24
  skip_install = true
25
25
  deps =
26
- pre-commit
26
+ pre-commit-uv
27
27
  pass_env =
28
28
  PRE_COMMIT_COLOR
29
29
  commands =
File without changes
File without changes
File without changes
File without changes
@@ -34,7 +34,6 @@ __all__ = [
34
34
  "ALL",
35
35
  "DEFAULT",
36
36
  "DOUBLE_BORDER",
37
- "SINGLE_BORDER",
38
37
  "FRAME",
39
38
  "HEADER",
40
39
  "MARKDOWN",
@@ -43,18 +42,19 @@ __all__ = [
43
42
  "ORGMODE",
44
43
  "PLAIN_COLUMNS",
45
44
  "RANDOM",
45
+ "SINGLE_BORDER",
46
46
  "HRuleStyle",
47
47
  "PrettyTable",
48
48
  "RowType",
49
49
  "TableHandler",
50
50
  "TableStyle",
51
51
  "VRuleStyle",
52
+ "__version__",
52
53
  "from_csv",
53
54
  "from_db_cursor",
54
55
  "from_html",
55
56
  "from_html_one",
56
57
  "from_json",
57
- "__version__",
58
58
  ]
59
59
 
60
60