-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github Action definition (#11320)
Define a Github Action that can be used as a canonical way of running mypy as part of Github CI workflows as easy as: ``` jobs: lint: runs-on: ubuntu-latest steps: - uses: python/mypy ``` The action is inspired by its equivalent in black and supports the following options: ``` with: options: "..." # mypy command-line options paths: "." # a list of paths to check version: "0.910" # mypy version to use install_types: yes|no # whether to auto-install stubs ```
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: "Mypy" | ||
description: "Optional Static Typing for Python." | ||
author: "Jukka Lehtosalo and contributors" | ||
inputs: | ||
options: | ||
description: > | ||
Options passed to mypy. Use `mypy --help` to see available options. | ||
required: false | ||
paths: | ||
description: > | ||
Explicit paths to run mypy on. Defaults to the current directory. | ||
required: false | ||
default: "." | ||
version: | ||
description: > | ||
Mypy version to use (PEP440) - e.g. "0.910" | ||
required: false | ||
default: "" | ||
install_types: | ||
description: > | ||
Whether to automatically install missing library stub packages. | ||
('yes'|'no', default: 'yes') | ||
default: "yes" | ||
install_project_dependencies: | ||
description: > | ||
Whether to attempt to install project dependencies into mypy | ||
environment. ('yes'|'no', default: 'yes') | ||
default: "yes" | ||
branding: | ||
color: "blue" | ||
icon: "check-circle" | ||
runs: | ||
using: composite | ||
steps: | ||
- name: mypy setup | ||
shell: bash | ||
run: | | ||
echo ::group::Installing mypy... | ||
export PIP_DISABLE_PIP_VERSION_CHECK=1 | ||
if [ "$RUNNER_OS" == "Windows" ]; then | ||
HOST_PYTHON=python | ||
else | ||
HOST_PYTHON=python3 | ||
fi | ||
venv_script="import os.path; import venv; import sys; | ||
path = os.path.join(r'${{ github.action_path }}', '.mypy-venv'); | ||
venv.main([path]); | ||
bin_subdir = 'Scripts' if sys.platform == 'win32' else 'bin'; | ||
print(os.path.join(path, bin_subdir, 'python')); | ||
" | ||
VENV_PYTHON=$(echo $venv_script | "$HOST_PYTHON") | ||
mypy_spec="mypy" | ||
if [ -n "${{ inputs.version }}" ]; then | ||
mypy_spec+="==${{ inputs.version }}" | ||
fi | ||
if ! "$VENV_PYTHON" -m pip install "$mypy_spec"; then | ||
echo "::error::Could not install mypy." | ||
exit 1 | ||
fi | ||
echo ::endgroup:: | ||
if [ "${{ inputs.install_project_dependencies }}" == "yes" ]; then | ||
VENV=$("$VENV_PYTHON" -c 'import sys;print(sys.prefix)') | ||
echo ::group::Installing project dependencies... | ||
"$VENV_PYTHON" -m pip download --dest="$VENV"/deps . | ||
"$VENV_PYTHON" -m pip install -U --find-links="$VENV"/deps "$VENV"/deps/* | ||
echo ::endgroup:: | ||
fi | ||
echo ::group::Running mypy... | ||
mypy_opts="" | ||
if [ "${{ inputs.install_types }}" == "yes" ]; then | ||
mypy_opts+="--install-types --non-interactive" | ||
fi | ||
echo "mypy $mypy_opts ${{ inputs.options }} ${{ inputs.paths }}" | ||
"$VENV_PYTHON" -m mypy $mypy_opts ${{ inputs.options }} ${{ inputs.paths }} | ||
echo ::endgroup:: |