Skip to content

ci,docs: Add Pyright checks to tests, add contributing docs #37

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 5 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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 <http://127.0.0.1:8888>.

### 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)
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ 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" }
test = { cmd = "tox", help = "Run tests" }


[tool.slotscheck]
Expand All @@ -45,6 +46,7 @@ require-subclass = false
typeCheckingMode = "basic"
include = [
"table2ascii",
"tests",
"*.py",
]
pythonVersion = "3.7"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}

Expand Down
2 changes: 1 addition & 1 deletion table2ascii/table_to_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion task.env

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_alignments.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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
)


Expand Down
22 changes: 22 additions & 0 deletions tests/test_column_widths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from table2ascii import alignment, table2ascii as t2a
from table2ascii import table2ascii as t2a


def test_header_body_footer():
Expand Down