Skip to content

Lint project and add check to CI #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint

on: [ pull_request, workflow_dispatch ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff

- name: Lint check
run: ruff check pytissueoptics
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ line-length = 120
target-version = "py39"

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"PT009", # unittest-style asserts
"F405", # Name defined from star imports
]

[tool.ruff.format]
quote-style = "double"
Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .scene import *
from .rayscattering import *
from importlib.metadata import version
from .scene import * # noqa: F403
from .rayscattering import * # noqa: F403

__version__ = version("pytissueoptics")
7 changes: 4 additions & 3 deletions pytissueoptics/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import argparse
import os
import sys
import argparse

from pytissueoptics import __version__
from pytissueoptics.examples import loadExamples

ap = argparse.ArgumentParser(prog="python -m pytissueoptics", description="Run PyTissueOptics examples. ")
ap.add_argument("-v", "--version", action="version", version=f"PyTissueOptics {__version__}")
ap.add_argument("-e", "--examples", required=False, default="all",
help="Run specific examples by number, e.g. -e 1,2,3. ")
ap.add_argument(
"-e", "--examples", required=False, default="all", help="Run specific examples by number, e.g. -e 1,2,3. "
)
ap.add_argument("-l", "--list", required=False, action="store_true", help="List available examples. ")
ap.add_argument("-t", "--tests", required=False, action="store_true", help="Run unit tests. ")

Expand Down
6 changes: 3 additions & 3 deletions pytissueoptics/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import importlib
import os
import re
import sys
import importlib
from dataclasses import dataclass
from typing import List

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter
from pygments.lexers import PythonLexer

EXAMPLE_MODULE = "rayscattering"
EXAMPLE_FILE_PATTERN = r"^(ex\d+)\.py$"
Expand All @@ -32,7 +32,7 @@ def loadExamples() -> List[Example]:
for file in EXAMPLE_FILES:
name = re.match(EXAMPLE_FILE_PATTERN, file).group(1)
module = importlib.import_module(f"pytissueoptics.examples.{EXAMPLE_MODULE}.{name}")
with open(os.path.join(EXAMPLE_DIR, file), 'r') as f:
with open(os.path.join(EXAMPLE_DIR, file), "r") as f:
srcCode = f.read()
pattern = r"def exampleCode\(\):\s*(.*?)\s*if __name__ == \"__main__\":"
srcCode = re.search(pattern, srcCode, re.DOTALL).group(1)
Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/benchmarks/cube60.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "MCX Homogeneous cube"

Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/benchmarks/cubesph60b.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "MCX Sphere"

Expand Down
10 changes: 3 additions & 7 deletions pytissueoptics/examples/benchmarks/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
# By adjusting the path, we use the current version in development.

import sys
import os
sys.path.insert(0,
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__))))))
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
20 changes: 14 additions & 6 deletions pytissueoptics/examples/benchmarks/skinvessel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Skin vessel"

Expand All @@ -13,15 +13,23 @@ def exampleCode():

# Units in mm and mm-1
waterLayer = Cuboid(1, 0.1, 1, material=ScatteringMaterial(mu_a=0.00004, mu_s=1, g=1, n=1.33), label="water")
epidermisLayer = Cuboid(1, 0.06, 1, material=ScatteringMaterial(mu_a=1.65724, mu_s=37.59398, g=0.9, n=1.44), label="epidermis")
dermisLayer = Cuboid(1, 0.84, 1, material=ScatteringMaterial(mu_a=0.04585, mu_s=35.65406, g=0.9, n=1.38), label="dermis")
epidermisLayer = Cuboid(
1, 0.06, 1, material=ScatteringMaterial(mu_a=1.65724, mu_s=37.59398, g=0.9, n=1.44), label="epidermis"
)
dermisLayer = Cuboid(
1, 0.84, 1, material=ScatteringMaterial(mu_a=0.04585, mu_s=35.65406, g=0.9, n=1.38), label="dermis"
)
zStack = waterLayer.stack(epidermisLayer).stack(dermisLayer)
zStack.translateTo(Vector(0, 0, 0))
bloodVessel = Cylinder(0.1, 0.99, material=ScatteringMaterial(mu_a=23.05427, mu_s=9.3985, g=0.9, n=1.361), label="blood")
bloodVessel = Cylinder(
0.1, 0.99, material=ScatteringMaterial(mu_a=23.05427, mu_s=9.3985, g=0.9, n=1.361), label="blood"
)

scene = ScatteringScene([zStack, bloodVessel])

source = DirectionalSource(position=Vector(0, -0.399, 0), direction=Vector(0, 1, 0), N=N, diameter=0.6, displaySize=0.06)
source = DirectionalSource(
position=Vector(0, -0.399, 0), direction=Vector(0, 1, 0), N=N, diameter=0.6, displaySize=0.06
)
logger = EnergyLogger(scene, defaultBinSize=0.001)
source.propagate(scene, logger=logger)

Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/benchmarks/sphshells.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "MCX Spherical shells"

Expand Down
10 changes: 3 additions & 7 deletions pytissueoptics/examples/rayscattering/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
# By adjusting the path, we use the current version in development.

import sys
import os
sys.path.insert(0,
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__))))))
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
9 changes: 5 additions & 4 deletions pytissueoptics/examples/rayscattering/ex01.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Divergent source propagation through a multi-layered tissue"

Expand All @@ -12,8 +12,9 @@ def exampleCode():

tissue = samples.PhantomTissue()
logger = EnergyLogger(tissue)
source = DivergentSource(position=Vector(0, 0, -0.2), direction=Vector(0, 0, 1), N=N,
diameter=0.1, divergence=0.4, displaySize=0.2)
source = DivergentSource(
position=Vector(0, 0, -0.2), direction=Vector(0, 0, 1), N=N, diameter=0.1, divergence=0.4, displaySize=0.2
)

