diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 33ce501..7381f37 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 @@ -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..caf5831 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,11 +13,11 @@ 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.10' + python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 95dc2dc..7694a92 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -16,17 +16,20 @@ 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 - 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 + # remove '.' in python-version and prepend with 'py' to get the correct tox env + tox -e py$(echo ${{ matrix.python-version }} | sed 's/\.//g') diff --git a/.github/workflows/python-update-docs.yml b/.github/workflows/python-update-docs.yml index 4932ae5..1d3c231 100644 --- a/.github/workflows/python-update-docs.yml +++ b/.github/workflows/python-update-docs.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + 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..4eba722 100644 --- a/.github/workflows/test-docs.yml +++ b/.github/workflows/test-docs.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7'] + 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 diff --git a/pyproject.toml b/pyproject.toml index e85aafc..1c5a9d5 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] @@ -70,7 +70,7 @@ reportUnnecessaryTypeIgnoreComment = true [tool.mypy] -python_version = "3.10" +python_version = "3.11" namespace_packages = true 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", 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: 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