Skip to content

Commit 374250d

Browse files
authored
PYTHON-2963 Add tox config in preparation for migration from setup.py (#1240)
1 parent 37202c0 commit 374250d

File tree

2 files changed

+85
-11
lines changed

2 files changed

+85
-11
lines changed

.github/workflows/test-python.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ jobs:
3333
python-version: ${{ matrix.python-version }}
3434
cache: 'pip'
3535
cache-dependency-path: 'setup.py'
36+
- name: Install dependencies
37+
run: |
38+
pip install tox
3639
- name: Start MongoDB
3740
uses: supercharge/[email protected]
3841
with:
3942
mongodb-version: 4.4
4043
- name: Run tests
4144
run: |
42-
python setup.py test
45+
tox -e test
4346
4447
mypytest:
4548
name: Run mypy
@@ -58,22 +61,16 @@ jobs:
5861
cache-dependency-path: 'setup.py'
5962
- name: Install dependencies
6063
run: |
61-
python -m pip install -U pip mypy==1.2
62-
pip install -e ".[zstd, encryption, ocsp]"
64+
pip install tox
6365
- name: Run mypy
6466
run: |
65-
mypy --install-types --non-interactive bson gridfs tools pymongo
66-
mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" test
67-
python -m pip install -U typing_extensions
68-
mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py
67+
tox -e typecheck-mypy
6968
- name: Run pyright
7069
run: |
71-
python -m pip install -U pip pyright==1.1.290
72-
pyright test/test_typing.py test/test_typing_strict.py
70+
tox -e typecheck-pyright
7371
- name: Run pyright strict
7472
run: |
75-
echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json
76-
pyright test/test_typing_strict.py
73+
tox -e typecheck-pyright-strict
7774
7875
linkcheck:
7976
name: Check Links

tox.ini

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[tox]
2+
requires =
3+
tox>=4
4+
envlist =
5+
# Test using the system Python.
6+
test,
7+
# Run pre-commit on all files.
8+
lint,
9+
# Run pre-commit on all files, including stages that require manual fixes.
10+
lint-manual,
11+
# Typecheck all files.
12+
typecheck
13+
14+
[testenv:test]
15+
description = run unit tests
16+
commands =
17+
python --version
18+
python setup.py test {posargs}
19+
20+
[testenv:lint]
21+
description = run pre-commit
22+
deps =
23+
pre-commit
24+
commands =
25+
pre-commit run --all-files
26+
27+
[testenv:lint-manual]
28+
description = run all pre-commit stages, including those that require manual fixes
29+
deps =
30+
pre-commit
31+
commands =
32+
pre-commit run --all-files --hook-stage manual
33+
34+
[testenv:typecheck-mypy]
35+
description = run mypy and pyright to typecheck
36+
deps =
37+
mypy
38+
zstandard
39+
certifi; platform_system == "win32" or platform_system == "Darwin"
40+
typing_extensions
41+
pyopenssl>=17.2.0
42+
requests<3.0.0
43+
service_identity>=18.1.0
44+
pymongocrypt>=1.6.0,<2.0.0
45+
pymongo-auth-aws<2.0.0
46+
commands =
47+
mypy --install-types --non-interactive bson gridfs tools pymongo
48+
mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" test
49+
mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py
50+
51+
[testenv:typecheck-pyright]
52+
description = run pyright to typecheck
53+
deps =
54+
mypy
55+
pyright==1.1.290
56+
commands =
57+
pyright test/test_typing.py test/test_typing_strict.py
58+
59+
[testenv:typecheck-pyright-strict]
60+
description = run pyright with strict mode to typecheck
61+
deps =
62+
{[testenv:typecheck-pyright]deps}
63+
allowlist_externals=echo
64+
commands =
65+
echo '{"strict": ["tests/test_typing_strict.py"]}' > pyrightconfig.json
66+
pyright test/test_typing_strict.py
67+
68+
[testenv:typecheck]
69+
description = run mypy and pyright to typecheck
70+
deps =
71+
{[testenv:typecheck-mypy]deps}
72+
{[testenv:typecheck-pyright]deps}
73+
allowlist_externals=echo
74+
commands =
75+
{[testenv:typecheck-mypy]commands}
76+
{[testenv:typecheck-pyright]commands}
77+
{[testenv:typecheck-pyright-strict]commands}

0 commit comments

Comments
 (0)