Skip to content

Commit

Permalink
added ruff, pre-commit as github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedNasser8 committed Jun 9, 2024
1 parent bc07ea5 commit 37e620f
Show file tree
Hide file tree
Showing 22 changed files with 567 additions and 429 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

20 changes: 19 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Lint and Auto-Fix Code

on: [push, pull_request]
on:
push:
pull_request:
branches:
- main

jobs:
lint_and_fix:
Expand All @@ -26,3 +30,17 @@ jobs:
- name: Run flake8 (lint only)
run: flake8 .

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
/.venv
dist
pytest_cache
src/osipi/__pycache__
tests/__pycache__
41 changes: 16 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8 # Use the latest version
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- id: ruff
args: [--fix] # Optional: to enable lint fixes
- id: ruff-format
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
args: [ '--max-line-length=100' ]


- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--line-length=70]

- repo: https://github.com/PyCQA/docformatter
rev: v1.4
args:
- --exclude=venv,.git,__pycache__,.eggs,.mypy_cache,.pytest_cache
- --max-line-length=100
- --ignore=E203
- --per-file-ignores=__init__.py:F401
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: docformatter
args: [--in-place, --recursive, --blank, --force-wrap, --wrap-summaries=100,--wrap-descriptions=100]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
hooks:
- id: autopep8
args: [--in-place, --aggressive, --aggressive, --recursive, --max-line-length=100]
2 changes: 1 addition & 1 deletion docs/examples/aif/plot_aif_parker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np

import osipi

# %%
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/aif/plot_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np

import osipi

# %%
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tissue/plot_extended_tofts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np

import osipi

# %%
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tissue/plot_tofts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np

import osipi

# %%
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os

# -- Project information ---------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import sys
Expand Down
193 changes: 110 additions & 83 deletions docs/source/generated/examples/aif/plot_aif_parker.ipynb
Original file line number Diff line number Diff line change
@@ -1,86 +1,113 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# The Parker AIF - a play with variables\n\nSimulating a Parker AIF with different settings. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import necessary packages\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nimport osipi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Generate synthetic AIF with default settings and plot the result.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Define time points in units of seconds - in this case we use a time resolution of 0.5 sec and a total duration of 6 minutes.\nt = np.arange(0, 6*60, 0.5)\n\n# Create an AIF with default settings\nca = osipi.aif_parker(t)\n\n# Plot the AIF over the full range\nplt.plot(t, ca, 'r-')\nplt.plot(t, 0*t, 'k-')\nplt.xlabel('Time (sec)')\nplt.ylabel('Plasma concentration (mM)')\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The bolus arrival time (BAT) defaults to 0s. What happens if we change it? Let's try, by changing it in steps of 30s:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ca = osipi.aif_parker(t, BAT=0)\nplt.plot(t, ca, 'b-', label='BAT = 0s')\nca = osipi.aif_parker(t, BAT=30)\nplt.plot(t, ca, 'r-', label='BAT = 30s')\nca = osipi.aif_parker(t, BAT=60)\nplt.plot(t, ca, 'g-', label='BAT = 60s')\nca = osipi.aif_parker(t, BAT=90)\nplt.plot(t, ca, 'm-', label='BAT = 90s')\nplt.xlabel('Time (sec)')\nplt.ylabel('Plasma concentration (mM)')\nplt.legend()\nplt.show()\n\n# Choose the last image as a thumbnail for the gallery\n# sphinx_gallery_thumbnail_number = -1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# The Parker AIF - a play with variables\n\nSimulating a Parker AIF with different settings. \n"
]
},
"nbformat": 4,
"nbformat_minor": 0
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import necessary packages\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import osipi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Generate synthetic AIF with default settings and plot the result.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Define time points in units of seconds - in this case we use a time resolution of 0.5 sec and a total duration of 6 minutes.\n",
"t = np.arange(0, 6 * 60, 0.5)\n",
"\n",
"# Create an AIF with default settings\n",
"ca = osipi.aif_parker(t)\n",
"\n",
"# Plot the AIF over the full range\n",
"plt.plot(t, ca, \"r-\")\n",
"plt.plot(t, 0 * t, \"k-\")\n",
"plt.xlabel(\"Time (sec)\")\n",
"plt.ylabel(\"Plasma concentration (mM)\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The bolus arrival time (BAT) defaults to 0s. What happens if we change it? Let's try, by changing it in steps of 30s:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ca = osipi.aif_parker(t, BAT=0)\n",
"plt.plot(t, ca, \"b-\", label=\"BAT = 0s\")\n",
"ca = osipi.aif_parker(t, BAT=30)\n",
"plt.plot(t, ca, \"r-\", label=\"BAT = 30s\")\n",
"ca = osipi.aif_parker(t, BAT=60)\n",
"plt.plot(t, ca, \"g-\", label=\"BAT = 60s\")\n",
"ca = osipi.aif_parker(t, BAT=90)\n",
"plt.plot(t, ca, \"m-\", label=\"BAT = 90s\")\n",
"plt.xlabel(\"Time (sec)\")\n",
"plt.ylabel(\"Plasma concentration (mM)\")\n",
"plt.legend()\n",
"plt.show()\n",
"\n",
"# Choose the last image as a thumbnail for the gallery\n",
"# sphinx_gallery_thumbnail_number = -1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
2 changes: 1 addition & 1 deletion docs/source/generated/examples/aif/plot_aif_parker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""

import matplotlib.pyplot as plt

# %%
# Import necessary packages
import numpy as np

import osipi

# %%
Expand Down
Loading

0 comments on commit 37e620f

Please sign in to comment.