Skip to content

Commit 0a3bcc5

Browse files
authored
Merge pull request #134 from DCC-Lab/jlb/linting
Lint project and add check to CI
2 parents ee66bdb + 38ce996 commit 0a3bcc5

File tree

194 files changed

+3449
-1916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+3449
-1916
lines changed

.github/workflows/lint.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
3+
on: [ pull_request, workflow_dispatch ]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Python 3.11
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: 3.11
17+
18+
- name: Install Ruff
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install ruff
22+
23+
- name: Lint check
24+
run: ruff check pytissueoptics

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ line-length = 120
5959
target-version = "py39"
6060

6161
[tool.ruff.lint]
62-
select = ["ALL"]
62+
ignore = [
63+
"PT009", # unittest-style asserts
64+
"F405", # Name defined from star imports
65+
]
6366

6467
[tool.ruff.format]
6568
quote-style = "double"

pytissueoptics/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .scene import *
2-
from .rayscattering import *
31
from importlib.metadata import version
2+
from .scene import * # noqa: F403
3+
from .rayscattering import * # noqa: F403
44

55
__version__ = version("pytissueoptics")

pytissueoptics/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import argparse
12
import os
23
import sys
3-
import argparse
44

55
from pytissueoptics import __version__
66
from pytissueoptics.examples import loadExamples
77

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

pytissueoptics/examples/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import importlib
12
import os
23
import re
34
import sys
4-
import importlib
55
from dataclasses import dataclass
66
from typing import List
77

88
from pygments import highlight
9-
from pygments.lexers import PythonLexer
109
from pygments.formatters import TerminalFormatter
10+
from pygments.lexers import PythonLexer
1111

1212
EXAMPLE_MODULE = "rayscattering"
1313
EXAMPLE_FILE_PATTERN = r"^(ex\d+)\.py$"
@@ -32,7 +32,7 @@ def loadExamples() -> List[Example]:
3232
for file in EXAMPLE_FILES:
3333
name = re.match(EXAMPLE_FILE_PATTERN, file).group(1)
3434
module = importlib.import_module(f"pytissueoptics.examples.{EXAMPLE_MODULE}.{name}")
35-
with open(os.path.join(EXAMPLE_DIR, file), 'r') as f:
35+
with open(os.path.join(EXAMPLE_DIR, file), "r") as f:
3636
srcCode = f.read()
3737
pattern = r"def exampleCode\(\):\s*(.*?)\s*if __name__ == \"__main__\":"
3838
srcCode = re.search(pattern, srcCode, re.DOTALL).group(1)

pytissueoptics/examples/benchmarks/cube60.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "MCX Homogeneous cube"
55

pytissueoptics/examples/benchmarks/cubesph60b.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "MCX Sphere"
55

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
22
# By adjusting the path, we use the current version in development.
33

4-
import sys
54
import os
6-
sys.path.insert(0,
7-
os.path.dirname(
8-
os.path.dirname(
9-
os.path.dirname(
10-
os.path.dirname(
11-
os.path.abspath(__file__))))))
5+
import sys
6+
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

pytissueoptics/examples/benchmarks/skinvessel.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "Skin vessel"
55

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

1414
# Units in mm and mm-1
1515
waterLayer = Cuboid(1, 0.1, 1, material=ScatteringMaterial(mu_a=0.00004, mu_s=1, g=1, n=1.33), label="water")
16-
epidermisLayer = Cuboid(1, 0.06, 1, material=ScatteringMaterial(mu_a=1.65724, mu_s=37.59398, g=0.9, n=1.44), label="epidermis")
17-
dermisLayer = Cuboid(1, 0.84, 1, material=ScatteringMaterial(mu_a=0.04585, mu_s=35.65406, g=0.9, n=1.38), label="dermis")
16+
epidermisLayer = Cuboid(
17+
1, 0.06, 1, material=ScatteringMaterial(mu_a=1.65724, mu_s=37.59398, g=0.9, n=1.44), label="epidermis"
18+
)
19+
dermisLayer = Cuboid(
20+
1, 0.84, 1, material=ScatteringMaterial(mu_a=0.04585, mu_s=35.65406, g=0.9, n=1.38), label="dermis"
21+
)
1822
zStack = waterLayer.stack(epidermisLayer).stack(dermisLayer)
1923
zStack.translateTo(Vector(0, 0, 0))
20-
bloodVessel = Cylinder(0.1, 0.99, material=ScatteringMaterial(mu_a=23.05427, mu_s=9.3985, g=0.9, n=1.361), label="blood")
24+
bloodVessel = Cylinder(
25+
0.1, 0.99, material=ScatteringMaterial(mu_a=23.05427, mu_s=9.3985, g=0.9, n=1.361), label="blood"
26+
)
2127

2228
scene = ScatteringScene([zStack, bloodVessel])
2329

24-
source = DirectionalSource(position=Vector(0, -0.399, 0), direction=Vector(0, 1, 0), N=N, diameter=0.6, displaySize=0.06)
30+
source = DirectionalSource(
31+
position=Vector(0, -0.399, 0), direction=Vector(0, 1, 0), N=N, diameter=0.6, displaySize=0.06
32+
)
2533
logger = EnergyLogger(scene, defaultBinSize=0.001)
2634
source.propagate(scene, logger=logger)
2735

pytissueoptics/examples/benchmarks/sphshells.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "MCX Spherical shells"
55

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
22
# By adjusting the path, we use the current version in development.
33

4-
import sys
54
import os
6-
sys.path.insert(0,
7-
os.path.dirname(
8-
os.path.dirname(
9-
os.path.dirname(
10-
os.path.dirname(
11-
os.path.abspath(__file__))))))
5+
import sys
6+
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

