From 8c66cd61296fe2a6d65fdb3769fe0c3e30114d1c Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:34:11 -0700 Subject: [PATCH 01/12] refactor: New annotation style, --- table2ascii/options.py | 7 ++++--- table2ascii/table_to_ascii.py | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/table2ascii/options.py b/table2ascii/options.py index bb2ac6e..998edbd 100644 --- a/table2ascii/options.py +++ b/table2ascii/options.py @@ -1,5 +1,6 @@ +from __future__ import annotations + from dataclasses import dataclass -from typing import List, Optional from .alignment import Alignment from .table_style import TableStyle @@ -11,7 +12,7 @@ class Options: first_col_heading: bool last_col_heading: bool - column_widths: Optional[List[Optional[int]]] - alignments: Optional[List[Alignment]] + column_widths: list[int | None] | None + alignments: list[Alignment] | None cell_padding: int style: TableStyle diff --git a/table2ascii/table_to_ascii.py b/table2ascii/table_to_ascii.py index 8835e61..f30cc97 100644 --- a/table2ascii/table_to_ascii.py +++ b/table2ascii/table_to_ascii.py @@ -1,5 +1,6 @@ +from __future__ import annotations + from math import ceil, floor -from typing import Callable, List, Optional, Union from .alignment import Alignment from .annotations import SupportsStr @@ -13,9 +14,9 @@ class TableToAscii: def __init__( self, - header: Optional[List[SupportsStr]], - body: Optional[List[List[SupportsStr]]], - footer: Optional[List[SupportsStr]], + header: list[SupportsStr] | None, + body: list[list[SupportsStr]] | None, + footer: list[SupportsStr] | None, options: Options, ): """ @@ -92,7 +93,7 @@ def __count_columns(self) -> int: return len(self.__body[0]) return 0 - def __auto_column_widths(self) -> List[int]: + def __auto_column_widths(self) -> list[int]: """ Get the minimum number of characters needed for the values in each column in the table with 1 space of padding on each side. @@ -151,7 +152,7 @@ def __row_to_ascii( heading_col_sep: str, column_seperator: str, right_edge: str, - filler: Union[str, List], + filler: str | list[SupportsStr], ) -> str: """ Assembles a line of text in the ascii table @@ -235,7 +236,7 @@ def __bottom_edge_to_ascii(self) -> str: filler=self.__style.top_and_bottom_edge, ) - def __heading_row_to_ascii(self, row: List) -> str: + def __heading_row_to_ascii(self, row: list[SupportsStr]) -> str: """ Assembles the header or footer row line of the ascii table @@ -265,7 +266,7 @@ def __heading_sep_to_ascii(self) -> str: filler=self.__style.heading_row_sep, ) - def __body_to_ascii(self, body: List[List[SupportsStr]]) -> str: + def __body_to_ascii(self, body: list[list[SupportsStr]]) -> str: """ Assembles the body of the ascii table @@ -317,14 +318,14 @@ def to_ascii(self) -> str: def table2ascii( - header: Optional[List[SupportsStr]] = None, - body: Optional[List[List[SupportsStr]]] = None, - footer: Optional[List[SupportsStr]] = None, + header: list[SupportsStr] | None = None, + body: list[list[SupportsStr]] | None = None, + footer: list[SupportsStr] | None = None, *, first_col_heading: bool = False, last_col_heading: bool = False, - column_widths: Optional[List[Optional[int]]] = None, - alignments: Optional[List[Alignment]] = None, + column_widths: list[int | None] | None = None, + alignments: list[Alignment] | None = None, cell_padding: int = 1, style: TableStyle = PresetStyle.double_thin_compact, ) -> str: From 7fa26c1ab67e4b79981e60d5583816a2ba331f2f Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:34:29 -0700 Subject: [PATCH 02/12] ci: Add Python versions to tox test --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 7b01ad7..d505b52 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,8 @@ [tox] -envlist = python3.9 +envlist = py37, py38, py39, py310, py311 [testenv] -deps = pytest +deps = + pytest + -rrequirements.txt commands = pytest tests -s From b31b2124b2418b28b9baab6217c18657397eefd5 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:35:03 -0700 Subject: [PATCH 03/12] ci: Refactor workflow dependency installation --- .github/workflows/lint.yml | 4 ++-- .github/workflows/python-test.yml | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 33ce501..1a23962 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,7 +49,7 @@ jobs: setup.py - name: Install dependencies - run: python -m pip install -r requirements.txt -e ".[dev]" -e ".[docs]" + run: python -m pip install -r requirements.txt -e ".[dev]" - name: Set up pyright run: echo "PYRIGHT_VERSION=$(python -c 'import pyright; print(pyright.__pyright_version__)')" >> $GITHUB_ENV @@ -94,7 +94,7 @@ jobs: setup.py - name: Install dependencies - run: python -m pip install -r requirements.txt -e ".[dev]" -e ".[docs]" + run: python -m pip install -r requirements.txt -e ".[dev]" - name: Run mypy run: mypy . diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 95dc2dc..c7a899f 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -25,8 +25,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8==3.8.4 pytest tox - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + python -m pip install -r requirements.txt -e ".[dev]" - name: Test with pytest - run: | - tox + run: task test From f9c3cea124e866485f123daf3bbbf07109f9fab0 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:35:23 -0700 Subject: [PATCH 04/12] ci: Update task test command --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e85aafc..be64300 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ lint = { cmd = "pre-commit run --all-files", help = "Check all files for linting precommit = { cmd = "pre-commit install --install-hooks", help = "Install the precommit hook" } pyright = { cmd = "pyright", help = "Run pyright" } slotscheck = { cmd = "python -m slotscheck --verbose -m table2ascii", help = "Run slotscheck" } -test = { cmd = "tox", help = "Run tests" } +test = { cmd = "tox --skip-missing-interpreters", help = "Run tests" } [tool.slotscheck] From 285cd0648e078aaa02562c7cfa92f9b7f9f795fd Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:36:07 -0700 Subject: [PATCH 05/12] chore: Fix requirement markers to be more specific --- requirements.txt | 2 +- setup.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index e1631f0..4037efa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -typing_extensions>=4.0.0,<5 \ No newline at end of file +typing-extensions>=3.7.4; python_version<'3.8' \ No newline at end of file diff --git a/setup.py b/setup.py index 6cf7af7..1647b0d 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import re from setuptools import setup -from setuptools.command.test import test as Command def version(): @@ -76,7 +75,7 @@ def requirements(): ], keywords="table ascii unicode formatter", python_requires=">=3.6", - install_requires=[requirements()], + install_requires=requirements(), extras_require=extras_require, setup_requires=[ "flake8>=3.8,<4", From 5dabb0351b9cbdef7b85b75255989286d7ad8a96 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:39:21 -0700 Subject: [PATCH 06/12] ci: Add back docs to mypy dependencies --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1a23962..25d8c88 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -94,7 +94,7 @@ jobs: setup.py - name: Install dependencies - run: python -m pip install -r requirements.txt -e ".[dev]" + run: python -m pip install -r requirements.txt -e ".[dev]" -e ".[docs]" - name: Run mypy run: mypy . From a98b3561ddc4cf149e4220021677285cdc8cd0e1 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:43:27 -0700 Subject: [PATCH 07/12] ci: Update default Python version to 3.11 --- .github/workflows/lint.yml | 2 +- .github/workflows/python-publish.yml | 2 +- .github/workflows/python-update-docs.yml | 2 +- pyproject.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 25d8c88..7381f37 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -80,7 +80,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10"] + python-version: ["3.11"] steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 298ac19..43faf95 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.10' + python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-update-docs.yml b/.github/workflows/python-update-docs.yml index 4932ae5..fef1707 100644 --- a/.github/workflows/python-update-docs.yml +++ b/.github/workflows/python-update-docs.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ['3.11'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index be64300..1c5a9d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,7 @@ reportUnnecessaryTypeIgnoreComment = true [tool.mypy] -python_version = "3.10" +python_version = "3.11" namespace_packages = true From 5ae71e0b7295e3d8d802aa9392a5f19fb0f9cff9 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:46:49 -0700 Subject: [PATCH 08/12] ci: Test on Python 3.7-3.11 --- .github/workflows/python-publish.yml | 4 ++-- .github/workflows/python-test.yml | 11 +++++++---- .github/workflows/python-update-docs.yml | 6 +++--- .github/workflows/test-docs.yml | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 43faf95..caf5831 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,9 +13,9 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.11' - name: Install dependencies diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index c7a899f..0c0d247 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -16,12 +16,15 @@ jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-update-docs.yml b/.github/workflows/python-update-docs.yml index fef1707..1d3c231 100644 --- a/.github/workflows/python-update-docs.yml +++ b/.github/workflows/python-update-docs.yml @@ -16,9 +16,9 @@ jobs: matrix: python-version: ['3.11'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -28,7 +28,7 @@ jobs: - name: execute script run: | python ./docs/source/generate_style_list.py - - uses: EndBug/add-and-commit@v8 + - uses: EndBug/add-and-commit@v9 with: default_author: github_actions message: 'docs: update style list' diff --git a/.github/workflows/test-docs.yml b/.github/workflows/test-docs.yml index ede4b76..e4263f6 100644 --- a/.github/workflows/test-docs.yml +++ b/.github/workflows/test-docs.yml @@ -16,9 +16,9 @@ jobs: matrix: python-version: ['3.7'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 798a55f1078a92a67387fa0c2d01f1d97f3a438f Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:54:09 -0700 Subject: [PATCH 09/12] ci: Test one environment at a time --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 0c0d247..fbf37d9 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -30,4 +30,4 @@ jobs: python -m pip install --upgrade pip python -m pip install -r requirements.txt -e ".[dev]" - name: Test with pytest - run: task test + run: tox -e "py${{ matrix.python-version//. }}" From ca7cae42fa9927d530567b889ad9e758f8ddcedb Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:56:36 -0700 Subject: [PATCH 10/12] Update python-test.yml --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index fbf37d9..47661dc 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -30,4 +30,4 @@ jobs: python -m pip install --upgrade pip python -m pip install -r requirements.txt -e ".[dev]" - name: Test with pytest - run: tox -e "py${{ matrix.python-version//. }}" + run: tox -e "py${{ matrix.python-version//./ }}" From bbc46fdd4f55de5aa2fd317006f2323cff2852b0 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 10 Dec 2022 23:59:39 -0700 Subject: [PATCH 11/12] Update python-test.yml --- .github/workflows/python-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 47661dc..7694a92 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -30,4 +30,6 @@ jobs: python -m pip install --upgrade pip python -m pip install -r requirements.txt -e ".[dev]" - name: Test with pytest - run: tox -e "py${{ matrix.python-version//./ }}" + run: | + # remove '.' in python-version and prepend with 'py' to get the correct tox env + tox -e py$(echo ${{ matrix.python-version }} | sed 's/\.//g') From 26e6c378e1f617a5338ab30b0466d1916b080b7b Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 11 Dec 2022 00:02:24 -0700 Subject: [PATCH 12/12] Use 3.11 for testing docs --- .github/workflows/test-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-docs.yml b/.github/workflows/test-docs.yml index e4263f6..4eba722 100644 --- a/.github/workflows/test-docs.yml +++ b/.github/workflows/test-docs.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7'] + python-version: ['3.11'] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }}