Skip to content

paquo update_image_paths with QuPath 0.7.0 on windows #130

Description

@ap--

see: https://github.com/Bayer-Group/paquo/actions/runs/23092637226/job/67079771911?pr=129
ref: #129

java error:

>                   new_pth = proj_pth.resolve(prev_pth.relativize(img_pth)).normalize()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E                   TypeError: Ambiguous overloads found for sun.nio.fs.WindowsPath.resolve(sun.nio.fs.WindowsPath) between:
E                   	public sun.nio.fs.WindowsPath sun.nio.fs.WindowsPath.resolve(java.nio.file.Path)
E                   	public default java.nio.file.Path java.nio.file.Path.resolve(java.nio.file.Path,java.nio.file.Path[])

full traceback:

================================== FAILURES ===================================
_________________ test_project_image_uri_update_try_relative __________________

tmp_path = WindowsPath('C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/test_project_image_uri_update_0')
svs_small = WindowsPath('D:/a/paquo/paquo/paquo/tests/data/CMU-1-Small-Region.svs')

    def test_project_image_uri_update_try_relative(tmp_path, svs_small):
    
        # prepare initial location
        location_0 = tmp_path / "location_0"
        location_0.mkdir()
    
        # prepare a project and images at location_0
        image_path = location_0 / "images" / "image0.svs"
        image_path.parent.mkdir(parents=True)
        shutil.copy(svs_small, image_path)
        assert image_path.is_file()
    
        # create a project
        with QuPathProject(location_0 / "project", mode='x') as qp:
            entry = qp.add_image(image_path)
            assert entry.is_readable()
            assert all(qp.is_readable().values())
    
        # cleanup
        del entry
        del qp
    
        # NOW move the location
        location_1 = tmp_path / "location_1"
        try:
            shutil.move(location_0, location_1)
        except PermissionError:
            if platform.system() == "Windows":
                pytest.xfail("Windows QuPath==0.5.0 quirk with permissions")
            else:
                raise
    
        with QuPathProject(location_1 / "project", mode='r') as qp:
            entry, = qp.images
            assert not entry.is_readable()
            assert not all(qp.is_readable().values())
            assert 'location_1' in str(qp.path)
            assert 'location_0' in entry.uri  # still points to the old location
    
            # fixme: testing private api
            assert 'location_0' in str(qp.java_object.getPreviousURI().toString())
    
>           qp.update_image_paths(try_relative=True)

paquo\tests\test_projects.py:420: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = QuPathProject(path="C:\Users\runneradmin\AppData\Local\Temp\pytest-of-runneradmin\pytest-0\test_project_image_uri_update_0\location_1\project\project.qpproj" mode="r")
try_relative = True, rebase_kwargs = {}
old_uris = ['file:///C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/test_project_image_uri_update_0/location_0/images/image0.svs']
uri2uri = {}, prev_pth = <java object 'sun.nio.fs.WindowsPath'>
proj_pth = <java object 'sun.nio.fs.WindowsPath'>
old_uri = <java object 'java.net.URI'>

    def update_image_paths(self, *, try_relative: bool = False, **rebase_kwargs) -> None:
        """update image path uris if image files moved
    
        Parameters
        ----------
        try_relative: bool
            if try_relative is True, update_image_paths tries to use relative paths
            to resolve missing image entries. This is useful in case you move the
            the project together with its images directory, or in case you remount
            at a different location.
        **rebase_kwargs:
            keyword arguments are handed over to the image provider instance.
            The default image provider is a paquo.images.ImageProvider
            which uses the uri2uri keyword argument. (A mapping from old URI to new
            URI: Mapping[str, str])
    
        """
        if not isinstance(try_relative, bool):
            raise TypeError(f"try_relative requires bool, got: {type(try_relative).__name__!r}")
    
        # get the current image URIs
        old_uris = [image.uri for image in self.images]
    
        # the uri to uri mapping
        uri2uri = {}
    
        if try_relative:
            assert not rebase_kwargs, "no other kwargs supported when try_relative=True"
            # test if project was moved (or mounted somewhere else...)
            prev_pth = GeneralTools.toPath(self.java_object.getPreviousURI()).getParent()
            proj_pth = GeneralTools.toPath(self.java_object.getURI()).getParent()
            if prev_pth and proj_pth and not prev_pth.equals(proj_pth):
                for old_uri in map(URI, old_uris):
                    img_pth = GeneralTools.toPath(old_uri)
>                   new_pth = proj_pth.resolve(prev_pth.relativize(img_pth)).normalize()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E                   TypeError: Ambiguous overloads found for sun.nio.fs.WindowsPath.resolve(sun.nio.fs.WindowsPath) between:
E                   	public sun.nio.fs.WindowsPath sun.nio.fs.WindowsPath.resolve(java.nio.file.Path)
E                   	public default java.nio.file.Path java.nio.file.Path.resolve(java.nio.file.Path,java.nio.file.Path[])

paquo\projects.py:439: TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions