Skip to content

Commit

Permalink
Deprecate Napari (#738)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Giovanni Palla <25887487+giovp@users.noreply.github.com>
Co-authored-by: giovp <giov.pll@gmail.com>
  • Loading branch information
4 people authored Oct 9, 2023
1 parent 9eca4a7 commit 1535dcb
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
17 changes: 17 additions & 0 deletions docs/release/notes-1.3.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Squidpy 1.3.1 (2023-10-09)
==========================

Miscellaneous
-------------

- Deprecated napari.
`@LLehner <https://github.com/LLehner>`__
`#738 <https://github.com/scverse/squidpy/pull/738>`__

- Various fixes.
`@giovp <https://github.com/giovp>`__
`#756 <https://github.com/scverse/squidpy/pull/756>`__

- Add cruft.json to comply with scverse cookiecutter template.
`@LLehner <https://github.com/LLehner>`__
`#756 <https://github.com/scverse/squidpy/pull/747>`__
70 changes: 70 additions & 0 deletions src/squidpy/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Spatial tools general utility functions."""
from __future__ import annotations

import functools
import inspect
import warnings
from contextlib import contextmanager
from enum import Enum
from multiprocessing import Manager, cpu_count
Expand Down Expand Up @@ -262,3 +265,70 @@ def verbosity(level: int) -> Generator[None, None, None]:
yield
finally:
sc.settings.verbosity = verbosity


string_types = (bytes, str)


def deprecated(reason: str) -> Any:
"""
This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.
"""

if isinstance(reason, string_types):
# The @deprecated is used with a 'reason'.
#
# .. code-block:: python
#
# @deprecated("please, use another function")
# def old_function(x, y):
# pass

def decorator(func1: Callable[..., Any]) -> Callable[..., Any]:
if inspect.isclass(func1):
fmt1 = "Call to deprecated class {name} ({reason})."
else:
fmt1 = "Call to deprecated function {name} ({reason})."

@functools.wraps(func1)
def new_func1(*args: Any, **kwargs: Any) -> Any:
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
fmt1.format(name=func1.__name__, reason=reason), category=DeprecationWarning, stacklevel=2
)
warnings.simplefilter("default", DeprecationWarning)
return func1(*args, **kwargs)

return new_func1

return decorator

elif inspect.isclass(reason) or inspect.isfunction(reason):
# The @deprecated is used without any 'reason'.
#
# .. code-block:: python
#
# @deprecated
# def old_function(x, y):
# pass

func2 = reason

if inspect.isclass(func2):
fmt2 = "Call to deprecated class {name}."
else:
fmt2 = "Call to deprecated function {name}."

@functools.wraps(func2)
def new_func2(*args: Any, **kwargs: Any) -> Any:
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(fmt2.format(name=func2.__name__), category=DeprecationWarning, stacklevel=2)
warnings.simplefilter("default", DeprecationWarning)
return func2(*args, **kwargs)

return new_func2

else:
raise TypeError(repr(type(reason)))
2 changes: 1 addition & 1 deletion src/squidpy/im/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ def interactive(
"""
from squidpy.pl import Interactive # type: ignore[attr-defined]

return Interactive( # type: ignore[return-value]
return Interactive( # type: ignore[no-any-return]
img=self,
adata=adata,
spatial_key=spatial_key,
Expand Down
2 changes: 2 additions & 0 deletions src/squidpy/pl/_interactive/_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
import pandas as pd
from deprecated import deprecated
from napari.layers import Points
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import Qt
Expand Down Expand Up @@ -341,6 +342,7 @@ def update_color(self) -> None:
self._colorbar._colorbar._colorbar._update()


@deprecated
class RangeSlider(QRangeSlider):
def __init__(self, *args: Any, layer: Points, colorbar: CBarWidget, **kwargs: Any):
super().__init__(*args, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion src/squidpy/pl/_interactive/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from scanpy import logging as logg

from squidpy._docs import d
from squidpy._utils import NDArrayA
from squidpy._utils import NDArrayA, deprecated
from squidpy.im import ImageContainer # type: ignore[attr-defined]
from squidpy.pl._utils import save_fig

Expand All @@ -36,6 +36,9 @@ class Interactive:
%(_interactive.parameters)s
"""

@deprecated(
reason="The squidpy napari plugin is deprecated, please use https://github.com/scverse/napari-spatialdata",
)
def __init__(self, img: ImageContainer, adata: AnnData, **kwargs: Any):
if _error is not None:
raise ImportError(f"Unable to import the interactive viewer. Reason `{_error}`.")
Expand Down

0 comments on commit 1535dcb

Please sign in to comment.