Skip to content

fix: pre-commit python version #176

fix: pre-commit python version

fix: pre-commit python version #176

# python linting - pylint and flake8
# pytest
name: Python application using pip
on:
push:
branches: [ "main", "dev*", "dev/**" ]
pull_request:
branches: [ "main", "dev*", "dev/**" ]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install pre-commit pytest
if [ -f "requirements/requirements_ci-cd.txt" ]; then
pip install -r requirements/requirements_ci-cd.txt
fi
- name: Install package
shell: bash
run: |
pip install -e .
- name: Compute diff range
id: range
shell: bash
run: |
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
echo "from=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
echo "to=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
elif [ -n "${{ github.event.before }}" ] \
&& [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
echo "from=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
echo "to=${{ github.sha }}" >> "$GITHUB_OUTPUT"
else
echo "from=HEAD~1" >> "$GITHUB_OUTPUT"
echo "to=HEAD" >> "$GITHUB_OUTPUT"
fi
- name: Cache pre-commit envs
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Lint via pre-commit (changed files only)
shell: bash
run: |
pre-commit run \
--from-ref "${{ steps.range.outputs.from }}" \
--to-ref "${{ steps.range.outputs.to }}" \
--show-diff-on-failure
- name: Get month
id: date
shell: bash
run: echo "month=$(date +'%Y-%m')" >> "$GITHUB_OUTPUT"
- name: Get pooch cache directory
id: cache-dir
shell: python
run: |
import pooch, os
cache = str(pooch.os_cache("proteopy"))
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"path={cache}\n")
- name: Cache downloaded datasets
uses: actions/cache@v4
with:
path: ${{ steps.cache-dir.outputs.path }}
key: proteopy-datasets-${{ runner.os }}-${{ steps.date.outputs.month }}
- name: Test with pytest
run: |
pytest -v -s tests/