Skip to content

Commit

Permalink
LORIS-MRI tooling configuration (#1170)
Browse files Browse the repository at this point in the history
* add pyproject.toml

* keep flake8 (for now)

* double type checking

* Use Pyright as main type checker

* remove comment

* test

* test

* change configuration

* add python environment variables

* try factorization

* test

* test

* test

* test

* remove temporary things

* test ruff error

* ruff output github

* further test errors

* test pyright output github

* test

* test

* test

* change comment

* remove test errors

* test

---------

Co-authored-by: Maxime Mulder <[email protected]>
  • Loading branch information
maximemulder and maximemuldermcgill authored Sep 13, 2024
1 parent 79520d7 commit 72634dd
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 43 deletions.
23 changes: 23 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Set up Python
input:
inputs:
python-version:
required: true

runs:
using: composite

steps:
- name: Set up the Python environment
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install Python dependencies
run: pip install -r python/requirements.txt
shell: bash

- name: Set up environment variables
run: echo PYTHONPATH=$PYTHONPATH:/`pwd`/python:/`pwd`/python/react-series-data-viewer >> $GITHUB_ENV
shell: bash
42 changes: 0 additions & 42 deletions .github/workflows/flake8_python_linter.yml

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Python checks

on:
- push
- pull_request

jobs:
ruff:
name: "Ruff"
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11", "3.12"]

steps:
- name: Check out LORIS-MRI
uses: actions/checkout@v4

- name: Set up Python
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Run Ruff
run: ruff check --output-format=github

pyright-strict:
name: "Pyright strict"
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11", "3.12"]

steps:
- name: Check out LORIS-MRI
uses: actions/checkout@v4

- name: Set up Python
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

# Like in the other Pyright run, the `jq` arcane is used to translate the errors from JSON to
# the GitHub actions format
- name: Run Pyright
run: |
pyright --outputjson | jq -r '.generalDiagnostics[] | "::error file=\(.file),line=\(.range.start.line),col=\(.range.start.character)::\(.message)"'
(exit ${PIPESTATUS[0]})
pyrigh-global:
name: "Pyright global"
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11", "3.12"]

steps:
- name: Check out LORIS-MRI
uses: actions/checkout@v4

- name: Set up Python
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Run Pyright
run: |
cd test
pyright --outputjson | jq -r '.generalDiagnostics[] | "::error file=\(.file),line=\(.range.start.line),col=\(.range.start.character)::\(.message)"'
(exit ${PIPESTATUS[0]})
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[tool.ruff]
include = ["python/**/*.py"]
exclude = ["python/react-series-data-viewer"]
line-length = 120
preview = true

[tool.ruff.lint]
ignore = ["E202", "E203", "E221", "E241", "E251", "E272"]
# TODO: Select "F", "I", "N", "UP" and format the codebase accordingly.
select = ["E", "W"]

# The strict type checking configuration is used to type check only the modern (typed) modules. An
# additional basic type checking configuration to type check legacy modules can be found in the
# `test` directory.

[tool.pyright]
include = [
"python/lib/db",
"python/lib/exception",
"python/lib/validate_subject_ids.py"
]
typeCheckingMode = "strict"
reportMissingTypeStubs = "none"

[tool.pytest.ini-options]
testpaths = ["python/tests"]
4 changes: 3 additions & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
boto3
flake8
google
mat73
matplotlib
Expand All @@ -13,7 +12,10 @@ nose
numpy
protobuf>=3.0.0
pybids==0.17.0
pyright
pytest
python-dateutil
ruff
scikit-learn
scipy
sqlalchemy>=2.0.0
Expand Down
7 changes: 7 additions & 0 deletions test/pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"include": ["../python"],
"exclude": ["../python/react-series-data-viewer"],
"typeCheckingMode": "off",
"reportDeprecated": "warning",
"reportMissingImports": "error"
}

0 comments on commit 72634dd

Please sign in to comment.