Skip to content

Commit

Permalink
mypy, pylint, isort (#66)
Browse files Browse the repository at this point in the history
* add isort, mypy, pylint

* path to pyproject.toml

* test python code

* feedback
  • Loading branch information
SKairinos authored Jan 17, 2024
1 parent 26b8f4d commit ac60097
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 45 deletions.
45 changes: 0 additions & 45 deletions .github/actions/python/test/action.yaml

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/test-python-code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test Python Code

on:
workflow_call:
inputs:
python-version:
description: "The python version to set up."
type: number
required: true
default: 3.8
working-directory:
description: "The current working directory."
type: string
required: true
default: "."
source-path:
description: "The path of the source files."
type: string
required: true
default: "."
check-django-migrations:
description: "Check if there are pending Django migrations."
type: boolean
required: true
default: true
pyproject-toml:
description: "The path to the pyproject.toml file."
type: string
required: true
default: "pyproject.toml"

jobs:
test-py-code:
runs-on: ubuntu-latest
steps:
- name: 🐍 Set up Python ${{ inputs.python-version }} Environment
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main
with:
python-version: ${{ inputs.python-version }}
working-directory: ${{ inputs.working-directory }}
install-args: --dev

- name: πŸ”Ž Check Import Sort
working-directory: ${{ inputs.working-directory }}
run: pipenv run isort --settings-file=${{ inputs.pyproject-toml }} --check ${{ inputs.source-path }}

- name: πŸ”Ž Check Code Format
working-directory: ${{ inputs.working-directory }}
run: if ! pipenv run black --config=${{ inputs.pyproject-toml }} --check ${{ inputs.source-path }}; then exit 1; fi

- name: πŸ”Ž Check Static Type Hints
working-directory: ${{ inputs.working-directory }}
run: pipenv run mypy --config-file=${{ inputs.pyproject-toml }} ${{ inputs.source-path }}

- name: πŸ”Ž Check Static Code
working-directory: ${{ inputs.working-directory }}
run: pipenv run pylint --rcfile=${{ inputs.pyproject-toml }} ${{ inputs.source-path }}

- name: πŸ”Ž Check Django Migrations
if: inputs.check-django-migrations
working-directory: ${{ inputs.working-directory }}
run: pipenv run python manage.py makemigrations --check --dry-run

- name: πŸ§ͺ Test Code Units
working-directory: ${{ inputs.working-directory }}
run: pipenv run pytest -n=auto -c=${{ inputs.pyproject-toml }} ${{ inputs.source-path }}

# TODO: assert code coverage target.

0 comments on commit ac60097

Please sign in to comment.