Skip to content

Commit b60bc59

Browse files
chore: Configure Poe the Poet (#19)
2 parents a4ab69b + 4d9aafb commit b60bc59

5 files changed

Lines changed: 105 additions & 43 deletions

File tree

.github/hooks/pre-commit

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
#!/bin/sh
22

3-
black_formatting_results=$(poetry run black --check --line-length 100 . 2>&1 > /dev/null)
3+
formatting_results=$(poe format 2>&1 > /dev/null)
44
if [[ "$?" == "0" ]]; then
5-
echo "Source Code Formatting"
5+
echo "✅ Formatting"
66
else
7-
echo "Source Code Formatting"
8-
echo "$black_formatting_results"
7+
echo "❌ Formatting"
8+
echo "$formatting_results"
99
exit 1
1010
fi
1111

12-
prettier_formatting_results=$(npx --yes prettier@3.0.3 . --no-config --check --log-level warn 2>&1 >/dev/null)
13-
if [[ "$?" == "0" ]]; then
14-
echo "✅ Supplemental Code Formatting"
15-
else
16-
echo "❌ Supplemental Code Formatting"
17-
echo "$prettier_formatting_results"
18-
exit 1
19-
fi
20-
21-
linting_results=$(poetry run pylint src tests)
12+
linting_results=$(poe lint 2>&1 > /dev/null)
2213
if [[ "$?" == "0" ]]; then
2314
echo "✅ Linting"
2415
else
@@ -27,11 +18,11 @@ else
2718
exit 1
2819
fi
2920

30-
test_results=$(poetry run pytest tests/unit tests/integration --cov=src/package_name --cov-fail-under=90 --no-header --no-summary -qq --cov=src/package_name --cov-report term-missing:skip-covered --cov-branch --cov-fail-under=90)
21+
test_results=$(poe test)
3122
if [[ "$?" == "0" ]]; then
32-
echo "Unit/Integration Tests"
23+
echo "Test Coverage"
3324
else
34-
echo "Unit/Integration Tests"
25+
echo "Test Coverage"
3526
echo "$test_results"
3627
exit 1
3728
fi

.github/hooks/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
test_results=$(poetry run pytest --no-header -qq tests/e2e)
3+
test_results=$(poe test-e2e)
44
if [[ "$?" == "0" ]]; then
55
echo "✅ End-to-End Tests"
66
else

README.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## 🎧 Quick Start
1414

15-
Ensure [Python](https://www.python.org/downloads) and [Python Poetry](https://python-poetry.org/docs/#installation) are installed.
15+
Ensure [Python](https://www.python.org/downloads), [Python Poetry](https://python-poetry.org/docs/#installation), and [Poe the Poet](https://poethepoet.natn.io/installation.html) are installed.
1616

1717
Dependency installation is managed via `poetry`. Once cloned, you can install dependencies from the project root:
1818

@@ -28,26 +28,6 @@ poetry run package-name
2828

2929
And boom! You're ready to customize a Python project! 🎉
3030

31-
## 🧪 Running Tests
32-
33-
[`pytest`](https://docs.pytest.org/en/7.4.x/) is used as a test runner and its configuration can be found in the `tool.pytest.ini_options` section of [pyproject.toml](./pyproject.toml). [`pytest-cov`](https://pytest-cov.readthedocs.io/en/latest/index.html) is used as a coverage reporter.
34-
35-
Running `pytest` with no arguments will:
36-
37-
- Automatically add `src` to `PYTHONPATH` (pythonpath: `src`)
38-
- Only run unit tests (testpaths: `tests/unit/package_name`)
39-
- Increase verbosity (`-vv`)
40-
- Calculate coverage (using `pytest-cov`) and display any modules missing coverage
41-
42-
You can specify different paths to run different groupings of tests:
43-
44-
```shell
45-
pytest tests/unit # Run unit tests
46-
pytest tests/integration # Run integration tests
47-
pytest tests/e2e # Run end-to-end tests
48-
pytest tests # Run all tests
49-
```
50-
5131
## Configuring Developer Standards
5232

5333
Use `git` to install commit message, pre-commit, and pre-push commit hooks:
@@ -61,6 +41,50 @@ These will ensure commit messages are consistent, code is correctly formatted an
6141

6242
Style decisions are based on the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html).
6343

44+
## 🧑🏽‍💻 Running Project Tasks
45+
46+
[`poe`](https://poethepoet.natn.io/index.html) is used as a task runner and its configuration can be found in the `tool.poe.tasks*` sections of [pyproject.toml](./pyproject.toml).
47+
48+
| Command | Summary | Bash Equivalent |
49+
| ---------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50+
| `poe test` | Run application test suites that support coverage | `PYTHONPATH=src poetry run pytest -vv --import-mode=importlib --cov=src/package_name --cov-fail-under=90 --cov=src/package_name --cov-branch --cov-report term-missing:skip-covered tests/unit tests/integration` |
51+
| `poe test-all` | Run all tests (without coverage) | `PYTHONPATH=src pytest -vv --import-mode=importlib` |
52+
| `poe test-e2e` | Run e2e tests only | `PYTHONPATH=src poetry run pytest -vv --import-mode=importlib tests/e2e` |
53+
| `poe test-integration` | Run integration tests only (with coverage) | `PYTHONPATH=src poetry run pytest -vv --import-mode=importlib --cov=src/package_name --cov-fail-under=90 --cov=src/package_name --cov-branch --cov-report term-missing:skip-covered tests/integration` |
54+
| `poe test-unit` | Run unit tests only (without coverage) | `PYTHONPATH=src poetry run pytest -vv --import-mode=importlib tests/unit` |
55+
| `poe check` | Run all formatting and linting tools against codebase | `poetry run black --check --line-length 100 . && npx --yes prettier@3.0.3 . --no-config --check && poetry run pylint src tests` |
56+
| `poe format` | Run all formatting tools against codebase | `poetry run black --check --line-length 100 . && npx --yes prettier@3.0.3 . --no-config --check` |
57+
| `poe format-black` | Run black against Python source code | `poetry run black --check --line-length 100 .` |
58+
| `poe format-prettier` | Run prettier against non-Python code | `npx --yes prettier@3.0.3 . --no-config --check` |
59+
| `poe lint` | Run all linting tools against codebase | `poetry run pylint src tests` |
60+
| `poe lint-pylint` | Lint Python source code and tests with pylint | `poetry run pylint src tests` |
61+
62+
## 🧪 Testing Configuration
63+
64+
[`pytest`](https://docs.pytest.org/en/7.4.x/) is used as a test runner and its configuration can be found in the `tool.pytest.ini_options` section of [pyproject.toml](./pyproject.toml). [`pytest-cov`](https://pytest-cov.readthedocs.io/en/latest/index.html) is used as a coverage reporter.
65+
66+
Running `pytest` with no arguments will:
67+
68+
- Automatically add `src` to the `PYTHONPATH` (pythonpath: `src`)
69+
- Increase verbosity (`-vv`)
70+
- Override pytest's historical default import mode to `importlib` which is recommended for new projects (`--import-mode=importlib`)
71+
- Run all available test items in [`./tests/`](./tests)
72+
73+
Tests are grouped into suites using different path names:
74+
75+
```shell
76+
tests/
77+
├── conftest.py
78+
├── ci/
79+
│ └── ...
80+
├── e2e/
81+
│ └── ...
82+
├── integration/
83+
│ └── ...
84+
└── unit/
85+
└── ...
86+
```
87+
6488
## 🪪 License
6589

6690
This tool is [MIT licensed](./LICENSE).

pyproject.toml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,59 @@ disable = ["missing-module-docstring"]
4545
[tool.pytest.ini_options]
4646
minversion = "7.4.0"
4747
pythonpath = "src"
48-
testpaths = ["tests/unit", "tests/integration"]
4948
addopts = "-vv --import-mode=importlib"
5049

5150
[tool.poetry.scripts]
5251
package-name = "package_name.cli:run"
5352

53+
[tool.poe.tasks.test]
54+
help = "Default: Run application test suites that support coverage"
55+
sequence = ["test-coverage"]
56+
57+
[tool.poe.tasks.test-all]
58+
help = "Run all application test suites"
59+
sequence = ["test-unit", "test-integration", "test-e2e"]
60+
61+
[tool.poe.tasks.test-coverage]
62+
help = "Run application test suites that support coverage"
63+
cmd = "pytest --cov=src/package_name --cov-fail-under=90 --cov=src/package_name --cov-branch --cov-report term-missing:skip-covered tests/unit tests/integration"
64+
65+
[tool.poe.tasks.test-e2e]
66+
help = "Run e2e tests only"
67+
cmd = "pytest tests/e2e"
68+
69+
[tool.poe.tasks.test-integration]
70+
help = "Run integration tests only (with coverage)"
71+
cmd = "pytest --cov=src/package_name --cov-fail-under=90 --cov=src/package_name --cov-branch --cov-report term-missing:skip-covered tests/integration"
72+
73+
[tool.poe.tasks.test-unit]
74+
help = "Run unit tests only (without coverage)"
75+
cmd = "pytest tests/unit"
76+
77+
[tool.poe.tasks.check]
78+
help = "Check code quality"
79+
sequence = ["format", "lint"]
80+
81+
[tool.poe.tasks.lint]
82+
help = "Run all linting tools against codebase"
83+
sequence = ["lint-pylint"]
84+
85+
[tool.poe.tasks.lint-pylint]
86+
help = "Lint Python source code and tests with pylint"
87+
cmd = "pylint --verbose --score y src tests"
88+
89+
[tool.poe.tasks.format]
90+
help = "Run all formatting tools against codebase"
91+
sequence = ["format-black", "format-prettier"]
92+
93+
[tool.poe.tasks.format-black]
94+
help = "Run black against Python source code"
95+
cmd = "black --check --line-length 100 ."
96+
97+
[tool.poe.tasks.format-prettier]
98+
help = "Run prettier against non-Python code"
99+
cmd = "npx --yes prettier@3.0.3 . --no-config --check"
100+
54101
[build-system]
55102
requires = ["poetry-core"]
56103
build-backend = "poetry.core.masonry.api"

tests/e2e/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def test_cli_default() -> None:
15-
output = os.popen("poetry run package-name").read()
15+
output = os.popen("package-name").read()
1616

1717
assert output == (
1818
"usage: package-name [-h] [--version] [--zen]\n\n"
@@ -25,14 +25,14 @@ def test_cli_default() -> None:
2525

2626

2727
def test_cli_zen_flag() -> None:
28-
output = os.popen("poetry run package-name --zen").read()
28+
output = os.popen("package-name --zen").read()
2929

3030
assert output.endswith(".\n"), "should return zen sentence"
3131
assert "usage" not in output, "should not print usage"
3232

3333

3434
def test_cli_version_flag() -> None:
35-
output = os.popen("poetry run package-name --version").read()
35+
output = os.popen("package-name --version").read()
3636

3737
match = re.match(SEMVAR_PATTERN, output.strip())
3838
assert match is not None, "should print a semvar-compliant version"

0 commit comments

Comments
 (0)