Skip to content

Commit c1c2cdc

Browse files
committed
Update
1 parent e43397b commit c1c2cdc

File tree

9 files changed

+84
-53
lines changed

9 files changed

+84
-53
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
os: [ubuntu-latest, windows-latest]
25-
python-version: ["3.10"] # ["3.7", "3.8", "3.9", "3.10"]
25+
python-version: ["3.7", "3.8", "3.9", "3.10"]
2626

2727
runs-on: ${{ matrix.os }}
2828

@@ -38,11 +38,11 @@ jobs:
3838
- name: Install dependencies
3939
run: |
4040
python -m pip install --upgrade pip
41-
pip install codecov tox tox-gh-actions
41+
pip install codecov tox
4242
4343
# with "-e py" tox runs the python version of the current environment
4444
- name: Unittests with tox
45-
run: tox # -e py
45+
run: tox -e py
4646

4747
# Coverage does not work for private repos
4848
- name: Upload coverage to Codecov

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ repos:
3333
rev: 22.10.0
3434
hooks:
3535
- id: black
36+
37+
- repo: https://github.com/pre-commit/mirrors-mypy
38+
rev: v0.991
39+
hooks:
40+
- id: mypy
41+
additional_dependencies: [types-all]

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ I tried to incorporate most "best practices" but in the end, most of the design
1515

1616
## Source code
1717

18-
All of the source code goes into the [src/\<project-name\>](src/squarer) directory. Here, some *dunder* files can be found:
19-
- [\_\_version\_\_.py](src/squarer/__version__.py): just the version number as string, used by config files
20-
- [\_\_init\_\_.py](src/squarer/__init__.py): entry point for the command line interface
21-
- [\_\_main\_\_.py](src/squarer/__main__.py): same as `__init__.py` allowing calls via `python -m <prog>`
18+
All of the source code goes into the [src/\<project-name\>](src/squarer) directory. Here, some _dunder_ files can be found:
19+
20+
- [\_\_version\_\_.py](src/squarer/__version__.py): just the version number as string, used by config files
21+
- [\_\_init\_\_.py](src/squarer/__init__.py): entry point for program/library
22+
- [\_\_main\_\_.py](src/squarer/__main__.py): same as `__init__.py` allowing calls via `python -m <prog>`
2223

2324
<br>
2425

@@ -37,7 +38,7 @@ section must be given. Here, additional options for the code coverage report fro
3738

3839
<br>
3940

40-
*When to use pytest, coverage and tox?*
41+
_When to use pytest, coverage and tox?_
4142

4243
Personally, I mostly use just pytest without coverage to test in my working environment with `pytest -svv test` or a specific
4344
test module. Before committing, however, it is a good idea to check if your code also runs in different environments, which is where
@@ -60,11 +61,18 @@ ln -s /opt/miniforge3/envs/py311/bin/python3.11 ~/bin/python3.11
6061
<br>
6162

6263
Finally, some handy features of pytest you should be aware of:
63-
- fixtures: common setup for multiple tests (e.g., reading file or database connection)
64-
- parametrize: multiple test cases for single function
65-
- expected fails: testing if the code handles wrong inputs (`pytest.raises(Exception)` or `@pytest.mark.xfail`)
6664

67-
<br>
65+
- fixtures: common setup for multiple tests (e.g., reading file or database connection)
66+
- parametrize: multiple test cases for single function
67+
- expected fails: testing if the code handles wrong inputs (`pytest.raises(Exception)` or `@pytest.mark.xfail`)
68+
69+
<br>
70+
71+
Further links:
72+
73+
- check for [test pollution](https://github.com/asottile/detect-test-pollution) by randomizing the order of tests ([pytest-plugin](https://pypi.org/project/pytest-random-order/))
74+
75+
<br>
6876

6977
## Setup files and Packaging
7078

@@ -82,7 +90,6 @@ Additional points:
8290

8391
...
8492

85-
8693
<br>
8794

8895
## Additional tools

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ build-backend = "setuptools.build_meta"
77
[tool.pytest.ini_options]
88
testpaths = ["test"]
99
pythonpath = ["src"]
10+
11+
12+
[tool.mypy]
13+
check_untyped_defs = true
14+
disallow_any_generics = true
15+
disallow_incomplete_defs = true
16+
disallow_untyped_defs = true
17+
warn_redundant_casts = true
18+
warn_unreachable = true
19+
warn_unused_ignores = true

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ license = MIT
88
license_file = LICENSE.md
99
classifiers =
1010
License :: OSI Approved :: MIT License
11+
Programming Language :: Python
1112
Programming Language :: Python :: 3
1213
Programming Language :: Python :: 3 :: Only
13-
Programming Language :: Python :: Implementation :: CPython
14+
Topic :: Scientific/Engineering
15+
Typing :: Typed
1416

1517
[options]
1618
packages = find:
@@ -22,6 +24,7 @@ package_dir =
2224

2325
[options.packages.find]
2426
where = src
27+
exclude = test
2528

2629
[options.entry_points]
2730
console_scripts =

src/squarer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__all__ = ["__version__", "maths", "square"]
1515

1616

17-
def main(argv: Sequence | None = None) -> int:
17+
def main(argv: Sequence[str] | None = None) -> int:
1818
# get command line argument
1919
parser = argparse.ArgumentParser()
2020
parser.add_argument("number", type=float, help="Number to square.")

tox-old.ini

Lines changed: 0 additions & 6 deletions
This file was deleted.

tox-torch.ini

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[tox]
2+
envlist = py310-torch{1110,1121,1130}
3+
4+
5+
[gh-actions]
6+
python =
7+
3.7: py37
8+
3.8: py38
9+
3.9: py39
10+
3.10: py310
11+
3.11: py311
12+
13+
14+
[testenv]
15+
deps = -r test/requirements-tests.txt
16+
commands =
17+
pytest -svv --cov=./src --cov-report=term-missing {posargs:test}
18+
19+
[testenv:py310-torch1110]
20+
deps =
21+
{[testenv]deps}
22+
commands =
23+
pip install torch==1.11.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
24+
{[testenv]commands}
25+
26+
[testenv:py310-torch1121]
27+
deps =
28+
{[testenv]deps}
29+
commands =
30+
pip install torch==1.12.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
31+
{[testenv]commands}
32+
33+
[testenv:py310-torch1130]
34+
deps =
35+
{[testenv]deps}
36+
commands =
37+
pip install torch==1.13.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
38+
{[testenv]commands}

tox.ini

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
[tox]
2-
envlist = py310-{linux,windows}-torch{1110,1121}
3-
4-
5-
[gh-actions]
6-
python =
7-
3.7: py37
8-
3.8: py38
9-
3.9: py39
10-
3.10: py310
11-
3.11: py311
12-
13-
[gh-actions:env]
14-
PLATFORM =
15-
ubuntu-latest: linux
16-
macos-latest: macos
17-
windows-latest: windows
18-
2+
envlist = py{37,39,310,311}
193

204
[testenv]
21-
deps = -r test/requirements-tests.txt
22-
commands =
23-
pytest -svv --cov=./src --cov-report=term-missing {posargs:test}
24-
25-
[testenv:py310-{linux,windows}-torch1110]
26-
deps =
27-
{[testenv]deps}
28-
commands =
29-
pip install torch==1.11.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
30-
{[testenv]commands}
31-
32-
[testenv:py310-{linux,windows}-torch1121]
335
deps =
34-
{[testenv]deps}
6+
pytest
7+
pytest-cov
8+
coverage
359
commands =
36-
pip install torch==1.12.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
37-
{[testenv]commands}
10+
pytest -svv --cov=./src --cov-report=term-missing {posargs:test}

0 commit comments

Comments
 (0)