tissue.show(source=source)

Expand Down
10 changes: 6 additions & 4 deletions pytissueoptics/examples/rayscattering/ex02.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Propagation in an Infinite Medium"

Expand All @@ -10,14 +10,16 @@

def exampleCode():
import math

N = 10000 if hardwareAccelerationIsAvailable() else 25

myMaterial = ScatteringMaterial(mu_s=30.0, mu_a=0.1, g=0.9)
tissue = samples.InfiniteTissue(myMaterial)

logger = EnergyLogger(tissue)
source = DivergentSource(position=Vector(0, 0, 0), direction=Vector(0, 0, 1), N=N,
diameter=0.2, divergence=math.pi/4)
source = DivergentSource(
position=Vector(0, 0, 0), direction=Vector(0, 0, 1), N=N, diameter=0.2, divergence=math.pi / 4
)

source.propagate(tissue, logger=logger)

Expand Down
10 changes: 6 additions & 4 deletions pytissueoptics/examples/rayscattering/ex03.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Propagate in a in a non-scattering custom scene with an optical lens." \
"Learn to save and load your data so you don't have to simulate again."
TITLE = (
"Propagate in a in a non-scattering custom scene with an optical lens."
"Learn to save and load your data so you don't have to simulate again."
)

DESCRIPTION = """
Thin Cuboid solids are used as screens for visualization, and a SymmetricLens() as a lens. They all go into a
Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/rayscattering/ex04.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Custom layer stack"

Expand Down
11 changes: 6 additions & 5 deletions pytissueoptics/examples/rayscattering/ex05.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env
from pytissueoptics import *
import env # noqa: F401
from pytissueoptics import * # noqa: F403

TITLE = "Sphere inside a cube"

Expand All @@ -14,12 +14,13 @@ def exampleCode():
material2 = ScatteringMaterial(mu_s=30, mu_a=0.2, g=0.9, n=1.7)

cube = Cuboid(a=3, b=3, c=3, position=Vector(0, 0, 0), material=material1, label="cube")
sphere = Sphere(radius=1, order=3, position=Vector(0, 0, 0), material=material2, label="sphere",
smooth=True)
sphere = Sphere(radius=1, order=3, position=Vector(0, 0, 0), material=material2, label="sphere", smooth=True)
scene = ScatteringScene([cube, sphere])

logger = EnergyLogger(scene)
source = DirectionalSource(position=Vector(0, 0, -2), direction=Vector(0, 0, 1), N=N, diameter=0.5, displaySize=0.25)
source = DirectionalSource(
position=Vector(0, 0, -2), direction=Vector(0, 0, 1), N=N, diameter=0.5, displaySize=0.25
)

source.propagate(scene, logger)

Expand Down
10 changes: 3 additions & 7 deletions pytissueoptics/examples/scene/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
# By adjusting the path, we use the current version in development.

import sys
import os
sys.path.insert(0,
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__))))))
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example0.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import env
import env # noqa: F401

TITLE = "Explore different Shapes"

Expand All @@ -10,7 +10,7 @@


def exampleCode():
from pytissueoptics.scene import Vector, Cuboid, Sphere, Ellipsoid, MayaviViewer
from pytissueoptics.scene import Cuboid, Ellipsoid, MayaviViewer, Sphere, Vector

cuboid = Cuboid(a=1, b=3, c=1, position=Vector(1, 0, 0))
sphere = Sphere(radius=0.5, position=Vector(0, 0, 0))
Expand Down
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import env
import env # noqa: F401

TITLE = "Transforms on a Solid"

Expand All @@ -8,7 +8,7 @@


def exampleCode():
from pytissueoptics.scene import Vector, Cuboid, MayaviViewer
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector

centerCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 0, 0))
topCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 2, 0))
Expand Down
6 changes: 3 additions & 3 deletions pytissueoptics/examples/scene/example2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import env
import env # noqa: F401

TITLE = "Stacking Cuboids"

Expand All @@ -7,7 +7,7 @@


def exampleCode():
from pytissueoptics.scene import Cuboid, Vector, MayaviViewer
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector

cuboid1 = Cuboid(1, 1, 1, position=Vector(2, 0, 0))
cuboid2 = Cuboid(2, 1, 1, position=Vector(0, 2, 0))
Expand All @@ -26,4 +26,4 @@ def exampleCode():


if __name__ == "__main__":
exampleCode()
exampleCode()
4 changes: 2 additions & 2 deletions pytissueoptics/examples/scene/example3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import env
import env # noqa: F401

TITLE = "Load a .obj wavefront file"

DESCRIPTION = """ """


def exampleCode():
from pytissueoptics.scene import loadSolid, MayaviViewer
from pytissueoptics.scene import MayaviViewer, loadSolid

solid = loadSolid("pytissueoptics/examples/scene/droid.obj")

Expand Down
12 changes: 10 additions & 2 deletions pytissueoptics/examples/scene/example4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import env
import env # noqa: F401

TITLE = "Lenses"

DESCRIPTION = """Explore different types of lens-shaped solids."""


def exampleCode():
from pytissueoptics.scene import Vector, MayaviViewer, RefractiveMaterial, ThickLens, SymmetricLens, PlanoConvexLens, PlanoConcaveLens
from pytissueoptics.scene import (
MayaviViewer,
PlanoConcaveLens,
PlanoConvexLens,
RefractiveMaterial,
SymmetricLens,
ThickLens,
Vector,
)

material = RefractiveMaterial(refractiveIndex=1.44)
lens1 = ThickLens(30, 60, diameter=25.4, thickness=4, material=material, position=Vector(0, 0, 0))
Expand Down
Loading