Skip to content

refactor: New annotation style and dependency specificity #61

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

Merged
merged 12 commits into from
Dec 11, 2022
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
8 changes: 4 additions & 4 deletions .github/workflows/python-update-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
6 changes: 3 additions & 3 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -70,7 +70,7 @@ reportUnnecessaryTypeIgnoreComment = true


[tool.mypy]
python_version = "3.10"
python_version = "3.11"
namespace_packages = true


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
typing_extensions>=4.0.0,<5
typing-extensions>=3.7.4; python_version<'3.8'
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re

from setuptools import setup
from setuptools.command.test import test as Command


def version():
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions table2ascii/options.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
27 changes: 14 additions & 13 deletions table2ascii/table_to_ascii.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
):
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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