Skip to content

Commit

Permalink
style: [pre-commit.ci] auto fixes [...]
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jun 3, 2024
1 parent eb38ba9 commit 4749c3e
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 98 deletions.
6 changes: 2 additions & 4 deletions src/npe2/_dynamic_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,12 @@ def __init__(self, plugin: DynamicPlugin, contrib_type: Type[C]) -> None:
self._contrib_name = CONTRIB_NAMES[self.contrib_type]

@overload
def __call__(self, func: T, **kwargs) -> T:
...
def __call__(self, func: T, **kwargs) -> T: ...

@overload
def __call__(
self, func: Optional[Literal[None]] = None, **kwargs
) -> Callable[[T], T]:
...
) -> Callable[[T], T]: ...

def __call__(
self, func: Optional[T] = None, **kwargs
Expand Down
1 change: 1 addition & 0 deletions src/npe2/_setuptools_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[tool.npe2]
"""

from __future__ import annotations

import os
Expand Down
20 changes: 9 additions & 11 deletions src/npe2/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def _read(
plugin_name: Optional[str] = None,
return_reader: Literal[False] = False,
_pm=None,
) -> List[LayerData]:
...
) -> List[LayerData]: ...


@overload
Expand All @@ -138,8 +137,7 @@ def _read(
plugin_name: Optional[str] = None,
return_reader: Literal[True],
_pm=None,
) -> Tuple[List[LayerData], ReaderContribution]:
...
) -> Tuple[List[LayerData], ReaderContribution]: ...


def _read(
Expand Down Expand Up @@ -270,8 +268,7 @@ def _write(
plugin_name: Optional[str] = None,
return_writer: Literal[False] = False,
_pm: Optional[PluginManager] = None,
) -> List[str]:
...
) -> List[str]: ...


@overload
Expand All @@ -282,8 +279,7 @@ def _write(
plugin_name: Optional[str] = None,
return_writer: Literal[True],
_pm: Optional[PluginManager] = None,
) -> Tuple[List[str], WriterContribution]:
...
) -> Tuple[List[str], WriterContribution]: ...


def _write(
Expand All @@ -300,9 +296,11 @@ def _write(
_pm = PluginManager.instance()

_layer_tuples: List[FullLayerData] = [
cast("napari.layers.Layer", x).as_layer_data_tuple()
if hasattr(x, "as_layer_data_tuple")
else x
(
cast("napari.layers.Layer", x).as_layer_data_tuple()
if hasattr(x, "as_layer_data_tuple")
else x
)
for x in layer_data
]
layer_types = [x[2] for x in _layer_tuples]
Expand Down
2 changes: 1 addition & 1 deletion src/npe2/manifest/contributions/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ConfigurationProperty(Draft07JsonSchema):
"plain text, set this value to `plain`.",
)

enum: Optional[conlist(Any, min_items=1, unique_items=True)] = Field( # type: ignore # noqa: E501
enum: Optional[conlist(Any, min_items=1, unique_items=True)] = Field( # type: ignore
None,
description="A list of valid options for this field. If you provide this field,"
"the settings UI will render a dropdown menu.",
Expand Down
2 changes: 1 addition & 1 deletion src/npe2/manifest/contributions/_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Config:
unique_items: bool = Field(False)
max_properties: Optional[int] = Field(None, ge=0)
min_properties: Optional[int] = Field(0, ge=0)
enum: Optional[conlist(Any, min_items=1, unique_items=True)] = Field(None) # type: ignore # noqa
enum: Optional[conlist(Any, min_items=1, unique_items=True)] = Field(None) # type: ignore
type: Union[JsonType, JsonTypeArray] = Field(None) # type: ignore
format: Optional[str] = Field(None)

Expand Down
3 changes: 1 addition & 2 deletions src/npe2/manifest/contributions/_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class _SampleDataContribution(GenericModel, ABC):
@abstractmethod
def open(
self, *args, _registry: Optional["CommandRegistry"] = None, **kwargs
) -> List[LayerData]:
...
) -> List[LayerData]: ...


class SampleDataGenerator(_SampleDataContribution, Executable[List[LayerData]]):
Expand Down
12 changes: 4 additions & 8 deletions src/npe2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@

class ArrayLike(Protocol):
@property
def shape(self) -> Tuple[int, ...]:
...
def shape(self) -> Tuple[int, ...]: ...

@property
def ndim(self) -> int:
...
def ndim(self) -> int: ...

@property
def dtype(self) -> "np.dtype":
...
def dtype(self) -> "np.dtype": ...

def __array__(self) -> "np.ndarray":
... # pragma: no cover
def __array__(self) -> "np.ndarray": ... # pragma: no cover


LayerName = Literal[
Expand Down
14 changes: 6 additions & 8 deletions tests/fixtures/my-compiled-plugin/my_module/_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@


@implements.on_activate
def activate(ctx):
...
def activate(ctx): ...


@implements.on_deactivate
def deactivate(ctx):
...
def deactivate(ctx): ...


@implements.reader(
Expand All @@ -26,8 +24,7 @@ def deactivate(ctx):
filename_patterns=["*.fzy", "*.fzzy"],
accepts_directories=True,
)
def get_reader(path: str):
...
def get_reader(path: str): ...


@implements.writer(
Expand All @@ -42,5 +39,6 @@ def get_reader(path: str):
filename_extensions=["*.pcd", "*.e57"],
layer_types=["points{1}", "surface+"],
)
def writer_function(path: str, layer_data: List[Tuple[Any, Dict, str]]) -> List[str]:
...
def writer_function(
path: str, layer_data: List[Tuple[Any, Dict, str]]
) -> List[str]: ...
9 changes: 3 additions & 6 deletions tests/fixtures/my-compiled-plugin/my_module/_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


@implements.widget(id="some_widget", title="Create my widget", display_name="My Widget")
class SomeWidget:
...
class SomeWidget: ...


@implements.sample_data_generator(
Expand All @@ -18,8 +17,7 @@ class SomeWidget:
key="random_data",
display_name="Some Random Data (512 x 512)",
)
def random_data():
...
def random_data(): ...


@implements.widget(
Expand All @@ -28,5 +26,4 @@ def random_data():
display_name="A Widget From a Function",
autogenerate=True,
)
def make_widget_from_function(x: int, threshold: int):
...
def make_widget_from_function(x: int, threshold: int): ...
24 changes: 8 additions & 16 deletions tests/npe1-plugin/npe1_module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,25 @@
from napari_plugin_engine import napari_hook_implementation


class MyWidget:
...
class MyWidget: ...


def some_function(x: int):
...
def some_function(x: int): ...


def gen_data():
...
def gen_data(): ...


@napari_hook_implementation
def napari_get_reader(path):
...
def napari_get_reader(path): ...


@napari_hook_implementation
def napari_write_image(path, data, meta):
...
def napari_write_image(path, data, meta): ...


@napari_hook_implementation
def napari_write_labels(path, data, meta):
...
def napari_write_labels(path, data, meta): ...


@napari_hook_implementation
Expand Down Expand Up @@ -79,8 +73,7 @@ def napari_experimental_provide_theme():
@napari_hook_implementation
def napari_experimental_provide_dock_widget():
@magic_factory
def local_widget(y: str):
...
def local_widget(y: str): ...

return [
MyWidget,
Expand All @@ -91,7 +84,6 @@ def local_widget(y: str):

@napari_hook_implementation
def napari_experimental_provide_function():
def local_function(x: int):
...
def local_function(x: int): ...

return [some_function, local_function]
29 changes: 11 additions & 18 deletions tests/sample/_with_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@


@implements.on_activate
def activate(ctx):
...
def activate(ctx): ...


@implements.on_deactivate
def deactivate(ctx):
...
def deactivate(ctx): ...


@implements.reader(
Expand All @@ -34,8 +32,7 @@ def deactivate(ctx):
filename_patterns=["*.fzy", "*.fzzy"],
accepts_directories=True,
)
def get_reader(path: str):
...
def get_reader(path: str): ...


@reader(
Expand All @@ -45,8 +42,7 @@ def get_reader(path: str):
accepts_directories=False,
ensure_args_valid=True,
)
def url_reader(path: str):
...
def url_reader(path: str): ...


@noimport.writer(
Expand All @@ -61,8 +57,9 @@ def url_reader(path: str):
filename_extensions=["*.pcd", "*.e57"],
layer_types=["points{1}", "surface+"],
)
def writer_function(path: str, layer_data: List[Tuple[Any, Dict, str]]) -> List[str]:
...
def writer_function(
path: str, layer_data: List[Tuple[Any, Dict, str]]
) -> List[str]: ...


@implements.writer(
Expand All @@ -71,15 +68,13 @@ def writer_function(path: str, layer_data: List[Tuple[Any, Dict, str]]) -> List[
filename_extensions=["*.xyz"],
layer_types=["labels"],
)
def writer_function_single(path: str, layer_data: Any, meta: Dict) -> List[str]:
...
def writer_function_single(path: str, layer_data: Any, meta: Dict) -> List[str]: ...


@npe2.implements.widget(
id="some_widget", title="Create my widget", display_name="My Widget"
)
class SomeWidget:
...
class SomeWidget: ...


@npe2.implements.sample_data_generator(
Expand All @@ -88,8 +83,7 @@ class SomeWidget:
key="random_data",
display_name="Some Random Data (512 x 512)",
)
def random_data():
...
def random_data(): ...


@impls.widget(
Expand All @@ -98,5 +92,4 @@ def random_data():
display_name="A Widget From a Function",
autogenerate=True,
)
def make_widget_from_function(x: int, threshold: int):
...
def make_widget_from_function(x: int, threshold: int): ...
9 changes: 3 additions & 6 deletions tests/sample/my_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

def activate(context: PluginContext):
@context.register_command("my_plugin.hello_world")
def _hello():
...
def _hello(): ...

context.register_command("my_plugin.another_command", lambda: print("yo!"))

Expand Down Expand Up @@ -72,8 +71,7 @@ class Arg(BaseModel):
return [path]


class SomeWidget:
...
class SomeWidget: ...


def random_data():
Expand All @@ -82,5 +80,4 @@ def random_data():
return [(np.random.rand(10, 10))]


def make_widget_from_function(image: "napari.types.ImageData", threshold: int):
...
def make_widget_from_function(image: "napari.types.ImageData", threshold: int): ...
6 changes: 2 additions & 4 deletions tests/test_contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ def test_writer_priority():
with DynamicPlugin(name="my_plugin", plugin_manager=pm) as plg:

@plg.contribute.writer(filename_extensions=["*.tif"], layer_types=["image"])
def my_writer1(path, data):
...
def my_writer1(path, data): ...

@plg.contribute.writer(filename_extensions=["*.abc"], layer_types=["image"])
def my_writer2(path, data):
...
def my_writer2(path, data): ...

writers = list(pm.iter_compatible_writers(["image"]))
assert writers[0].command == "my_plugin.my_writer1"
Expand Down
3 changes: 1 addition & 2 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class MyPlugin:
@staticmethod
@napari_hook_implementation
def napari_experimental_provide_function():
def f(x: int):
...
def f(x: int): ...

return [f]

Expand Down
Loading

0 comments on commit 4749c3e

Please sign in to comment.