From 90a08a01a826015e7cb16243fd0d0ec3397b13c1 Mon Sep 17 00:00:00 2001 From: iback Date: Mon, 17 Aug 2026 08:44:04 +0000 Subject: [PATCH 1/2] linter workflow runs ruff fixing now --- .github/workflows/linter.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0b91985c..1a960493 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -6,19 +6,25 @@ on: pull_request: branches: [ main ] +permissions: + contents: write + jobs: ruff: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - uses: actions/setup-python@v5 - run: pip install ruff - - run: ruff check . #--fix - #- uses: chartboost/ruff-action@v1 - # with: - # fix_args: --fix - # with: - # args: --check . - - uses: stefanzweifel/git-auto-commit-action@v4 + - name: Apply ruff auto-fixes + run: | + ruff check . --fix + ruff format . + - name: Commit auto-fixes + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: 'style fixes by ruff' + - name: Gate on remaining lint errors + run: ruff check . From f8b4362c7823d9052a5577f97c73997afab9a44a Mon Sep 17 00:00:00 2001 From: Hendrik-code <19862882+Hendrik-code@users.noreply.github.com> Date: Mon, 17 Aug 2026 08:46:51 +0000 Subject: [PATCH 2/2] style fixes by ruff --- README.md | 4 ++-- TPTBox/core/README.md | 3 ++- TPTBox/core/README_BIDS.md | 7 +------ TPTBox/core/README_NII.md | 1 + TPTBox/core/README_POI.md | 12 +++--------- TPTBox/logger/README.md | 3 ++- TPTBox/registration/README.md | 5 ++--- TPTBox/spine/snapshot2D/README.md | 28 +++++++++++++++++----------- TPTBox/spine/spinestats/README.md | 4 ++-- TPTBox/stitching/README.md | 6 +++++- docs/modules/stitching.md | 5 ++++- unit_tests/test_compat.py | 8 ++++---- 12 files changed, 45 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 26ff5fb9..26f43e6a 100755 --- a/README.md +++ b/README.md @@ -73,8 +73,8 @@ nii.get_array() # get numpy array nii.affine # Affine matrix nii.header # NIFTY header nii.orientation # Orientation in 3-Letters -nii.zoom # Scale of the three image axis -nii.shape #shape +nii.zoom # Scale of the three image axis +nii.shape # shape ``` diff --git a/TPTBox/core/README.md b/TPTBox/core/README.md index d4f6c5e4..e062326e 100644 --- a/TPTBox/core/README.md +++ b/TPTBox/core/README.md @@ -38,7 +38,7 @@ Numpy functionalities that a lot of NII functions above utilize under the hood. ```python from TPTBox.core.np_utils import np_unique, np_center_of_mass -a = np.array([0,1,2,3], [4,5,6,7], dtype=np.uint8) +a = np.array([0, 1, 2, 3], [4, 5, 6, 7], dtype=np.uint8) label = np_unique(a) center_of_mass_of_label_four = np_center_of_mass(a)[4] @@ -59,6 +59,7 @@ center_of_mass_of_label_four = np_center_of_mass(a)[4] ```python from TPTBox import NII, Location + # Segmentation seg = NII.load("path/to/seg.nii.gz", seg=True) diff --git a/TPTBox/core/README_BIDS.md b/TPTBox/core/README_BIDS.md index e617f80e..3becab40 100644 --- a/TPTBox/core/README_BIDS.md +++ b/TPTBox/core/README_BIDS.md @@ -49,11 +49,7 @@ from TPTBox import BIDS_FILE root = Path("path/to/dataset-dsname") # Example BIDS-compliant input file -example_file = ( - root - / "rawdata/sub-Max-Mustermann/ses-01012026/anat/" - "sub-Max-Mustermann_ses-01012026_acq-sag_ce-GBCA_T1w.nii.gz" -) +example_file = root / "rawdata/sub-Max-Mustermann/ses-01012026/anat/sub-Max-Mustermann_ses-01012026_acq-sag_ce-GBCA_T1w.nii.gz" # Create a BIDS_FILE object bf_file = BIDS_FILE(example_file, root) @@ -85,5 +81,4 @@ seg_path = bf_file.get_changed_path( # If True, disables strict validation against predefined key--value pairs non_strict_mode=False, ) - ``` diff --git a/TPTBox/core/README_NII.md b/TPTBox/core/README_NII.md index d581b69b..cedc7706 100644 --- a/TPTBox/core/README_NII.md +++ b/TPTBox/core/README_NII.md @@ -20,6 +20,7 @@ The `core` subpackage is the foundation of TPTBox. It provides the three primary ```python from TPTBox import NII + # Image nii = NII.load("path/to/img.nii.gz", seg=False) # Segmentation diff --git a/TPTBox/core/README_POI.md b/TPTBox/core/README_POI.md index 5f911a87..3e2e86a4 100644 --- a/TPTBox/core/README_POI.md +++ b/TPTBox/core/README_POI.md @@ -32,15 +32,12 @@ Compute a full set of anatomical landmarks. The registry of supported non-centro from TPTBox.core.poi_fun.vertebra_pois_non_centroids import all_poi_functions poi_full = calc_poi_from_subreg_vert( - instance_nii, semantic_nii, + instance_nii, + semantic_nii, subreg_id=list(all_poi_functions.keys()), ) # export as a 3D Slicer markup file -poi_full.to_global().save_mrk( - "poi_as_markup.mrk.json", - split_by_region=True, - pointLabelsVisibility=True -) +poi_full.to_global().save_mrk("poi_as_markup.mrk.json", split_by_region=True, pointLabelsVisibility=True) ``` @@ -136,7 +133,4 @@ poi.save(poi_path) # Loading local/global Poi poi = POI.load(poi_path) poi = POI_Global.load(poi_path) - - - ``` diff --git a/TPTBox/logger/README.md b/TPTBox/logger/README.md index 3f677e2f..4d3f0cc0 100644 --- a/TPTBox/logger/README.md +++ b/TPTBox/logger/README.md @@ -38,7 +38,7 @@ from TPTBox import Logger, Print_Logger, No_Logger, String_Logger, Log_Type ## Example ```python -logger.print() # logs/prints empty line +logger.print() # logs/prints empty line logger.print("Started logging to path: ./logs/test.log", lt.LOG) logger.print() @@ -69,6 +69,7 @@ log.print("Missing T2w for sub-007", Log_Type.WARNING) # Suppress all output (e.g. in a library function) from TPTBox import No_Logger + log = No_Logger() log.print("This is silently discarded") ``` diff --git a/TPTBox/registration/README.md b/TPTBox/registration/README.md index 8d9f23a7..90c538ba 100644 --- a/TPTBox/registration/README.md +++ b/TPTBox/registration/README.md @@ -12,8 +12,8 @@ from TPTBox.registration import ( ridged_points_from_subreg_vert, Deformable_Registration, Template_Registration, - General_Registration, # requires hf-deepali - Rigid_Elements_Registration, # requires hf-deepali + General_Registration, # requires hf-deepali + Rigid_Elements_Registration, # requires hf-deepali ) ``` @@ -49,5 +49,4 @@ reg_obj = Point_Registration(poi_fixed, poi_moving) nii_moving = NII.load("path/to/moving_img.nii.gz", False) nii_moved = reg_obj.transform_nii(nii_moving) poi_moved = reg_obj.transform_poi(poi_moving) - ``` diff --git a/TPTBox/spine/snapshot2D/README.md b/TPTBox/spine/snapshot2D/README.md index c2cdd642..9f06df6b 100644 --- a/TPTBox/spine/snapshot2D/README.md +++ b/TPTBox/spine/snapshot2D/README.md @@ -43,38 +43,44 @@ poi = calc_poi_from_subreg_vert(vert, subreg) create_snapshot( out_path, [ - Snapshot_Frame(img, vert, poi, sagittal=True, coronal=True, - mode="CT"), - Snapshot_Frame(img, subreg, poi, sagittal=True, coronal=True, - axial=True, mode="CTs", axial_heights=[0.20, 0.4, 0.6, 0.8]), + Snapshot_Frame(img, vert, poi, sagittal=True, coronal=True, mode="CT"), + Snapshot_Frame(img, subreg, poi, sagittal=True, coronal=True, axial=True, mode="CTs", axial_heights=[0.20, 0.4, 0.6, 0.8]), ], ) create_snapshot( out_path2, [ Snapshot_Frame( - img, subreg, poi, - sagittal=True, coronal=True, + img, + subreg, + poi, + sagittal=True, + coronal=True, mode="MINMAX", only_mask_area=True, hide_segmentation=True, ), Snapshot_Frame( - img, subreg, poi, - sagittal=True, coronal=True, + img, + subreg, + poi, + sagittal=True, + coronal=True, mode="MINMAX", only_mask_area=True, visualization_type=Visualization_Type.Maximum_Intensity, hide_segmentation=True, ), Snapshot_Frame( - img, subreg, poi, - sagittal=True, coronal=True, + img, + subreg, + poi, + sagittal=True, + coronal=True, mode="MINMAX", visualization_type=Visualization_Type.Maximum_Intensity, hide_segmentation=True, ), ], ) - ``` diff --git a/TPTBox/spine/spinestats/README.md b/TPTBox/spine/spinestats/README.md index de4b078e..7e04fed7 100644 --- a/TPTBox/spine/spinestats/README.md +++ b/TPTBox/spine/spinestats/README.md @@ -350,9 +350,9 @@ collector = ExcelCollector(out_folder="/tmp/nako_summary") collector.start() for nako_id in ids: f = get_nako_paths(nako_id) - run_all(f) # writes the per-subject json + run_all(f) # writes the per-subject json collector.submit(nako_id, _final_json_path(f)) -collector.close() # flushes and joins +collector.close() # flushes and joins ``` The collector re-writes the Excel files every `flush_every` submissions diff --git a/TPTBox/stitching/README.md b/TPTBox/stitching/README.md index 43096d51..18ebd8db 100644 --- a/TPTBox/stitching/README.md +++ b/TPTBox/stitching/README.md @@ -58,7 +58,11 @@ pip install TPTBox ```python from TPTBox.stitching import stitching -list_of_files = ["File_A.nii.gz", "File_B.nii.gz", "File_C.nii.gz",] +list_of_files = [ + "File_A.nii.gz", + "File_B.nii.gz", + "File_C.nii.gz", +] # Call the stitching function # This will combine your images into a single NIfTI file diff --git a/docs/modules/stitching.md b/docs/modules/stitching.md index 44836436..3c9149f4 100644 --- a/docs/modules/stitching.md +++ b/docs/modules/stitching.md @@ -58,8 +58,10 @@ pip install TPTBox ```python from TPTBox import NII from TPTBox.stitching import stitching -out_nii,_ = stitching([NII.load("a.nii.gz",seg=False), NII.load("b.nii.gz",seg=False), NII.load("c.nii.gz",seg=False)], out="out.nii.gz") +out_nii, _ = stitching( + [NII.load("a.nii.gz", seg=False), NII.load("b.nii.gz", seg=False), NII.load("c.nii.gz", seg=False)], out="out.nii.gz" +) ``` or @@ -67,6 +69,7 @@ or ```python from TPTBox.stitching import stitching_raw + stitching_raw(["a.nii.gz", "b.nii.gz", "c.nii.gz"], "out.nii.gz", is_segmentation=False) ``` diff --git a/unit_tests/test_compat.py b/unit_tests/test_compat.py index 75204637..d8eabe5c 100644 --- a/unit_tests/test_compat.py +++ b/unit_tests/test_compat.py @@ -12,14 +12,14 @@ class TestZipStrict(unittest.TestCase): def test_equal_length_lists(self): a = [1, 2, 3] - b = ['a', 'b', 'c'] - expected = [(1, 'a'), (2, 'b'), (3, 'c')] + b = ["a", "b", "c"] + expected = [(1, "a"), (2, "b"), (3, "c")] result = list(zip_strict(a, b)) self.assertEqual(result, expected) def test_unequal_length_lists(self): a = [1, 2, 3] - b = ['a', 'b'] + b = ["a", "b"] with self.assertRaises(ValueError) as context: list(zip_strict(a, b)) self.assertIn("Length mismatch", str(context.exception)) @@ -41,6 +41,6 @@ def test_multiple_iterables(self): def test_generator_iterables(self): a = (x for x in range(3)) b = (chr(97 + x) for x in range(3)) - expected = [(0, 'a'), (1, 'b'), (2, 'c')] + expected = [(0, "a"), (1, "b"), (2, "c")] result = list(zip_strict(a, b)) self.assertEqual(result, expected)