Skip to content

Commit 3b8e293

Browse files
author
Sam Porter
committed
ci: tighten test selection and fix ruff findings
1 parent 75a1e99 commit 3b8e293

20 files changed

Lines changed: 93 additions & 62 deletions

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
ruff format --check .
2929
- name: Run CI-friendly tests
3030
run: |
31-
python -m pytest tests/ -v -m "not requires_sirf and not requires_simind and not ci_skip" --cov=sirf_simind_connection --cov-report=xml
31+
python -m pytest tests/ -v -m "not integration and not requires_sirf and not requires_stir and not requires_simind and not requires_pytomography and not requires_cil and not requires_setr and not ci_skip" --cov=sirf_simind_connection --cov-report=xml
3232
- name: Upload coverage to Codecov
3333
uses: codecov/codecov-action@v4
3434
with:
@@ -54,4 +54,4 @@ jobs:
5454
python -m build
5555
- name: Check package
5656
run: |
57-
twine check dist/*
57+
twine check dist/*

examples/04_custom_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,19 @@ def main():
216216
"--backend",
217217
type=str,
218218
choices=["sirf", "stir"],
219-
help="Force a specific backend (sirf or stir). If not specified, auto-detection is used.",
219+
help=(
220+
"Force a specific backend (sirf or stir). "
221+
"If not specified, auto-detection is used."
222+
),
220223
)
221224
args = parser.parse_args()
222225

223226
# Set backend if specified and backend layer is available.
224227
if args.backend:
225228
if set_backend is None:
226229
print(
227-
f"Backend '{args.backend}' requested, but backend libraries are not installed."
230+
f"Backend '{args.backend}' requested, "
231+
"but backend libraries are not installed."
228232
)
229233
else:
230234
set_backend(args.backend)

examples/06_schneider_density_conversion.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,20 @@ def create_ct_image_example(output_dir):
303303
"--backend",
304304
type=str,
305305
choices=["sirf", "stir"],
306-
help="Force a specific backend (sirf or stir). Note: This example doesn't use backends but the argument is provided for consistency.",
306+
help=(
307+
"Force a specific backend (sirf or stir). "
308+
"Note: This example doesn't use backends, but the argument is "
309+
"provided for consistency."
310+
),
307311
)
308312
args = parser.parse_args()
309313

310-
# Note: This example doesn't actually use the backend, but we accept the argument for consistency
314+
# This example does not use backend implementations directly, but accepts
315+
# the argument for consistency with the rest of the examples.
311316
if args.backend:
312317
print(
313-
f"Note: Backend argument '{args.backend}' specified but not used in this example."
318+
f"Note: Backend argument '{args.backend}' "
319+
"specified but not used in this example."
314320
)
315321

316322
main()

examples/_python_connector_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
def require_simind() -> None:
1515
if shutil.which("simind") is None:
1616
raise RuntimeError(
17-
"SIMIND executable not found in PATH. Install SIMIND before running this example."
17+
"SIMIND executable not found in PATH. "
18+
"Install SIMIND before running this example."
1819
)
1920

2021

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ select = ["F", "E", "W", "I"] # Include import sorting (I)
7777
force-single-line = false
7878
lines-after-imports = 2
7979
known-first-party = ["sirf_simind_connection"]
80+
81+
[tool.ruff.lint.per-file-ignores]
82+
"sirf_simind_connection/configs/get_sirf_sinos.ipynb" = ["E501", "E722"]

pytest-ci.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ addopts =
1818
-v
1919
--tb=short
2020
--strict-markers
21-
-m "not requires_sirf and not requires_simind and not ci_skip"
21+
-m "not integration and not requires_sirf and not requires_stir and not requires_simind and not requires_pytomography and not requires_cil and not requires_setr and not ci_skip"
2222
--durations=10
2323

2424
# Output
@@ -29,4 +29,4 @@ junit_family = xunit2
2929
# --cov=sirf_simind_connection
3030
# --cov-report=xml
3131
# --cov-report=html
32-
# --cov-report=term-missing
32+
# --cov-report=term-missing

sirf_simind_connection/backends/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
set_backend("stir") # Force STIR Python
1818
"""
1919

20+
import importlib
2021
import logging
2122
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
2223

@@ -141,14 +142,14 @@ def get_backend() -> str:
141142

142143
# Auto-detect
143144
try:
144-
import sirf.STIR
145+
importlib.import_module("sirf.STIR")
145146

146147
_backend = "sirf"
147148
logger.info("Auto-detected SIRF backend")
148149
except ImportError:
149150
try:
150-
import stir
151-
import stirextra
151+
importlib.import_module("stir")
152+
importlib.import_module("stirextra")
152153

153154
_backend = "stir"
154155
logger.info("Auto-detected STIR Python backend")
@@ -182,13 +183,13 @@ def set_backend(backend: Literal["sirf", "stir"]) -> None:
182183
# Verify the backend is available
183184
if backend == "sirf":
184185
try:
185-
import sirf.STIR
186+
importlib.import_module("sirf.STIR")
186187
except ImportError:
187188
raise ImportError("SIRF is not available")
188189
elif backend == "stir":
189190
try:
190-
import stir
191-
import stirextra
191+
importlib.import_module("stir")
192+
importlib.import_module("stirextra")
192193
except ImportError:
193194
raise ImportError("STIR Python is not available")
194195

@@ -355,7 +356,8 @@ def create_acquisition_data(
355356
if filepath_or_object is None:
356357
raise NotImplementedError(
357358
"Creating empty STIR ProjData requires exam_info and proj_data_info. "
358-
"Please provide a filepath or use StirAcquisitionData.create_empty() directly."
359+
"Please provide a filepath or use "
360+
"StirAcquisitionData.create_empty() directly."
359361
)
360362
elif isinstance(filepath_or_object, str):
361363
return StirAcquisitionData.read_from_file(filepath_or_object)

sirf_simind_connection/backends/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
class ImageDataInterface(ABC):
15-
"""Abstract interface for image data objects (ImageData or FloatVoxelsOnCartesianGrid)."""
15+
"""Abstract interface for image data objects.
16+
17+
Includes SIRF ``ImageData`` and STIR ``FloatVoxelsOnCartesianGrid`` types.
18+
"""
1619

1720
@classmethod
1821
@abstractmethod
@@ -123,7 +126,11 @@ def maximum(self, value: float) -> None:
123126
@property
124127
@abstractmethod
125128
def native_object(self):
126-
"""Get the underlying native object (ImageData or FloatVoxelsOnCartesianGrid)."""
129+
"""Get the underlying native object.
130+
131+
Returns either SIRF ``ImageData`` or STIR
132+
``FloatVoxelsOnCartesianGrid``.
133+
"""
127134
pass
128135

129136
# Arithmetic operations

sirf_simind_connection/backends/sirf_backend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
from sirf_simind_connection.utils.import_helpers import get_sirf_types
1313

14+
from .base import AcquisitionDataInterface, ImageDataInterface
1415

15-
ImageData, AcquisitionData, SIRF_AVAILABLE = get_sirf_types()
1616

17-
from .base import AcquisitionDataInterface, ImageDataInterface
17+
ImageData, AcquisitionData, SIRF_AVAILABLE = get_sirf_types()
1818

1919

2020
class SirfImageData(ImageDataInterface):
@@ -230,7 +230,8 @@ def get_energy_window_bounds(self) -> Tuple[float, float]:
230230
Tuple[float, float]: (lower_threshold, upper_threshold) in keV
231231
232232
Raises:
233-
NotImplementedError: SIRF backend does not currently support accessing energy window bounds
233+
NotImplementedError: SIRF backend does not currently support
234+
accessing energy window bounds.
234235
"""
235236
raise NotImplementedError(
236237
"SIRF backend does not currently support accessing energy window bounds. "

sirf_simind_connection/builders/acquisition_builder.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
import numpy as np
88
import pydicom
99

10+
from sirf_simind_connection.utils.backend_access import BACKEND_AVAILABLE, BACKENDS
11+
1012
# Conditional import for SIRF types
1113
from sirf_simind_connection.utils.import_helpers import get_sirf_types
14+
from sirf_simind_connection.utils.io_utils import temporary_directory
1215

1316

1417
_, AcquisitionData, SIRF_AVAILABLE = get_sirf_types()
1518

16-
# Import backend factory using centralized access
17-
from sirf_simind_connection.utils.backend_access import BACKEND_AVAILABLE, BACKENDS
18-
from sirf_simind_connection.utils.io_utils import temporary_directory
19-
20-
2119
# Unpack interfaces needed by builder
2220
create_acquisition_data = BACKENDS.factories.create_acquisition_data
2321

@@ -168,7 +166,8 @@ def _load_acquisition(self, header_path: str):
168166
return AcquisitionData(header_path)
169167

170168
raise ImportError(
171-
"Unable to load acquisition data: neither SIRF nor STIR Python backends are available."
169+
"Unable to load acquisition data: neither SIRF nor STIR Python "
170+
"backends are available."
172171
)
173172

174173
@staticmethod

0 commit comments

Comments
 (0)