ZanSara eb57e1fc09
chore: make Mypy work when Haystack is installed (#3856)
* add ignore statements to each failing line in haystack/

* simplify workflow

* few typos

* mypy cache directory missing

* mypy cache directory missing

* install types from Haystack only

* install types from rest_api too

* mypy vs literal

* install types at check time

* add mypy cache to python cache

* fix version condition

* fix version condition

* try running mypy only on affected files

* try using explicit hashes

* try another approach

* filter python files

* typo

* quotes

* use action
2023-01-18 15:36:10 +01:00

68 lines
2.3 KiB
YAML

name: Python Cache
description: Caches a full installation of Haystack dependencies
inputs:
prefix:
description: 'prefix for the cache (to distinguish OS)'
required: true
default: 'linux'
pythonPath:
description: 'Python path to cache/restore'
required: true
pythonVersion:
description: 'Python version to use'
required: true
default: "3.7"
runs:
using: "composite"
steps:
- name: Get date
shell: bash
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.pythonVersion }}
- name: Cache Python path
id: cache-python-env
uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
# The cache will be rebuild every day and at every change of the dependency files
key: ${{ inputs.prefix }}-py${{ inputs.pythonVersion }}-${{ env.date }}-${{ hashFiles('**/pyproject.toml') }}
- name: Cache Mypy path
id: cache-mypy
uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}/.mypy_cache
# The cache will be rebuild every day and at every change of the dependency files
key: mypy-${{ inputs.prefix }}-py${{ inputs.pythonVersion }}-${{ env.date }}-${{ hashFiles('**/pyproject.toml') }}
- name: Install dependencies
# NOTE: this action runs only on cache miss to refresh the dependencies and make sure the next Haystack install will be faster.
# Do not rely on this step to install Haystack itself!
# The cache can last way longer than a specific action's run, so older Haystack version could be carried over and the tests will run
# against the cached code instead of the new changes.
if: steps.cache-python-env.outputs.cache-hit != 'true'
shell: bash
run: |
python -m pip install --upgrade pip
pip install .[all]
pip install rest_api/
- name: Install mypy dependencies
shell: bash
if: inputs.pythonVersion != 3.7
run: python -m mypy --install-types --non-interactive --cache-dir=${{ env.pythonLocation }}/.mypy_cache/ haystack/ rest_api/ --exclude=rest_api/build/ --exclude=rest_api/test/