From d10f084b84cae8b867718cf416c99ee7cd237f08 Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Wed, 9 Oct 2024 17:52:15 -0700 Subject: [PATCH 1/4] Use the new hatch test command to run tests Signed-off-by: Nic Cope --- .github/workflows/ci.yml | 11 ++++++----- README.md | 2 +- pyproject.toml | 8 -------- tests/test_resource.py | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 177f5e8..a334695 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ concurrency: env: # Common versions PYTHON_VERSION: '3.11.5' + HATCH_VERSION: '1.12.0' # The PyPi project version to push. The default is v0.0.0+gitdate-gitsha. PYPI_VERSION: ${{ inputs.version }} @@ -45,7 +46,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Setup Hatch - run: pipx install hatch==1.7.0 + run: pipx install hatch==${{ env.HATCH_VERSION }} - name: Lint run: hatch run lint:check @@ -62,10 +63,10 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Setup Hatch - run: pipx install hatch==1.7.0 + run: pipx install hatch==${{ env.HATCH_VERSION }} - name: Run Unit Tests - run: hatch run test:unit + run: hatch test --all --randomize build: @@ -80,7 +81,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Setup Hatch - run: pipx install hatch==1.7.0 + run: pipx install hatch==${{ env.HATCH_VERSION }} # If a version wasn't explicitly passed as a workflow_dispatch input we # default to version v0.0.0+-, for example @@ -143,7 +144,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Setup Hatch - run: pipx install hatch==1.7.0 + run: pipx install hatch==${{ env.HATCH_VERSION }} - name: Build Documentation run: hatch run docs:pdoc -d google crossplane/function -o docs diff --git a/README.md b/README.md index ad1f88e..d20d968 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ hatch run generate:protoc hatch run lint:check # Run unit tests. -hatch run test:unit +hatch test # Build an sdist and wheel. hatch build diff --git a/pyproject.toml b/pyproject.toml index 08a6eb3..54346d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,14 +58,6 @@ dependencies = ["ruff==0.6.9"] [tool.hatch.envs.lint.scripts] check = "ruff format crossplane tests && ruff check --fix crossplane tests" - -[tool.hatch.envs.test] -type = "virtual" -path = ".venv-test" - -[tool.hatch.envs.test.scripts] -unit = "python -m unittest tests/*.py" - [tool.hatch.envs.docs] type = "virtual" path = ".venv-docs" diff --git a/tests/test_resource.py b/tests/test_resource.py index 47fb18b..e9c818f 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -22,8 +22,7 @@ from google.protobuf import struct_pb2 as structpb import crossplane.function.proto.v1.run_function_pb2 as fnv1 from crossplane.function import logging, resource - -from .testdata.models.io.upbound.aws.s3 import v1beta2 +from tests.testdata.models.io.upbound.aws.s3 import v1beta2 class TestResource(unittest.TestCase): From 7990ab89394727fd27005aea04c3479a775d528c Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Wed, 9 Oct 2024 18:10:13 -0700 Subject: [PATCH 2/4] Use the new hatch fmt command to run linters and formatting Right now this defaults to a pretty old version of ruff. Hatch pins a ruff version though, so I'm inclined to just use whatever ruff version Hatch uses. Signed-off-by: Nic Cope --- .github/workflows/ci.yml | 2 +- README.md | 4 ++-- pyproject.toml | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a334695..a85399a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: run: pipx install hatch==${{ env.HATCH_VERSION }} - name: Lint - run: hatch run lint:check + run: hatch fmt unit-test: runs-on: ubuntu-22.04 diff --git a/README.md b/README.md index d20d968..87e6e24 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ Some useful commands: # Generate gRPC stubs. hatch run generate:protoc -# Lint the code. -hatch run lint:check +# Format and lint the code. +hatch fmt # Run unit tests. hatch test diff --git a/pyproject.toml b/pyproject.toml index 54346d9..40c2cb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,15 +49,6 @@ dependencies = ["grpcio-tools==1.66.2"] [tool.hatch.envs.generate.scripts] protoc = "python -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. crossplane/function/proto/v1beta1/run_function.proto crossplane/function/proto/v1/run_function.proto" -[tool.hatch.envs.lint] -type = "virtual" -detached = true -path = ".venv-lint" -dependencies = ["ruff==0.6.9"] - -[tool.hatch.envs.lint.scripts] -check = "ruff format crossplane tests && ruff check --fix crossplane tests" - [tool.hatch.envs.docs] type = "virtual" path = ".venv-docs" @@ -69,6 +60,11 @@ generate = "pdoc -m google crossplane/function -o docs" [tool.hatch.build.targets.wheel] packages = ["crossplane"] +# This special environment is used by hatch fmt. +[tool.hatch.envs.hatch-static-analysis] +dependencies = ["ruff==0.6.9"] +config-path = "none" # Disable Hatch's default Ruff config. + [tool.ruff] target-version = "py311" exclude = ["crossplane/function/proto/*", "tests/testdata/*"] From 8057458e361adeb77806b1c5cea343aa8645fedf Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Wed, 9 Oct 2024 19:57:32 -0700 Subject: [PATCH 3/4] Bump Python version Signed-off-by: Nic Cope --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a85399a..f35b35c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ concurrency: env: # Common versions - PYTHON_VERSION: '3.11.5' + PYTHON_VERSION: '3.11.10' HATCH_VERSION: '1.12.0' # The PyPi project version to push. The default is v0.0.0+gitdate-gitsha. From 59f8ccc62a9805046ce03b98feea0e12b1c3423a Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Wed, 9 Oct 2024 19:58:54 -0700 Subject: [PATCH 4/4] Use latest available Python 3.11.x Signed-off-by: Nic Cope --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f35b35c..cc5e70d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ concurrency: env: # Common versions - PYTHON_VERSION: '3.11.10' + PYTHON_VERSION: '3.11' HATCH_VERSION: '1.12.0' # The PyPi project version to push. The default is v0.0.0+gitdate-gitsha.