From 589ebd11798d3cc28d456ee4d00d33c0ed095e49 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 14 Jun 2023 16:34:41 -0700 Subject: [PATCH 1/6] PYTHON-2963 Migrate to tox from setup.py test --- tox.ini | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000..00df41df05 --- /dev/null +++ b/tox.ini @@ -0,0 +1,45 @@ +[tox] +requires = + tox>=4 +envlist = + # Test using the system Python. + test, + # Run pre-commit on all files. + lint, + # Run pre-commit on all files, including stages that require manual fixes. + lint-manual, + # Typecheck all files. + typecheck + +[testenv:test] +description = run unit tests +commands = + python --version + python setup.py test {posargs} + +[testenv:lint] +description = run pre-commit +deps = + pre-commit +commands = + pre-commit run --all-files + +[testenv:lint-manual] +description = run all pre-commit stages, including those that require manual fixes +deps = + pre-commit +commands = + pre-commit run --all-files + pre-commit run --all-files --hook-stage manual flake8 + pre-commit run --all-files --hook-stage manual doc8 + +[testenv:typecheck] +description = run mypy to typecheck +deps = + mypy + zstandard + certifi; platform_system == "win32" or platform_system == "Darwin" +commands = + mypy --install-types --non-interactive bson gridfs tools pymongo + 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 + mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py From 8c32abef47c1046ab315a81f1a5f3adfa059639f Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 11:38:47 -0700 Subject: [PATCH 2/6] Consolidate lint-manual commands --- tox.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 00df41df05..5f738cb91c 100644 --- a/tox.ini +++ b/tox.ini @@ -29,9 +29,7 @@ description = run all pre-commit stages, including those that require manual fix deps = pre-commit commands = - pre-commit run --all-files - pre-commit run --all-files --hook-stage manual flake8 - pre-commit run --all-files --hook-stage manual doc8 + pre-commit run --all-files --hook-stage manual [testenv:typecheck] description = run mypy to typecheck From 8bdd581b8ff040588b00b06aedcfb8bc88c6fd08 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 13:20:29 -0700 Subject: [PATCH 3/6] Update Github workflows for test and typecheck to use tox --- .github/workflows/test-python.yml | 19 ++++++------ tox.ini | 48 ++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index b4a8177fda..fc7f989977 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -29,6 +29,9 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 + - name: Install dependencies + run: | + pip install tox with: python-version: ${{ matrix.python-version }} cache: 'pip' @@ -39,7 +42,7 @@ jobs: mongodb-version: 4.4 - name: Run tests run: | - python setup.py test + tox -e test mypytest: name: Run mypy @@ -58,22 +61,16 @@ jobs: cache-dependency-path: 'setup.py' - name: Install dependencies run: | - python -m pip install -U pip mypy==1.2 - pip install -e ".[zstd, encryption, ocsp]" + pip install tox - name: Run mypy run: | - mypy --install-types --non-interactive bson gridfs tools pymongo - 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 - python -m pip install -U typing_extensions - mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py + tox -e typecheck-mypy - name: Run pyright run: | - python -m pip install -U pip pyright==1.1.290 - pyright test/test_typing.py test/test_typing_strict.py + tox -e typecheck-pyright - name: Run pyright strict run: | - echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json - pyright test/test_typing_strict.py + tox -e typecheck-pyright-strict linkcheck: name: Check Links diff --git a/tox.ini b/tox.ini index 5f738cb91c..7e17d88069 100644 --- a/tox.ini +++ b/tox.ini @@ -31,13 +31,59 @@ deps = commands = pre-commit run --all-files --hook-stage manual +[testenv:typecheck-mypy] +description = run mypy and pyright to typecheck +deps = + mypy + zstandard + certifi; platform_system == "win32" or platform_system == "Darwin" + typing_extensions + pyopenssl>=17.2.0 + requests<3.0.0 + service_identity>=18.1.0 + pymongocrypt>=1.6.0,<2.0.0 + pymongo-auth-aws<2.0.0 +commands = + mypy --install-types --non-interactive bson gridfs tools pymongo + 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 + mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py + +[testenv:typecheck-pyright] +description = run pyright to typecheck +deps = + mypy + pyright==1.1.290 +commands = + pyright test/test_typing.py test/test_typing_strict.py + +[testenv:typecheck-pyright-strict] +description = run pyright to typecheck +deps = + mypy + pyright==1.1.290 +allowlist_externals=echo +commands = + echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json + pyright test/test_typing_strict.py + [testenv:typecheck] -description = run mypy to typecheck +description = run mypy and pyright to typecheck deps = mypy zstandard certifi; platform_system == "win32" or platform_system == "Darwin" + typing_extensions + pyopenssl>=17.2.0 + requests<3.0.0 + service_identity>=18.1.0 + pymongocrypt>=1.6.0,<2.0.0 + pymongo-auth-aws<2.0.0 + pyright==1.1.290 +allowlist_externals=echo commands = mypy --install-types --non-interactive bson gridfs tools pymongo 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 mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py + pyright test/test_typing.py test/test_typing_strict.py + echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json + pyright test/test_typing_strict.py From 423643d03d452b8906347ac0f009707d9c93c21c Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 13:32:02 -0700 Subject: [PATCH 4/6] Fix Github workflow syntax --- .github/workflows/test-python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index fc7f989977..83def93f57 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -29,13 +29,13 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 - - name: Install dependencies - run: | - pip install tox with: python-version: ${{ matrix.python-version }} cache: 'pip' cache-dependency-path: 'setup.py' + - name: Install dependencies + run: | + pip install tox - name: Start MongoDB uses: supercharge/mongodb-github-action@1.7.0 with: From 88c919a70e52c9aaef835a0a2b6a85c8fc2ddc68 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 15:19:00 -0700 Subject: [PATCH 5/6] Use composition for tox typecheck env --- tox.ini | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/tox.ini b/tox.ini index 7e17d88069..aefcd1593e 100644 --- a/tox.ini +++ b/tox.ini @@ -57,10 +57,9 @@ commands = pyright test/test_typing.py test/test_typing_strict.py [testenv:typecheck-pyright-strict] -description = run pyright to typecheck +description = run pyright with strict mode to typecheck deps = - mypy - pyright==1.1.290 + {[testenv:typecheck-pyright]deps} allowlist_externals=echo commands = echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json @@ -69,21 +68,10 @@ commands = [testenv:typecheck] description = run mypy and pyright to typecheck deps = - mypy - zstandard - certifi; platform_system == "win32" or platform_system == "Darwin" - typing_extensions - pyopenssl>=17.2.0 - requests<3.0.0 - service_identity>=18.1.0 - pymongocrypt>=1.6.0,<2.0.0 - pymongo-auth-aws<2.0.0 - pyright==1.1.290 + {[testenv:typecheck-mypy]deps} + {[testenv:typecheck-pyright]deps} allowlist_externals=echo commands = - mypy --install-types --non-interactive bson gridfs tools pymongo - 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 - mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py - pyright test/test_typing.py test/test_typing_strict.py - echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json - pyright test/test_typing_strict.py + {[testenv:typecheck-mypy]commands} + {[testenv:typecheck-pyright]commands} + {[testenv:typecheck-pyright-strict]commands} From afb851f59363ebb235e9075e88cc98530f0f0791 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 17:00:30 -0700 Subject: [PATCH 6/6] Use > and not >> to overwrite and not append --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index aefcd1593e..e199914cb5 100644 --- a/tox.ini +++ b/tox.ini @@ -62,7 +62,7 @@ deps = {[testenv:typecheck-pyright]deps} allowlist_externals=echo commands = - echo '{"strict": ["tests/test_typing_strict.py"]}' >> pyrightconfig.json + echo '{"strict": ["tests/test_typing_strict.py"]}' > pyrightconfig.json pyright test/test_typing_strict.py [testenv:typecheck]