pytissueoptics/examples/rayscattering/ex01.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

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

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

1313
tissue = samples.PhantomTissue()
1414
logger = EnergyLogger(tissue)
15-
source = DivergentSource(position=Vector(0, 0, -0.2), direction=Vector(0, 0, 1), N=N,
16-
diameter=0.1, divergence=0.4, displaySize=0.2)
15+
source = DivergentSource(
16+
position=Vector(0, 0, -0.2), direction=Vector(0, 0, 1), N=N, diameter=0.1, divergence=0.4, displaySize=0.2
17+
)
1718

1819
tissue.show(source=source)
1920

pytissueoptics/examples/rayscattering/ex02.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "Propagation in an Infinite Medium"
55

@@ -10,14 +10,16 @@
1010

1111
def exampleCode():
1212
import math
13+
1314
N = 10000 if hardwareAccelerationIsAvailable() else 25
1415

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

1819
logger = EnergyLogger(tissue)
19-
source = DivergentSource(position=Vector(0, 0, 0), direction=Vector(0, 0, 1), N=N,
20-
diameter=0.2, divergence=math.pi/4)
20+
source = DivergentSource(
21+
position=Vector(0, 0, 0), direction=Vector(0, 0, 1), N=N, diameter=0.2, divergence=math.pi / 4
22+
)
2123

2224
source.propagate(tissue, logger=logger)
2325

pytissueoptics/examples/rayscattering/ex03.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

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

79
DESCRIPTION = """
810
Thin Cuboid solids are used as screens for visualization, and a SymmetricLens() as a lens. They all go into a

pytissueoptics/examples/rayscattering/ex04.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "Custom layer stack"
55

pytissueoptics/examples/rayscattering/ex05.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import env
2-
from pytissueoptics import *
1+
import env # noqa: F401
2+
from pytissueoptics import * # noqa: F403
33

44
TITLE = "Sphere inside a cube"
55

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

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

2120
logger = EnergyLogger(scene)
22-
source = DirectionalSource(position=Vector(0, 0, -2), direction=Vector(0, 0, 1), N=N, diameter=0.5, displaySize=0.25)
21+
source = DirectionalSource(
22+
position=Vector(0, 0, -2), direction=Vector(0, 0, 1), N=N, diameter=0.5, displaySize=0.25
23+
)
2324

2425
source.propagate(scene, logger)
2526

pytissueoptics/examples/scene/env.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# We set up the environment so we do not have to install PyTissueOptics to run the examples.
22
# By adjusting the path, we use the current version in development.
33

4-
import sys
54
import os
6-
sys.path.insert(0,
7-
os.path.dirname(
8-
os.path.dirname(
9-
os.path.dirname(
10-
os.path.dirname(
11-
os.path.abspath(__file__))))))
5+
import sys
6+
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

pytissueoptics/examples/scene/example0.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import env
1+
import env # noqa: F401
22

33
TITLE = "Explore different Shapes"
44

@@ -10,7 +10,7 @@
1010

1111

1212
def exampleCode():
13-
from pytissueoptics.scene import Vector, Cuboid, Sphere, Ellipsoid, MayaviViewer
13+
from pytissueoptics.scene import Cuboid, Ellipsoid, MayaviViewer, Sphere, Vector
1414

1515
cuboid = Cuboid(a=1, b=3, c=1, position=Vector(1, 0, 0))
1616
sphere = Sphere(radius=0.5, position=Vector(0, 0, 0))

pytissueoptics/examples/scene/example1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import env
1+
import env # noqa: F401
22

33
TITLE = "Transforms on a Solid"
44

@@ -8,7 +8,7 @@
88

99

1010
def exampleCode():
11-
from pytissueoptics.scene import Vector, Cuboid, MayaviViewer
11+
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector
1212

1313
centerCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 0, 0))
1414
topCube = Cuboid(a=1, b=1, c=1, position=Vector(0, 2, 0))

pytissueoptics/examples/scene/example2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import env
1+
import env # noqa: F401
22

33
TITLE = "Stacking Cuboids"
44

@@ -7,7 +7,7 @@
77

88

99
def exampleCode():
10-
from pytissueoptics.scene import Cuboid, Vector, MayaviViewer
10+
from pytissueoptics.scene import Cuboid, MayaviViewer, Vector
1111

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

2727

2828
if __name__ == "__main__":
29-
exampleCode()
29+
exampleCode()

pytissueoptics/examples/scene/example3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import env
1+
import env # noqa: F401
22

33
TITLE = "Load a .obj wavefront file"
44

55
DESCRIPTION = """ """
66

77

88
def exampleCode():
9-
from pytissueoptics.scene import loadSolid, MayaviViewer
9+
from pytissueoptics.scene import MayaviViewer, loadSolid
1010

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

pytissueoptics/examples/scene/example4.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import env
1+
import env # noqa: F401
22

33
TITLE = "Lenses"
44

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

77

88
def exampleCode():
9-
from pytissueoptics.scene import Vector, MayaviViewer, RefractiveMaterial, ThickLens, SymmetricLens, PlanoConvexLens, PlanoConcaveLens
9+
from pytissueoptics.scene import (
10+
MayaviViewer,
11+
PlanoConcaveLens,
12+
PlanoConvexLens,
13+
RefractiveMaterial,
14+
SymmetricLens,
15+
ThickLens,
16+
Vector,
17+
)
1018

1119
material = RefractiveMaterial(refractiveIndex=1.44)
1220
lens1 = ThickLens(30, 60, diameter=25.4, thickness=4, material=material, position=Vector(0, 0, 0))

0 commit comments

Comments
 (0)