Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thombashi/pytablewriter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0
Choose a base ref
...
head repository: thombashi/pytablewriter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.0
Choose a head ref

Commits on Oct 2, 2023

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    3281eb3 View commit details
  2. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    162b4b7 View commit details
  3. Update docstrings

    thombashi committed Oct 2, 2023
    Copy the full SHA
    68476be View commit details
  4. Copy the full SHA
    afdb5a5 View commit details
  5. Fix type annotations

    thombashi committed Oct 2, 2023
    Copy the full SHA
    5c9d8e4 View commit details

Commits on Oct 7, 2023

  1. Rename a step of CI

    thombashi committed Oct 7, 2023
    Copy the full SHA
    9a2245a View commit details
  2. Refactor steps of CI

    thombashi committed Oct 7, 2023
    Copy the full SHA
    a3b8062 View commit details
  3. Modify concurrency.group

    thombashi committed Oct 7, 2023
    Copy the full SHA
    1dda127 View commit details
  4. Refactoring

    thombashi committed Oct 7, 2023
    Copy the full SHA
    654af51 View commit details
  5. Fix margin and stream to be propagated correctly in from_writer method

        - Fix the output of HtmlTableWriter.write_table method when the method called with write_css=True
    thombashi committed Oct 7, 2023
    Copy the full SHA
    ddf170c View commit details

Commits on Oct 8, 2023

  1. Fix an issue where the CSS output would be incorrect if the HtmlTable…

    …Writer.write_table method was called with `write_css=True` when `table_name` was not specified
    thombashi committed Oct 8, 2023
    Copy the full SHA
    c7c9382 View commit details
  2. Copy the full SHA
    6c78df3 View commit details
  3. Copy the full SHA
    57f1f61 View commit details
  4. Add type annotations

    thombashi committed Oct 8, 2023
    Copy the full SHA
    f60d4b1 View commit details
  5. Update theme_requires

    thombashi committed Oct 8, 2023
    Copy the full SHA
    a216239 View commit details
  6. Update a debug message

    thombashi committed Oct 8, 2023
    Copy the full SHA
    7676457 View commit details
  7. Copy the full SHA
    958182d View commit details
  8. Refactoring

    thombashi committed Oct 8, 2023
    Copy the full SHA
    0ce5bce View commit details
  9. Update __all__

    thombashi committed Oct 8, 2023
    Copy the full SHA
    41d1b5e View commit details
  10. Copy the full SHA
    5f3c3ad View commit details
  11. Copy the full SHA
    dd5bcae View commit details
  12. Copy the full SHA
    8f4193f View commit details
  13. Copy the full SHA
    5c16a5c View commit details
  14. Copy the full SHA
    dca9d00 View commit details
  15. Update docstrings

    thombashi committed Oct 8, 2023
    Copy the full SHA
    b0f3c97 View commit details
  16. Fix a lint error

    thombashi committed Oct 8, 2023
    Copy the full SHA
    45bdc57 View commit details
  17. Change the add_col_separator_style_filter method that raises NotImple…

    …mentedError to debug-log output
    thombashi committed Oct 8, 2023
    Copy the full SHA
    727a82c View commit details
  18. Add an example

    thombashi committed Oct 8, 2023
    Copy the full SHA
    720ab08 View commit details
  19. Copy the full SHA
    2741a9e View commit details
  20. Fix CI

    thombashi committed Oct 8, 2023
    Copy the full SHA
    c2fd536 View commit details
  21. Copy the full SHA
    2911756 View commit details
  22. Update docs

    thombashi committed Oct 8, 2023
    Copy the full SHA
    7243fda View commit details
  23. Update README

    thombashi committed Oct 8, 2023
    Copy the full SHA
    82acd78 View commit details
  24. Modify a test case

    thombashi committed Oct 8, 2023
    Copy the full SHA
    1aa73c9 View commit details
  25. Bump version

    thombashi committed Oct 8, 2023
    Copy the full SHA
    55aaac2 View commit details
