diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index c8405bc..eaf9af9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -115,19 +115,19 @@ jobs: --log-errors --latest - name: Upload MRtrix3 install - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: MRtrix3 path: ${{ env.MRTRIX_INSTALL}} - name: Upload auto-gen pydra - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: AutoGen path: pydra/tasks/mrtrix3/${{ env.SUBPKG_NAME }} - name: Write version file run: echo $MRTRIX_VERSION > mrtrix3_version.txt - name: Upload version file - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: VersionFile path: mrtrix3_version.txt @@ -352,7 +352,7 @@ jobs: git tag -d ${{ steps.latest_tag.outputs.TAG }}; git tag -a ${{ steps.latest_tag.outputs.TAG }} -m"Tag used to create a pydra-mrtrix3 $MRTRIX_VERSION release"; - name: Set up Python 3.11 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: 3.11 - name: Install build tools @@ -362,7 +362,7 @@ jobs: - name: Check distributions run: twine check dist/* - name: Upload sdist - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: SDist path: dist/*.tar.gz diff --git a/conftest.py b/conftest.py index f6c49a9..c7b2c3b 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ import os +import typing as ty import pytest from pathlib import Path @@ -22,9 +23,10 @@ def cli_parse_only(): if os.getenv("_PYTEST_RAISE", "0") != "0": @pytest.hookimpl(tryfirst=True) - def pytest_exception_interact(call): - raise call.excinfo.value + def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None: + if call.excinfo is not None: + raise call.excinfo.value @pytest.hookimpl(tryfirst=True) - def pytest_internalerror(excinfo): + def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None: raise excinfo.value diff --git a/related-packages/fileformats-extras/conftest.py b/related-packages/fileformats-extras/conftest.py index 7d7f343..fc1317f 100644 --- a/related-packages/fileformats-extras/conftest.py +++ b/related-packages/fileformats-extras/conftest.py @@ -2,6 +2,7 @@ import logging from pathlib import Path import tempfile +import typing as ty import pytest from fileformats.medimage import DicomDir, Nifti @@ -24,11 +25,12 @@ if os.getenv("_PYTEST_RAISE", "0") != "0": @pytest.hookimpl(tryfirst=True) - def pytest_exception_interact(call): - raise call.excinfo.value + def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None: + if call.excinfo is not None: + raise call.excinfo.value @pytest.hookimpl(tryfirst=True) - def pytest_internalerror(excinfo): + def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None: raise excinfo.value diff --git a/related-packages/fileformats-extras/fileformats/extras/medimage_mrtrix3/gradients.py b/related-packages/fileformats-extras/fileformats/extras/medimage_mrtrix3/gradients.py index e25d5da..854b1b7 100644 --- a/related-packages/fileformats-extras/fileformats/extras/medimage_mrtrix3/gradients.py +++ b/related-packages/fileformats-extras/fileformats/extras/medimage_mrtrix3/gradients.py @@ -1,11 +1,15 @@ -import numpy as np +import typing # noqa: F401 +import numpy.typing from fileformats.core import extra_implementation from fileformats.medimage import DwiEncoding +from fileformats.medimage.diffusion import EncodingArrayType from fileformats.medimage_mrtrix3 import BFile @extra_implementation(DwiEncoding.read_array) -def bfile_read_array(bfile: BFile) -> np.ndarray: - return np.asarray( +def bfile_read_array( + bfile: BFile, +) -> EncodingArrayType: + return numpy.asarray( [[float(x) for x in ln.split()] for ln in bfile.read_contents().splitlines()] ) diff --git a/related-packages/fileformats/conftest.py b/related-packages/fileformats/conftest.py index 2a703c0..55ca863 100644 --- a/related-packages/fileformats/conftest.py +++ b/related-packages/fileformats/conftest.py @@ -1,5 +1,6 @@ import os import logging +import typing as ty from pathlib import Path import tempfile import pytest @@ -23,11 +24,12 @@ if os.getenv("_PYTEST_RAISE", "0") != "0": @pytest.hookimpl(tryfirst=True) - def pytest_exception_interact(call): - raise call.excinfo.value + def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None: + if call.excinfo is not None: + raise call.excinfo.value @pytest.hookimpl(tryfirst=True) - def pytest_internalerror(excinfo): + def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None: raise excinfo.value diff --git a/related-packages/fileformats/fileformats/medimage_mrtrix3/dwi.py b/related-packages/fileformats/fileformats/medimage_mrtrix3/dwi.py index 287e9da..d89aff1 100644 --- a/related-packages/fileformats/fileformats/medimage_mrtrix3/dwi.py +++ b/related-packages/fileformats/fileformats/medimage_mrtrix3/dwi.py @@ -1,3 +1,4 @@ +from fileformats.core import validated_property from fileformats.core.mixin import WithAdjacentFiles from fileformats.medimage import DwiEncoding, Nifti1, NiftiGz, NiftiX, NiftiGzX from .image import ImageFormat, ImageHeader, ImageFormatGz @@ -11,7 +12,7 @@ class BFile(DwiEncoding): # NIfTI file format gzipped with BIDS side car class WithBFile(WithAdjacentFiles): - @property + @validated_property def encoding(self) -> BFile: return BFile(self.select_by_ext(BFile)) diff --git a/related-packages/fileformats/fileformats/medimage_mrtrix3/image.py b/related-packages/fileformats/fileformats/medimage_mrtrix3/image.py index c429a7a..62e196f 100644 --- a/related-packages/fileformats/fileformats/medimage_mrtrix3/image.py +++ b/related-packages/fileformats/fileformats/medimage_mrtrix3/image.py @@ -1,7 +1,7 @@ from pathlib import Path import typing as ty -from fileformats.core import FileSet, extra_implementation -from fileformats.generic import File +from fileformats.core import FileSet, extra_implementation, validated_property +from fileformats.generic import BinaryFile from fileformats.application.archive import BaseGzip from fileformats.core.mixin import WithMagicNumber from fileformats.core.exceptions import FormatMismatchError @@ -12,12 +12,12 @@ class MultiLineMetadataValue(list): pass -class BaseMrtrixImage(WithMagicNumber, fileformats.medimage.MedicalImage, File): +class BaseMrtrixImage(WithMagicNumber, fileformats.medimage.MedicalImage, BinaryFile): magic_number = b"mrtrix image\n" binary = True - @property + @validated_property def data_fspath(self): data_fspath = self.metadata["file"].split()[0] if data_fspath == ".": @@ -48,8 +48,8 @@ class ImageFormat(BaseMrtrixImage): ext = ".mif" iana_mime = "application/x-mrtrix-image-format" - @property - def check_data_file(self): + @validated_property + def _check_data_file(self): if self.data_fspath != self.fspath: raise FormatMismatchError( f"Data file ('{self.data_fspath}') is not set to the same file as header " @@ -73,7 +73,7 @@ class ImageHeader(BaseMrtrixImage): ext = ".mih" iana_mime = "application/x-mrtrix-image-header" - @property + @validated_property def data_file(self): return ImageDataFile(self.data_fspath) @@ -84,14 +84,14 @@ def __attrs_post_init__(self): super().__attrs_post_init__() -class ImageDataFile(File): +class ImageDataFile(BinaryFile): ext = ".dat" @extra_implementation(FileSet.read_metadata) def mrtrix_read_metadata( - mif: BaseMrtrixImage, selected_keys: ty.Optional[ty.Collection[str]] = None + mif: BaseMrtrixImage, **kwargs: ty.Any ) -> ty.Mapping[str, ty.Any]: metadata = {} with open(mif.fspath, "rb") as f: @@ -127,6 +127,4 @@ def mrtrix_read_metadata( else: metadata[key] = value line = f.readline().decode("utf-8") - if selected_keys: - metadata = {k: v for k, v in metadata.items() if k in selected_keys} return metadata diff --git a/related-packages/fileformats/fileformats/medimage_mrtrix3/track.py b/related-packages/fileformats/fileformats/medimage_mrtrix3/track.py index d1dee77..29c0df5 100644 --- a/related-packages/fileformats/fileformats/medimage_mrtrix3/track.py +++ b/related-packages/fileformats/fileformats/medimage_mrtrix3/track.py @@ -1,8 +1,8 @@ -from fileformats.generic import File +from fileformats.generic import BinaryFile from fileformats.core.mixin import WithMagicNumber -class Tracks(WithMagicNumber, File): +class Tracks(WithMagicNumber, BinaryFile): ext = ".tck" magic_number = b"mrtrix tracks\n"