Skip to content

Commit

Permalink
Update GHA and pyproject to run more tools via ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
kedhammar committed Dec 11, 2023
1 parent a35c53e commit dce39eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 57 deletions.
60 changes: 12 additions & 48 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
@@ -1,94 +1,58 @@
name: lint-code
on: [push]
jobs:
# Use ruff to check for code style violations
ruff-check:
# Use ruff to check for code style violations
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: ruff --> Check for style violations
# The following style violations will be ignored
# ==============================================
# E402: Module level import not at top of file
# E722: Do not use bare 'except'
# E741: Ambiguous variable name
run: ruff check --ignore E402,E722,E741 --unsafe-fixes .

isort-check:
# Use isort to check that imports are ordered according to best practice
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install isort
- name: isort --> Check for best-practice sorting of imports
run: isort --check .
# Configured in pyproject.toml
run: ruff check .

# Use ruff to check code formatting
ruff-format:
# Use ruff to check code formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: ruff --> Check code formatting
run: ruff format --check .

# Use mypy for static type checking
mypy-check:
# Use mypy for static type checking
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
# Start by installing type stubs
- name: mypy --> Install stubs
run: echo -e "y" | mypy --install-types --ignore-missing-imports --follow-imports=skip --exclude build . || exit 0
run: echo -e "y" | mypy --install-types || exit 0
- name: mypy --> Static type checking
run: mypy --ignore-missing-imports --follow-imports=skip --exclude build .

pyupgrade-check:
# Use pyupgrade to check for outdated syntax
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyupgrade
- name: pyupgrade --> Check for outdated syntax
run: pyupgrade **/*.py
# Configured in pyprojet.toml
run: mypy **/*.py
24 changes: 15 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
title = "scilifelab_epps"

[tool.ruff.lint]

[tool.ruff.lint]
select =[
# === Ruff defaults ===
# Ruff default rules
# ------------------------------
"E4", # pycodestyle Imports
"E7", # pycodestyle Statement
"E9", # pycodestyle Runstyle
"E7", # pycodestyle Statements
"E9", # pycodestyle Runtime
"F", # Pyflakes
# === Additional ===
"I", # isort
"UP", # pyupgrade
]

# Additional Comment
# ------------------------------------------------------
"I", # isort Best-practice sorting of imports
"UP", # pyupgrade Make sure syntax is up-to-date
]
ignore = [
"E402", # Module level import not at top of file
"E722", # Do not use bare 'except'
"E741", # Ambiguous variable name
]
]


[tool.mypy]
ignore_missing_imports = true
follow_imports = 'skip'

0 comments on commit dce39eb

Please sign in to comment.