Showing with 625 additions and 237 deletions.
  1. +9 −11 .github/workflows/ci.yml
  2. +64 −52 README.rst
  3. +26 −8 docs/make_readme.py
  4. +9 −3 docs/pages/examples/style/theme.txt
  5. +2 −2 docs/pages/examples/table_format/text/markdown/markdown.rst
  6. +2 −2 docs/pages/examples/table_format/text/markdown/md_example_with_style_filter.txt
  7. +1 −0 docs/pages/introduction/dependencies.rst
  8. +1 −0 docs/pages/reference/index.rst
  9. +16 −0 docs/pages/reference/theme.rst
  10. +53 −0 examples/py/logging_example.py
  11. +1 −1 pyproject.toml
  12. +1 −1 pytablewriter/__version__.py
  13. +6 −9 pytablewriter/_factory.py
  14. +1 −1 pytablewriter/sanitizer/_interface.py
  15. +9 −1 pytablewriter/style/__init__.py
  16. +12 −10 pytablewriter/style/_style.py
  17. +40 −12 pytablewriter/style/_theme.py
  18. +107 −22 pytablewriter/writer/_table_writer.py
  19. +2 −1 pytablewriter/writer/binary/_excel.py
  20. +3 −1 pytablewriter/writer/text/__init__.py
  21. +9 −4 pytablewriter/writer/text/_asciidoc.py
  22. +8 −5 pytablewriter/writer/text/_css.py
  23. +18 −10 pytablewriter/writer/text/_html.py
  24. +2 −2 pytablewriter/writer/text/_json.py
  25. +41 −12 pytablewriter/writer/text/_markdown.py
  26. +7 −3 pytablewriter/writer/text/_mediawiki.py
  27. +2 −15 pytablewriter/writer/text/_text_writer.py
  28. +1 −1 requirements/requirements.txt
  29. +5 −1 setup.py
  30. +1 −1 test/test_style.py
  31. +45 −36 test/writer/text/test_css.py
  32. +49 −7 test/writer/text/test_html_writer.py
  33. +24 −0 test/writer/text/test_markdown_writer.py
  34. +3 −1 test/writer/text/test_mediawiki_writer.py
  35. +43 −0 test/writer/text/test_writer.py
  36. +2 −2 tox.ini
20 changes: 9 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:
build-package:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-build
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-build-pkg
cancel-in-progress: true
timeout-minutes: 20
container:
@@ -33,7 +33,7 @@ jobs:
build-docs:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-docs
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-build-docs
cancel-in-progress: true
timeout-minutes: 20
container:
@@ -66,7 +66,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.8"]
python-version:
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8"]
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- os: macos-latest
@@ -90,12 +91,10 @@ jobs:
- name: Install pip
run: python -m pip install --upgrade --disable-pip-version-check "pip>=21.1"

- name: Install dependencies
run: make setup-ci
- run: make setup-ci

- name: Run tests
- run: make test
timeout-minutes: 20
run: tox --verbose -e py

coverage:
runs-on: ubuntu-latest
@@ -117,8 +116,7 @@ jobs:
**/*requirements.txt
tox.ini
- name: Install dependencies
run: make setup-ci
- run: make setup-ci

- name: Run tests
run: tox -e cov
@@ -149,9 +147,9 @@ jobs:
**/*requirements.txt
- name: Install dependencies
run: python -m pip install --upgrade --disable-pip-version-check .[all] jupyter
run: python -m pip install --upgrade --disable-pip-version-check .[all] jupyter tblfaker

- name: Run tests
- name: Run examples
run: |
set -eux
116 changes: 64 additions & 52 deletions README.rst
Original file line number Diff line number Diff line change
@@ -227,54 +227,8 @@ Rendered results can be found at `here <https://github.com/thombashi/pytablewrit

Apply styles to GFM table with programmatically
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can apply styles to specific cells by using style filters.
Style filters will be written as functions.
Example of a style filter function are as follows:

:Sample Code:
.. code-block:: python
from typing import Any, Optional
from pytablewriter import MarkdownTableWriter
from pytablewriter.style import Cell, Style
def style_filter(cell: Cell, **kwargs: Any) -> Optional[Style]:
if cell.is_header_row():
return None
if cell.col == 0:
return Style(font_weight="bold")
value = int(cell.value)
if value > 80:
return Style(fg_color="red", font_weight="bold", decoration_line="underline")
elif value > 50:
return Style(fg_color="yellow", font_weight="bold")
elif value > 20:
return Style(fg_color="green")
return Style(fg_color="lightblue")
writer = MarkdownTableWriter(
table_name="style filter example",
headers=["Key", "Value 1", "Value 2"],
value_matrix=[
["A", 95, 40],
["B", 55, 5],
["C", 30, 85],
["D", 0, 69],
],
flavor="github",
enable_ansi_escape=False,
)
writer.add_style_filter(style_filter)
writer.write_table()
Rendered results can be found at `here <https://github.com/thombashi/pytablewriter/blob/master/docs/pages/examples/output/markdown/style_filter.md>`__
Applying style filters to GFM allows for more flexible style settings for cells.
See also the `example <#style-filter>`_

Write a Markdown table to a stream or a file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -449,7 +403,7 @@ Adding a column of the DataFrame index if you specify ``add_index_column=True``:
|a | 1| 10|
|b | 2| 11|
Write a markdown table from space-separated values
Write a Markdown table from space-separated values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Sample Code:
.. code-block:: python
@@ -626,13 +580,66 @@ You can also set ``Style`` to a specific column with an index or header by using
Style filter
~~~~~~~~~~~~~~
You can apply styles to specific cells by using style filters.
Style filters will be written as Python functions.
Examples of a style filter function and how you apply it are as follows:

:Sample Code:
.. code-block:: python
from typing import Any, Optional
from pytablewriter import MarkdownTableWriter
from pytablewriter.style import Cell, Style
def style_filter(cell: Cell, **kwargs: Any) -> Optional[Style]:
if cell.is_header_row():
return None
if cell.col == 0:
return Style(font_weight="bold")
value = int(cell.value)
if value > 80:
return Style(fg_color="red", font_weight="bold", decoration_line="underline")
elif value > 50:
return Style(fg_color="yellow", font_weight="bold")
elif value > 20:
return Style(fg_color="green")
return Style(fg_color="lightblue")
writer = MarkdownTableWriter(
table_name="style filter example",
headers=["Key", "Value 1", "Value 2"],
value_matrix=[
["A", 95, 40],
["B", 55, 5],
["C", 30, 85],
["D", 0, 69],
],
flavor="github",
enable_ansi_escape=False,
)
writer.add_style_filter(style_filter)
writer.write_table()
Rendered results can be found at `here <https://github.com/thombashi/pytablewriter/blob/master/docs/pages/examples/output/markdown/style_filter.md>`__

Theme
~~~~~~~
Themes consists of a set of style filters.
The following command will install external predefined themes:

::

pip install pytablewriter[theme]

``theme`` argument of writer constructor or ``set_theme`` method can set"" predefined style filters.
Themes can be set via the constructor of the writer classes or the ``set_theme`` method.
The following is an example of setting the ``altrow`` theme via the constructor.
``altrow`` theme will be colored rows alternatively:

:Sample Code:
@@ -654,8 +661,12 @@ The following command will install external predefined themes:
:scale: 100%
:alt: https://github.com/thombashi/pytablewriter-altrow-theme/blob/master/ss/ptw-altrow-theme_example_default.png

Themes can be created as plugins like as follows:
https://github.com/thombashi/pytablewriter-altrow-theme
`[theme]` extras includes the following themes:

- `pytablewriter-altrow-theme <https://github.com/thombashi/pytablewriter-altrow-theme>`__
- `Generated HTML table example <https://thombashi.github.io/pytablewriter-altrow-theme/example.html>`__
- `pytablewriter-altcol-theme <https://github.com/thombashi/pytablewriter-altcol-theme>`__
- `Generated HTML table example <https://thombashi.github.io/pytablewriter-altcol-theme/example.html>`__

Make tables for specific applications
---------------------------------------
@@ -761,6 +772,7 @@ Optional dependencies
- `SimpleSQLite <https://github.com/thombashi/SimpleSQLite>`__
- ``theme`` extras
- `pytablewriter-altrow-theme <https://github.com/thombashi/pytablewriter-altrow-theme>`__
- `pytablewriter-altcol-theme <https://github.com/thombashi/pytablewriter-altcol-theme>`__
- ``toml`` extras
- `toml <https://github.com/uiri/toml>`__

34 changes: 26 additions & 8 deletions docs/make_readme.py
Original file line number Diff line number Diff line change
@@ -5,13 +5,23 @@
"""

import sys
from typing import Final

from path import Path
from readmemaker import ReadmeMaker


PROJECT_NAME = "pytablewriter"
OUTPUT_DIR = ".."
PROJECT_NAME: Final = "pytablewriter"
OUTPUT_DIR: Final = ".."


class Chapter:
STYLE_FILTER: Final = "Style filter"


def make_internal_link(title: str, chapter: str) -> str:
link = chapter.replace(" ", "-").lower()
return f"`{title:s} <#{link:s}>`_"


def write_examples(maker: ReadmeMaker) -> None:
@@ -39,10 +49,11 @@ def write_examples(maker: ReadmeMaker) -> None:
)

maker.write_chapter("Apply styles to GFM table with programmatically")
maker.write_file(
examples_root.joinpath(
"table_format", "text", "markdown", "md_example_with_style_filter.txt"
)
maker.write_lines(
[
"Applying style filters to GFM allows for more flexible style settings for cells.",
"See also the {}".format(make_internal_link("example", Chapter.STYLE_FILTER)),
]
)

with maker.indent():
@@ -71,7 +82,7 @@ def write_examples(maker: ReadmeMaker) -> None:
maker.write_chapter("Write a Markdown table from ``pandas.DataFrame`` instance")
maker.write_file(examples_root.joinpath("datasource", "from_pandas_dataframe_example.txt"))

maker.write_chapter("Write a markdown table from space-separated values")
maker.write_chapter("Write a Markdown table from space-separated values")
maker.write_file(examples_root.joinpath("datasource", "from_ssv_example.txt"))

maker.set_indent_level(1)
@@ -84,7 +95,14 @@ def write_examples(maker: ReadmeMaker) -> None:
maker.write_chapter("Column styles")
maker.write_file(examples_root.joinpath("style", "column_style_example.txt"))

maker.write_chapter("Style filter")
maker.write_chapter(Chapter.STYLE_FILTER)
maker.write_file(
examples_root.joinpath(
"table_format", "text", "markdown", "md_example_with_style_filter.txt"
)
)

maker.write_chapter("Theme")
maker.write_file(examples_root.joinpath("style", "theme.txt"))

maker.set_indent_level(1)
12 changes: 9 additions & 3 deletions docs/pages/examples/style/theme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Themes consists of a set of style filters.
The following command will install external predefined themes:

::

pip install pytablewriter[theme]

``theme`` argument of writer constructor or ``set_theme`` method can set"" predefined style filters.
Themes can be set via the constructor of the writer classes or the ``set_theme`` method.
The following is an example of setting the ``altrow`` theme via the constructor.
``altrow`` theme will be colored rows alternatively:

:Sample Code:
@@ -26,5 +28,9 @@ The following command will install external predefined themes:
:scale: 100%
:alt: https://github.com/thombashi/pytablewriter-altrow-theme/blob/master/ss/ptw-altrow-theme_example_default.png

Themes can be created as plugins like as follows:
https://github.com/thombashi/pytablewriter-altrow-theme
`[theme]` extras includes the following themes:

- `pytablewriter-altrow-theme <https://github.com/thombashi/pytablewriter-altrow-theme>`__
- `Generated HTML table example <https://thombashi.github.io/pytablewriter-altrow-theme/example.html>`__
- `pytablewriter-altcol-theme <https://github.com/thombashi/pytablewriter-altcol-theme>`__
- `Generated HTML table example <https://thombashi.github.io/pytablewriter-altcol-theme/example.html>`__
4 changes: 2 additions & 2 deletions docs/pages/examples/table_format/text/markdown/markdown.rst
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@ GitHub flavored Markdown (GFM)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: md_example_with_flavor.txt

Apply styles to GFM table with programmatically
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apply styles to GFM table with programmatically (style filter)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: md_example_with_style_style.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
You can apply styles to specific cells by using style filters.
Style filters will be written as functions.
Example of a style filter function are as follows:
Style filters will be written as Python functions.
Examples of a style filter function and how you apply it are as follows:

:Sample Code:
.. code-block:: python
1 change: 1 addition & 0 deletions docs/pages/introduction/dependencies.rst
Original file line number Diff line number Diff line change
@@ -21,5 +21,6 @@ Optional dependencies
- `SimpleSQLite <https://github.com/thombashi/SimpleSQLite>`__
- ``theme`` extras
- `pytablewriter-altrow-theme <https://github.com/thombashi/pytablewriter-altrow-theme>`__
- `pytablewriter-altcol-theme <https://github.com/thombashi/pytablewriter-altcol-theme>`__
- ``toml`` extras
- `toml <https://github.com/uiri/toml>`__
1 change: 1 addition & 0 deletions docs/pages/reference/index.rst
Original file line number Diff line number Diff line change
@@ -9,4 +9,5 @@ Reference
table_format
style
function
theme
error
16 changes: 16 additions & 0 deletions docs/pages/reference/theme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Theme
---------------

.. autoclass:: pytablewriter.style.StyleFilterFunc
:members:
:undoc-members:
:special-members: __call__

.. autoclass:: pytablewriter.style.ColSeparatorStyleFilterFunc
:members:
:undoc-members:
:special-members: __call__

.. autoclass:: pytablewriter.style.Theme
:members:
:undoc-members:
Loading