From 30be1b1c6dcb36aa1cc241f2bcce7586d7d36533 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 26 Jun 2022 13:51:13 -0600 Subject: [PATCH 1/5] docs: Updated docs and added col width test --- table2ascii/table_to_ascii.py | 2 +- tests/test_column_widths.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/table2ascii/table_to_ascii.py b/table2ascii/table_to_ascii.py index b344b81..3f77d89 100644 --- a/table2ascii/table_to_ascii.py +++ b/table2ascii/table_to_ascii.py @@ -327,7 +327,7 @@ def table2ascii( footer (:class:`Optional[List[Any]]`): List of column values in the table's footer row first_col_heading (:class:`bool`): Whether to add a header column separator after the first column last_col_heading (:class:`bool`): Whether to add a header column separator before the last column - column_widths (:class:`List[int]`): List of widths in characters for each column (defaults to auto-sizing) + column_widths (:class:`Optional[List[int]]`): List of widths in characters for each column (``None`` for auto-sizing) alignments (:class:`List[Alignment]`): List of alignments (ex. `[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]`) style (:class:`TableStyle`): Table style to use for styling (preset styles can be imported) diff --git a/tests/test_column_widths.py b/tests/test_column_widths.py index feecfc0..f7b367d 100644 --- a/tests/test_column_widths.py +++ b/tests/test_column_widths.py @@ -25,6 +25,28 @@ def test_column_widths(): assert text == expected +def test_column_widths_none(): + text = t2a( + header=["#", "G", "H", "R", "S"], + body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], + footer=["TOTL", "130", "140", "135", "130"], + first_col_heading=True, + last_col_heading=True, + column_widths=None, + ) + expected = ( + "╔══════╦═════════════════╦═════╗\n" + "║ # ║ G H R ║ S ║\n" + "╟──────╫─────────────────╫─────╢\n" + "║ 1 ║ 30 40 35 ║ 30 ║\n" + "║ 2 ║ 30 40 35 ║ 30 ║\n" + "╟──────╫─────────────────╫─────╢\n" + "║ TOTL ║ 130 140 135 ║ 130 ║\n" + "╚══════╩═════════════════╩═════╝" + ) + assert text == expected + + def test_wrong_number_column_widths(): with pytest.raises(ValueError): t2a( From dfd3ce119f66e2136963eab8710be507817e5b17 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 26 Jun 2022 13:51:53 -0600 Subject: [PATCH 2/5] ci: Remove ignore warnings, add pytest as a dev dep --- pyproject.toml | 2 +- setup.py | 2 +- task.env | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 task.env diff --git a/pyproject.toml b/pyproject.toml index e529124..f480e66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ docs = { cmd = "cd docs && sphinx-autobuild source _build/html --ignore _build - isort = { cmd = "task lint isort", help = "Run isort" } lint = { cmd = "pre-commit run --all-files", help = "Check all files for linting errors" } precommit = { cmd = "pre-commit install --install-hooks", help = "Install the precommit hook" } -pyright = { cmd = "dotenv -f task.env run -- pyright", help = "Run pyright" } +pyright = { cmd = "pyright", help = "Run pyright" } slotscheck = { cmd = "python -m slotscheck --verbose -m table2ascii", help = "Run slotscheck" } diff --git a/setup.py b/setup.py index 66a8e5d..c4f622c 100644 --- a/setup.py +++ b/setup.py @@ -45,9 +45,9 @@ def requirements(): "pre-commit==2.18.1", "taskipy==1.10.1", "slotscheck==0.14.0", - "python-dotenv==0.20.0", "pyright==1.1.244", "tox==3.24.5", + "pytest==7.1.2", ], } diff --git a/task.env b/task.env deleted file mode 100644 index b0e60a2..0000000 --- a/task.env +++ /dev/null @@ -1 +0,0 @@ -PYRIGHT_PYTHON_IGNORE_WARNINGS=1 \ No newline at end of file From 9aee4ff12817443753dca31b270257a24e297cb8 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 26 Jun 2022 13:56:02 -0600 Subject: [PATCH 3/5] pyright on tests, remove unused imports --- pyproject.toml | 1 + tests/test_alignments.py | 4 ++-- tests/test_convert.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f480e66..5765b72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ require-subclass = false typeCheckingMode = "basic" include = [ "table2ascii", + "tests", "*.py", ] pythonVersion = "3.7" diff --git a/tests/test_alignments.py b/tests/test_alignments.py index 555f0b6..b0c18b2 100644 --- a/tests/test_alignments.py +++ b/tests/test_alignments.py @@ -1,6 +1,6 @@ import pytest -from table2ascii import Alignment, alignment, table2ascii as t2a +from table2ascii import Alignment, table2ascii as t2a def test_first_left_four_right(): @@ -42,7 +42,7 @@ def test_invalid_alignments(): body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], footer=["SUM", "130", "140", "135", "130"], first_col_heading=True, - alignments=[9999, -1, Alignment.RIGHT, Alignment.CENTER, Alignment.RIGHT], + alignments=[9999, -1, Alignment.RIGHT, Alignment.CENTER, Alignment.RIGHT], # type: ignore ) diff --git a/tests/test_convert.py b/tests/test_convert.py index cb67a03..5c0653a 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -1,6 +1,6 @@ import pytest -from table2ascii import alignment, table2ascii as t2a +from table2ascii import table2ascii as t2a def test_header_body_footer(): From 4a985aaa413ce42a24c126650338f923e67b57d1 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 26 Jun 2022 14:12:07 -0600 Subject: [PATCH 4/5] Add test task --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 5765b72..c79dcf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +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" } [tool.slotscheck] From ca463784cb4b127037a4c111cc95e5b6292847f4 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 26 Jun 2022 14:12:18 -0600 Subject: [PATCH 5/5] Add CONTRIBUTING.md and update docs --- CONTRIBUTING.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 12 +++------ 2 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..91b025b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,69 @@ +## Contributing Guidelines + +Contributions are welcome! Feel free to open an issue or submit a pull request if you have a way to improve this project. + +Make sure your request is meaningful and you have tested the app locally before submitting a pull request. + +### Installing Requirements + +#### Software Requirements + +- [Python 3.7+](https://www.python.org/downloads/) + +#### Development Dependencies + +Install development dependencies with: + +```bash +pip install -e ".[dev]" +``` + +Install documentation dependencies with: + +```bash +pip install -e ".[docs]" +``` + +### Running the Tests + +Run the following command to run the [Tox](https://github.com/tox-dev/tox) test script which will verify that the tested functionality is still working. + +```bash +task test +``` + +### Linting + +Black, isort, and pre-commit hooks are used to lint the codebase. Run the following command to lint and fix the codebase. + +```bash +task lint +``` + +### Pyright + +To ensure that type hints are used correctly, Pyright is used to lint the codebase. Run the following command to check for typing errors. + +```bash +task pyright +``` + +### Documentation + +To view the documentation locally, run the following command. + +```bash +task docs +``` + +The documentation will be served at . + +### Need some help regarding the basics? + +You can refer to the following articles on the basics of Git and GitHub in case you are stuck: + +- [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) +- [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-an-issue-or-pull-request) +- [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github) +- [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6) +- [Learn GitHub from Scratch](https://lab.github.com/githubtraining/introduction-to-github) \ No newline at end of file diff --git a/README.md b/README.md index 5a1da1d..e6ec014 100644 --- a/README.md +++ b/README.md @@ -176,14 +176,8 @@ All parameters are optional. ![image](https://user-images.githubusercontent.com/20955511/116204490-802dcf80-a745-11eb-9b4a-7cef49f23958.png) -## 🧰 Development +## 🤗 Contributing -Install development dependencies with `pip install -e .[dev]` +Contributions are welcome! -### Running tests - -Run tests with the command `tox` - -### Linting - -Run `task lint` to lint with black, isort, and pre-commit hooks. +See [CONTRIBUTING.md](https://github.com/DenverCoder1/table2ascii/blob/main/CONTRIBUTING.md) for more details on how to get involved.