diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 336d01e5f..24f6b4698 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,25 +74,9 @@ jobs: poetry run pip install pydantic==${{ matrix.pydantic-version }} poetry run pip install openai==${{ matrix.openai-version }} - - if: matrix.pydantic-version == '2.4.2' && matrix.openai-version == '0.28.1' - name: Static analysis with pyright (ignoring pydantic v1 and openai v1) + - name: Static analysis with pyright run: | - make type-pydantic-v2-openai-v0 - - - if: matrix.pydantic-version == '1.10.9' && matrix.openai-version == '0.28.1' - name: Static analysis with mypy (ignoring pydantic v2 and openai v1) - run: | - make type-pydantic-v1-openai-v0 - - - if: matrix.pydantic-version == '2.4.2' && matrix.openai-version == '1.2.4' - name: Static analysis with pyright (ignoring pydantic v1 and openai v0) - run: | - make type-pydantic-v2-openai-v1 - - - if: matrix.pydantic-version == '1.10.9' && matrix.openai-version == '1.2.4' - name: Static analysis with mypy (ignoring pydantic v2 and openai v0) - run: | - make type-pydantic-v1-openai-v1 + make type Pytests: runs-on: LargeBois diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae972b098..fa1df836c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,8 @@ Follow these steps before committing your changes: 1. Ensure tests pass: `make test` 2. Format your code: `make autoformat` -3. Update documentation if needed. Docs are located in the `docs` directory. You can serve docs using `mkdocs serve`. +3. Run static analysis: `make type` +4. Update documentation if needed. Docs are located in the `docs` directory. You can serve docs using `mkdocs serve`. ### Optional: Pre-Commit Hooks diff --git a/Makefile b/Makefile index 633025c7d..228b81435 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,20 @@ MKDOCS_SERVE_ADDR ?= localhost:8000 # Default address for mkdocs serve, format: :, override with `make docs-serve MKDOCS_SERVE_ADDR=:` +# Extract major package versions for OpenAI and Pydantic +OPENAI_VERSION_MAJOR := $(shell poetry run python -c 'import openai; print(openai.__version__.split(".")[0])') +PYDANTIC_VERSION_MAJOR := $(shell poetry run python -c 'import pydantic; print(pydantic.__version__.split(".")[0])') + +# Construct the typing command using only major versions +TYPING_CMD := type-pydantic-v$(PYDANTIC_VERSION_MAJOR)-openai-v$(OPENAI_VERSION_MAJOR) + autoformat: poetry run black guardrails/ tests/ poetry run isort --atomic guardrails/ tests/ poetry run docformatter --in-place --recursive guardrails tests +.PHONY: type type: - poetry run pyright guardrails/ + @make $(TYPING_CMD) type-pydantic-v1-openai-v0: echo '{"exclude": ["guardrails/utils/pydantic_utils/v2.py", "guardrails/utils/openai_utils/v1.py"]}' > pyrightconfig.json