#!/usr/bin/env bash

# A script for running mypy,
# with all its dependencies installed.

set -o errexit

if [[ ( (! -f requirements/typing.txt) || (requirements/typing.in -nt requirements/typing.txt) ) ]]  || \
   [[ ( (! -f requirements/runtime.txt) || (requirements/runtime.in -nt requirements/runtime.txt) ) ]]
then
    echo "Installing pip-tools and generating (requirements/typing.txt and/or requirements/runtime.txt)"
    pip install pip-tools
    pip-compile requirements/typing.in -o requirements/typing.txt
    pip-compile requirements/runtime.in -o requirements/runtime.txt
fi

echo "Installing typing and runtime deps"
pip install -r requirements/typing.txt -r requirements/runtime.txt

# Run on all files,
# ignoring the paths passed to this script,
# so as not to miss type errors.
# My repo makes use of namespace packages.
# Use the namespace-packages flag
# and specify the package to run on explicitly.
# Note that we do not use --ignore-missing-imports,
# as this can give us false confidence in our results.
mypy --install-types --non-interactive --package kintro --namespace-packages
