From 875688cecc8827434476bd23de942b558f49680d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 11 Jul 2024 11:56:18 -0500 Subject: [PATCH] PYTHON-4483 Use hatch as task runner (#1728) Co-authored-by: Noah Stapp --- .evergreen/config.yml | 22 +- .evergreen/hatch.sh | 24 ++ .evergreen/run-azurekms-fail-test.sh | 2 +- .evergreen/run-azurekms-test.sh | 2 +- .evergreen/run-gcpkms-test.sh | 2 +- .evergreen/run-mongodb-aws-ecs-test.sh | 4 +- .evergreen/run-mongodb-aws-test.sh | 2 +- .evergreen/run-mongodb-oidc-test.sh | 2 +- .evergreen/run-perf-tests.sh | 2 +- .evergreen/run-tests.sh | 4 +- ...p-libmongocrypt.sh => setup-encryption.sh} | 7 + .evergreen/teardown-encryption.sh | 10 + .evergreen/tox.sh | 24 -- .evergreen/utils.sh | 2 +- .github/workflows/test-python.yml | 34 +-- CONTRIBUTING.md | 27 +-- README.md | 9 +- doc/index.rst | 4 +- hatch.toml | 51 +++++ tox.ini | 212 ------------------ 20 files changed, 156 insertions(+), 290 deletions(-) create mode 100644 .evergreen/hatch.sh rename .evergreen/{setup-libmongocrypt.sh => setup-encryption.sh} (87%) create mode 100644 .evergreen/teardown-encryption.sh delete mode 100644 .evergreen/tox.sh create mode 100644 hatch.toml delete mode 100644 tox.ini diff --git a/.evergreen/config.yml b/.evergreen/config.yml index ef27397b3..f08525354 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -365,7 +365,7 @@ functions: ${PREPARE_SHELL} set -o xtrace export PYTHON_BINARY=${PYTHON_BINARY} - bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-mockupdb + bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh test:test-mockupdb "run doctests": - command: shell.exec @@ -375,18 +375,19 @@ functions: script: | ${PREPARE_SHELL} set -o xtrace - PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m doc-test + PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh doctest:test "run tests": - command: shell.exec params: working_dir: "src" shell: bash - include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"] + background: true + include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"] script: | ${PREPARE_SHELL} if [ -n "${test_encryption}" ]; then - . .evergreen/tox.sh -m setup-encryption + ./.evergreen/hatch.sh encryption:setup fi - command: shell.exec type: test @@ -407,6 +408,7 @@ functions: if [ -n "${test_encryption}" ]; then # Disable xtrace (just in case it was accidentally set). set +x + bash ${DRIVERS_TOOLS}/.evergreen/csfle/await-servers.sh export TEST_ENCRYPTION=1 if [ -n "${test_encryption_pyopenssl}" ]; then export TEST_ENCRYPTION_PYOPENSSL=1 @@ -446,7 +448,7 @@ functions: SSL=${SSL} \ TEST_DATA_LAKE=${TEST_DATA_LAKE} \ MONGODB_API_VERSION=${MONGODB_API_VERSION} \ - bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg + bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh test:test-eg "run enterprise auth tests": - command: shell.exec @@ -462,7 +464,7 @@ functions: PYTHON_BINARY="${PYTHON_BINARY}" \ TEST_ENTERPRISE_AUTH=1 \ AUTH=auth \ - bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg + bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh test:test-eg "run atlas tests": - command: shell.exec @@ -478,7 +480,7 @@ functions: PROJECT_DIRECTORY="${PROJECT_DIRECTORY}" \ PYTHON_BINARY="${PYTHON_BINARY}" \ TEST_ATLAS=1 \ - bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg + bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh test:test-eg "get aws auth secrets": - command: subprocess.exec @@ -597,7 +599,7 @@ functions: working_dir: "src" script: | ${PREPARE_SHELL} - . .evergreen/tox.sh -m teardown-encryption + . .evergreen/hatch.sh encryption:teardown rm -rf $DRIVERS_TOOLS || true rm -f ./secrets-export.sh || true @@ -683,7 +685,7 @@ functions: PYTHON_BINARY=${PYTHON_BINARY} \ CA_FILE="$DRIVERS_TOOLS/.evergreen/ocsp/${OCSP_ALGORITHM}/ca.pem" \ OCSP_TLS_SHOULD_SUCCEED="${OCSP_TLS_SHOULD_SUCCEED}" \ - bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg + bash ${PROJECT_DIRECTORY}/.evergreen/hatch.sh test:test-eg run-valid-ocsp-server: - command: shell.exec @@ -2128,7 +2130,7 @@ tasks: ${PREPARE_SHELL} export PYTHON_BINARY=/opt/mongodbtoolchain/v4/bin/python3 export LIBMONGOCRYPT_URL=https://s3.amazonaws.com/${bucket_name}/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz - SUCCESS=false TEST_FLE_GCP_AUTO=1 ./.evergreen/tox.sh -m test-eg + SUCCESS=false TEST_FLE_GCP_AUTO=1 ./.evergreen/hatch.sh test:test-eg - name: testazurekms-task commands: diff --git a/.evergreen/hatch.sh b/.evergreen/hatch.sh new file mode 100644 index 000000000..8a1654404 --- /dev/null +++ b/.evergreen/hatch.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -o errexit # Exit the script with error if any of the commands fail +set -x + +. .evergreen/utils.sh + +if [ -z "$PYTHON_BINARY" ]; then + PYTHON_BINARY=$(find_python3) +fi + +if $PYTHON_BINARY -m hatch --version; then + run_hatch() { + $PYTHON_BINARY hatch run "$@" + } +else # No toolchain hatch present, set up virtualenv before installing hatch + createvirtualenv "$PYTHON_BINARY" hatchenv + trap "deactivate; rm -rf hatchenv" EXIT HUP + python -m pip install -q hatch + run_hatch() { + python -m hatch run "$@" + } +fi + +run_hatch "${@:1}" diff --git a/.evergreen/run-azurekms-fail-test.sh b/.evergreen/run-azurekms-fail-test.sh index 13b34d01e..65c5cd0bb 100644 --- a/.evergreen/run-azurekms-fail-test.sh +++ b/.evergreen/run-azurekms-fail-test.sh @@ -7,4 +7,4 @@ PYTHON_BINARY=/opt/mongodbtoolchain/v4/bin/python3 \ KEY_VAULT_ENDPOINT="${AZUREKMS_KEYVAULTENDPOINT}" \ LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz \ SUCCESS=false TEST_FLE_AZURE_AUTO=1 \ - ./.evergreen/tox.sh -m test-eg + ./.evergreen/hatch.sh test:test-eg diff --git a/.evergreen/run-azurekms-test.sh b/.evergreen/run-azurekms-test.sh index d8fb3449f..961bcf507 100644 --- a/.evergreen/run-azurekms-test.sh +++ b/.evergreen/run-azurekms-test.sh @@ -16,6 +16,6 @@ AZUREKMS_CMD="tar xf mongo-python-driver.tgz" \ $DRIVERS_TOOLS/.evergreen/csfle/azurekms/run-command.sh echo "Untarring file ... end" echo "Running test ... begin" -AZUREKMS_CMD="KEY_NAME=\"$AZUREKMS_KEYNAME\" KEY_VAULT_ENDPOINT=\"$AZUREKMS_KEYVAULTENDPOINT\" LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz SUCCESS=true TEST_FLE_AZURE_AUTO=1 ./.evergreen/tox.sh -m test-eg" \ +AZUREKMS_CMD="KEY_NAME=\"$AZUREKMS_KEYNAME\" KEY_VAULT_ENDPOINT=\"$AZUREKMS_KEYVAULTENDPOINT\" LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz SUCCESS=true TEST_FLE_AZURE_AUTO=1 ./.evergreen/hatch.sh test:test-eg" \ $DRIVERS_TOOLS/.evergreen/csfle/azurekms/run-command.sh echo "Running test ... end" diff --git a/.evergreen/run-gcpkms-test.sh b/.evergreen/run-gcpkms-test.sh index 221100de8..8a5fef04c 100644 --- a/.evergreen/run-gcpkms-test.sh +++ b/.evergreen/run-gcpkms-test.sh @@ -14,5 +14,5 @@ echo "Untarring file ... begin" GCPKMS_CMD="tar xf mongo-python-driver.tgz" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh echo "Untarring file ... end" echo "Running test ... begin" -GCPKMS_CMD="SUCCESS=true TEST_FLE_GCP_AUTO=1 LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz ./.evergreen/tox.sh -m test-eg" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh +GCPKMS_CMD="SUCCESS=true TEST_FLE_GCP_AUTO=1 LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian10/master/latest/libmongocrypt.tar.gz ./.evergreen/hatch.sh test:test-eg" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh echo "Running test ... end" diff --git a/.evergreen/run-mongodb-aws-ecs-test.sh b/.evergreen/run-mongodb-aws-ecs-test.sh index 757ad8079..3905a0876 100755 --- a/.evergreen/run-mongodb-aws-ecs-test.sh +++ b/.evergreen/run-mongodb-aws-ecs-test.sh @@ -30,5 +30,5 @@ export TEST_AUTH_AWS=1 export AUTH="auth" export SET_XTRACE_ON=1 cd src -$PYTHON_BINARY -m pip install -q --user tox -bash .evergreen/tox.sh -m test-eg +$PYTHON_BINARY -m pip install -q --user hatch +bash .evergreen/hatch.sh test:test-eg diff --git a/.evergreen/run-mongodb-aws-test.sh b/.evergreen/run-mongodb-aws-test.sh index 684c80452..c4051bb34 100755 --- a/.evergreen/run-mongodb-aws-test.sh +++ b/.evergreen/run-mongodb-aws-test.sh @@ -24,4 +24,4 @@ set -x export TEST_AUTH_AWS=1 export AUTH="auth" export SET_XTRACE_ON=1 -bash ./.evergreen/tox.sh -m test-eg +bash ./.evergreen/hatch.sh test:test-eg diff --git a/.evergreen/run-mongodb-oidc-test.sh b/.evergreen/run-mongodb-oidc-test.sh index 89a211930..0c34912c8 100755 --- a/.evergreen/run-mongodb-oidc-test.sh +++ b/.evergreen/run-mongodb-oidc-test.sh @@ -29,4 +29,4 @@ fi export TEST_AUTH_OIDC=1 export COVERAGE=1 export AUTH="auth" -bash ./.evergreen/tox.sh -m test-eg -- "${@:1}" +bash ./.evergreen/hatch.sh test:test-eg -- "${@:1}" diff --git a/.evergreen/run-perf-tests.sh b/.evergreen/run-perf-tests.sh index 9d6afacf7..ff8d81a83 100644 --- a/.evergreen/run-perf-tests.sh +++ b/.evergreen/run-perf-tests.sh @@ -16,4 +16,4 @@ export OUTPUT_FILE="${PROJECT_DIRECTORY}/results.json" export PYTHON_BINARY=/opt/mongodbtoolchain/v4/bin/python3 export PERF_TEST=1 -bash ./.evergreen/tox.sh -m test-eg +bash ./.evergreen/hatch.sh test:test-eg diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 5e482b3d1..0147a7bc5 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -123,9 +123,9 @@ if [ -n "$TEST_ENCRYPTION" ] || [ -n "$TEST_FLE_AZURE_AUTO" ] || [ -n "$TEST_FLE python -m pip install '.[encryption]' - # Install libmongocrypt if necessary. + # Setup encryption if necessary. if [ ! -d "libmongocrypt" ]; then - bash ./.evergreen/setup-libmongocrypt.sh + bash ./.evergreen/setup-encryption.sh fi # Use the nocrypto build to avoid dependency issues with older windows/python versions. diff --git a/.evergreen/setup-libmongocrypt.sh b/.evergreen/setup-encryption.sh similarity index 87% rename from .evergreen/setup-libmongocrypt.sh rename to .evergreen/setup-encryption.sh index 99ca6ebd3..b439c15dd 100644 --- a/.evergreen/setup-libmongocrypt.sh +++ b/.evergreen/setup-encryption.sh @@ -2,6 +2,10 @@ set -o errexit # Exit the script with error if any of the commands fail set -o xtrace +if [ -z "${DRIVERS_TOOLS}" ]; then + echo "Missing environment variable DRIVERS_TOOLS" +fi + TARGET="" if [ "Windows_NT" = "${OS:-''}" ]; then # Magic variable in cygwin @@ -45,3 +49,6 @@ mkdir libmongocrypt tar xzf libmongocrypt.tar.gz -C ./libmongocrypt ls -la libmongocrypt ls -la libmongocrypt/nocrypto + +bash ${DRIVERS_TOOLS}/.evergreen/csfle/setup-secrets.sh +bash ${DRIVERS_TOOLS}/.evergreen/csfle/start-servers.sh diff --git a/.evergreen/teardown-encryption.sh b/.evergreen/teardown-encryption.sh new file mode 100644 index 000000000..88dc16bba --- /dev/null +++ b/.evergreen/teardown-encryption.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -o errexit # Exit the script with error if any of the commands fail +set -o xtrace + +if [ -z "${DRIVERS_TOOLS}" ]; then + echo "Missing environment variable DRIVERS_TOOLS" +fi + +bash ${DRIVERS_TOOLS}/.evergreen/csfle/stop-servers.sh +rm -rf libmongocrypt/ libmongocrypt_git/ libmongocrypt.tar.gz mongocryptd.pid diff --git a/.evergreen/tox.sh b/.evergreen/tox.sh deleted file mode 100644 index 808787d63..000000000 --- a/.evergreen/tox.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -o errexit # Exit the script with error if any of the commands fail -set -x - -. .evergreen/utils.sh - -if [ -z "$PYTHON_BINARY" ]; then - PYTHON_BINARY=$(find_python3) -fi - -if $PYTHON_BINARY -m tox --version; then - run_tox() { - $PYTHON_BINARY -m tox "$@" - } -else # No toolchain present, set up virtualenv before installing tox - createvirtualenv "$PYTHON_BINARY" toxenv - trap "deactivate; rm -rf toxenv" EXIT HUP - python -m pip install -q tox - run_tox() { - python -m tox "$@" - } -fi - -run_tox "${@:1}" diff --git a/.evergreen/utils.sh b/.evergreen/utils.sh index f0a5851d9..84d010f54 100755 --- a/.evergreen/utils.sh +++ b/.evergreen/utils.sh @@ -66,7 +66,7 @@ createvirtualenv () { export PIP_QUIET=1 python -m pip install --upgrade pip - python -m pip install --upgrade tox + python -m pip install --upgrade hatch } # Usage: diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 19b209693..3a03be8ee 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -27,10 +27,10 @@ jobs: cache-dependency-path: 'pyproject.toml' - name: Install Python dependencies run: | - python -m pip install -U pip tox + python -m pip install -U pip hatch - name: Run linters run: | - tox -m lint-manual + hatch run lint:run-manual - name: Run compilation run: | export PYMONGO_C_EXT_MUST_BUILD=1 @@ -38,7 +38,7 @@ jobs: python tools/fail_if_no_c.py - name: Run typecheck run: | - tox -m typecheck + hatch run typing:check - run: | sudo apt-get install -y cppcheck - run: | @@ -64,17 +64,23 @@ jobs: allow-prereleases: true - name: Install dependencies run: | - pip install -q tox + pip install -U pip + if [ "${{ matrix.python-version }}" == "3.13" ]; then + pip install --pre cffi setuptools + pip install --no-build-isolation hatch + else + pip install hatch + fi - name: Start MongoDB uses: supercharge/mongodb-github-action@1.10.0 with: mongodb-version: 6.0 - name: Run tests run: | - tox -m test + hatch run test:test - name: Run async tests run: | - tox -m test-async + hatch run test:test-async doctest: runs-on: ubuntu-latest @@ -89,14 +95,14 @@ jobs: cache-dependency-path: 'pyproject.toml' - name: Install dependencies run: | - pip install -q tox + pip install -U hatch pip - name: Start MongoDB uses: supercharge/mongodb-github-action@1.10.0 with: mongodb-version: 4.4 - name: Run tests run: | - tox -m doc-test + hatch run doctest:test docs: name: Docs Checks @@ -111,10 +117,10 @@ jobs: python-version: '3.8' - name: Install dependencies run: | - pip install -q tox + pip install -U pip hatch - name: Build docs run: | - tox -m doc + hatch run doc:build linkcheck: name: Link Check @@ -129,10 +135,10 @@ jobs: python-version: '3.8' - name: Install dependencies run: | - pip install -q tox + pip install -U pip hatch - name: Build docs run: | - tox -m linkcheck + hatch run doc:linkcheck typing: name: Typing Tests @@ -149,10 +155,10 @@ jobs: cache-dependency-path: 'pyproject.toml' - name: Install dependencies run: | - pip install -q tox + pip install -U pip hatch - name: Run typecheck run: | - tox -m typecheck + hatch run typing:check make_sdist: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e2fd0e32b..4dede8343 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,8 +28,9 @@ including 4 space indents and 79 character line limits. - Avoid backward breaking changes if at all possible. - Write inline documentation for new classes and methods. +- We use [hatch](https://hatch.pypa.io/dev/) for our script runner and packaging tool. - Write tests and make sure they pass (make sure you have a mongod - running on the default port, then execute `tox -e test` from the cmd + running on the default port, then execute `hatch run test:test` from the cmd line to run the test suite). - Add yourself to doc/contributors.rst `:)` @@ -153,11 +154,11 @@ To run a manual hook like `mypy` manually, run: pre-commit run --all-files --hook-stage manual mypy ``` -Typically we use `tox` to run the linters, e.g. +Typically we use `hatch` to run the linters, e.g. ```bash -tox -e typecheck-mypy -tox -e lint-manual +hatch run typing:check-mypy +hatch run lint:build-manual ``` ## Documentation @@ -178,13 +179,13 @@ documentation including narrative docs, and the [Sphinx docstring format](https: You can build the documentation locally by running: ```bash -tox -e doc +hatch run doc:build ``` When updating docs, it can be helpful to run the live docs server as: ```bash -tox -e doc-serve +hatch run doc:serve ``` Browse to the link provided, and then as you make changes to docstrings or narrative docs, @@ -194,13 +195,13 @@ the pages will re-render and the browser will automatically refresh. ## Running Tests Locally - Ensure you have started the appropriate Mongo Server(s). -- Run `pip install tox` to use `tox` for testing or run +- Run `pip install hatch` to use `hatch` for testing or run `pip install -e ".[test]"` to run `pytest` directly. -- Run `tox -m test` or `pytest` to run all of the tests. +- Run `hatch run test:test` or `pytest` to run all of the tests. - Append `test/.py::::` to run specific tests. You can omit the `` to test a full class and the `` to test a full module. For example: - `tox -m test -- test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`. + `hatch run test:test -- test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`. - Use the `-k` argument to select tests by pattern. ## Running Load Balancer Tests Locally @@ -213,15 +214,15 @@ the pages will re-render and the browser will automatically refresh. - Start the load balancer using: `MONGODB_URI='mongodb://localhost:27017,localhost:27018/' $PWD/drivers-evergreen-tools/.evergreen/run-load-balancer.sh start`. - Run the tests from the `pymongo` checkout directory using: - `TEST_LOADBALANCER=1 tox -m test-eg`. + `TEST_LOADBALANCER=1 hatch run test:test-eg`. ## Running Encryption Tests Locally - Clone `drivers-evergreen-tools`: `git clone git@github.com:mongodb-labs/drivers-evergreen-tools.git`. - Run `export DRIVERS_TOOLS=$PWD/drivers-evergreen-tools` -- Run `AWS_PROFILE= tox -m setup-encryption` after setting up your AWS profile with `aws configure sso`. -- Run the tests with `TEST_ENCRYPTION=1 tox -e test-eg`. -- When done, run `tox -m teardown-encryption` to clean up. +- Run `AWS_PROFILE= hatch run encryption:setup` after setting up your AWS profile with `aws configure sso`. +- Run the tests with `TEST_ENCRYPTION=1 hatch run test:test-eg`. +- When done, run `hatch run encryption:teardown` to clean up. ## Re-sync Spec Tests diff --git a/README.md b/README.md index ed434b02b..bb773b795 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ python -m pip install "pymongo[gssapi,aws,ocsp,snappy,zstd,encryption]" Additional dependencies are: - (to generate documentation or run tests) - [tox](https://tox.wiki/en/latest/index.html) + [hatch](https://hatch.pypa.io/dev/) ## Examples @@ -201,7 +201,7 @@ ObjectId('4aba160ee23f6b543e000002') Documentation is available at [pymongo.readthedocs.io](https://pymongo.readthedocs.io/en/stable/). -Documentation can be generated by running **tox -m doc**. Generated +Documentation can be generated by running **pip install hatch; hatch run doc:build**. Generated documentation can be found in the `doc/build/html/` directory. ## Learning Resources @@ -213,9 +213,10 @@ Center](https://www.mongodb.com/developer/languages/python/). ## Testing -The easiest way to run the tests is to run **tox -m test** in the root +The easiest way to run the tests is to run *hatch run test:test** in the root of the distribution. For example, ```bash -tox -e test +pip install hatch +hatch run test:test ``` diff --git a/doc/index.rst b/doc/index.rst index f2797eb73..096a6a8ae 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -105,8 +105,8 @@ following command from the root directory of the **PyMongo** source: .. code-block:: bash - $ pip install tox - $ tox -m doc + $ pip install hatch + $ hatch run doc:build Indices and tables ------------------ diff --git a/hatch.toml b/hatch.toml new file mode 100644 index 000000000..281564d40 --- /dev/null +++ b/hatch.toml @@ -0,0 +1,51 @@ +# See https://hatch.pypa.io/dev/config/environment/overview/ + +[envs.doc] +features = ["docs"] +[envs.doc.scripts] +build = "sphinx-build -W -b html doc ./doc/_build/html" +serve = "sphinx-autobuild -W -b html doc --watch ./pymongo --watch ./bson --watch ./gridfs ./doc/_build/serve" +linkcheck = "sphinx-build -E -b linkcheck doc ./doc/_build/linkcheck" + +[envs.doctest] +features = ["docs","test"] +[envs.doctest.scripts] +test = "sphinx-build -E -b doctest doc ./doc/_build/doctest" + +[envs.typing] +features = ["encryption", "ocsp", "zstd", "aws"] +dependencies = ["mypy==1.2.0","pyright==1.1.290", "certifi", "typing_extensions"] +[envs.typing.scripts] +check-mypy = [ + "mypy --install-types --non-interactive bson gridfs tools pymongo", + "mypy --install-types --non-interactive --config-file mypy_test.ini test", + "mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py" +] +check-pyright = ["rm -f pyrightconfig.json", "pyright test/test_typing.py test/test_typing_strict.py"] +check-strict-pyright = [ + "echo '{{\"strict\": [\"tests/test_typing_strict.py\"]}}' > pyrightconfig.json", + "pyright test/test_typing_strict.py", + "rm -f pyrightconfig.json" +] +check = ["check-mypy", "check-pyright", "check-strict-pyright"] + +[envs.lint] +skip-install = true +dependencies = ["pre-commit"] +[envs.lint.scripts] +run = "pre-commit run --all-files" +run-manual = "pre-commit run --all-files --hook-stage manual" + +[envs.test] +features = ["test"] +[envs.test.scripts] +test = "pytest -v --durations=5 --maxfail=10 {args}" +test-eg = "bash ./.evergreen/run-tests.sh {args}" +test-async = "test test/asynchronous/ {args}" +test-mockupdb = ["pip install -U git+https://github.com/ajdavis/mongo-mockup-db@master", "test ./test/mockupdb"] + +[envs.encryption] +skip-install = true +[envs.encryption.scripts] +setup = "bash .evergreen/setup-encryption.sh" +teardown = "bash .evergreen/teardown-encryption.sh" diff --git a/tox.ini b/tox.ini deleted file mode 100644 index adc804170..000000000 --- a/tox.ini +++ /dev/null @@ -1,212 +0,0 @@ -[tox] -requires = - tox>=4 - -envlist = - # Test using the system Python. - test, - # Test async tests using the system Python. - test-async, - # Test using the run-tests Evergreen script. - test-eg, - # Set up encryption files and services. - setup-encryption, - # Tear down encryption files and services. - teardown-encryption, - # Run pre-commit on all files. - lint, - # Run pre-commit on all files, including stages that require manual fixes. - lint-manual, - # Typecheck using mypy. - typecheck-mypy, - # Typecheck using pyright. - typecheck-pyright, - # Typecheck using pyright strict. - typecheck-pyright-strict, - # Typecheck all files. - typecheck, - # Build sphinx docs - doc, - # Server live sphinx docs - doc-serve, - # Test sphinx docs - doc-test, - # Linkcheck sphinx docs - linkcheck - -labels = # Use labels and -m instead of -e so that tox -m