From 7d807013814df29608e3b7b916a0b68a2417e126 Mon Sep 17 00:00:00 2001 From: Daulet Amirkhanov Date: Wed, 6 Aug 2025 13:35:34 +0100 Subject: [PATCH] chore: update mypy and create a GitHub workflow --- .github/workflows/basic_tests_with_mypy.yml | 197 ++++++++++++++++++++ mypy.ini | 10 +- 2 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/basic_tests_with_mypy.yml diff --git a/.github/workflows/basic_tests_with_mypy.yml b/.github/workflows/basic_tests_with_mypy.yml new file mode 100644 index 000000000..d9367ba1d --- /dev/null +++ b/.github/workflows/basic_tests_with_mypy.yml @@ -0,0 +1,197 @@ +name: Reusable Basic Tests with MyPy + +on: + workflow_call: + inputs: + python-version: + required: false + type: string + default: '3.11.x' + secrets: + LLM_PROVIDER: + required: true + LLM_MODEL: + required: true + LLM_ENDPOINT: + required: true + LLM_API_KEY: + required: true + LLM_API_VERSION: + required: true + EMBEDDING_PROVIDER: + required: true + EMBEDDING_MODEL: + required: true + EMBEDDING_ENDPOINT: + required: true + EMBEDDING_API_KEY: + required: true + EMBEDDING_API_VERSION: + required: true + +env: + RUNTIME__LOG_LEVEL: ERROR + ENV: 'dev' + +jobs: + + lint: + name: Run Linting + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Linting + uses: astral-sh/ruff-action@v2 + + format-check: + name: Run Formatting Check + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Formatting Check + uses: astral-sh/ruff-action@v2 + with: + args: "format --check" + + mypy-check: + name: Run MyPy Type Checking + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run MyPy on Critical Interfaces + shell: bash + run: | + poetry run mypy cognee/infrastructure/databases/graph/graph_db_interface.py + poetry run mypy cognee/infrastructure/databases/graph/neo4j_driver/adapter.py + poetry run mypy cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py + + unit-tests: + name: Run Unit Tests + runs-on: ubuntu-22.04 + env: + LLM_PROVIDER: openai + LLM_MODEL: ${{ secrets.LLM_MODEL }} + LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }} + LLM_API_KEY: ${{ secrets.LLM_API_KEY }} + LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }} + + EMBEDDING_PROVIDER: openai + EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }} + EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }} + EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }} + EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Unit Tests + run: poetry run pytest cognee/tests/unit/ + + integration-tests: + name: Run Integration Tests + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Integration Tests + run: poetry run pytest cognee/tests/integration/ + + simple-examples: + name: Run Simple Examples + runs-on: ubuntu-22.04 + env: + LLM_PROVIDER: openai + LLM_MODEL: ${{ secrets.LLM_MODEL }} + LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }} + LLM_API_KEY: ${{ secrets.LLM_API_KEY }} + LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }} + + EMBEDDING_PROVIDER: openai + EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }} + EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }} + EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }} + EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Simple Examples + run: poetry run python ./examples/python/simple_example.py + + graph-tests: + name: Run Basic Graph Tests + runs-on: ubuntu-22.04 + env: + LLM_PROVIDER: openai + LLM_MODEL: ${{ secrets.LLM_MODEL }} + LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }} + LLM_API_KEY: ${{ secrets.LLM_API_KEY }} + LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }} + + EMBEDDING_PROVIDER: openai + EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }} + EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }} + EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }} + EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cognee Setup + uses: ./.github/actions/cognee_setup + with: + python-version: ${{ inputs.python-version }} + + - name: Run Graph Tests + run: poetry run python ./examples/python/code_graph_example.py --repo_path ./cognee/tasks/graph \ No newline at end of file diff --git a/mypy.ini b/mypy.ini index ba3dd40a4..8050645c5 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,7 +1,7 @@ [mypy] -python_version=3.8 +python_version=3.10 ignore_missing_imports=false -strict_optional=false +strict_optional=true warn_redundant_casts=true disallow_any_generics=true disallow_untyped_defs=true @@ -10,6 +10,12 @@ warn_return_any=true namespace_packages=true warn_unused_ignores=true show_error_codes=true +disallow_incomplete_defs=true +disallow_untyped_decorators=true +no_implicit_optional=true +warn_unreachable=true +warn_no_return=true +warn_unused_configs=true #exclude=reflection/module_cases/* exclude=docs/examples/archive/*|tests/reflection/module_cases/*