From b7d2036695cdbef8169836eae56a11ff4518a94c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:51:54 +0000 Subject: [PATCH] style: [pre-commit.ci] auto fixes [...] --- src/npe2/_dynamic_plugin.py | 6 ++-- src/npe2/_setuptools_plugin.py | 1 + src/npe2/io_utils.py | 20 ++++++------- .../manifest/contributions/_configuration.py | 2 +- .../manifest/contributions/_json_schema.py | 2 +- .../manifest/contributions/_sample_data.py | 3 +- src/npe2/types.py | 12 +++----- .../my-compiled-plugin/my_module/_a.py | 14 ++++----- .../my-compiled-plugin/my_module/_b.py | 9 ++---- tests/npe1-plugin/npe1_module/__init__.py | 24 +++++---------- tests/sample/_with_decorators.py | 29 +++++++------------ tests/sample/my_plugin/__init__.py | 9 ++---- tests/test_contributions.py | 6 ++-- tests/test_conversion.py | 3 +- tests/test_fetch.py | 6 ++-- tests/test_npe1_adapter.py | 3 +- tests/test_tmp_plugin.py | 9 ++---- 17 files changed, 60 insertions(+), 98 deletions(-) diff --git a/src/npe2/_dynamic_plugin.py b/src/npe2/_dynamic_plugin.py index 7b98f4fc..9a7d2613 100644 --- a/src/npe2/_dynamic_plugin.py +++ b/src/npe2/_dynamic_plugin.py @@ -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 diff --git a/src/npe2/_setuptools_plugin.py b/src/npe2/_setuptools_plugin.py index 99ff9174..6ece6eec 100644 --- a/src/npe2/_setuptools_plugin.py +++ b/src/npe2/_setuptools_plugin.py @@ -6,6 +6,7 @@ [tool.npe2] """ + from __future__ import annotations import os diff --git a/src/npe2/io_utils.py b/src/npe2/io_utils.py index 2ba68594..f2aed80f 100644 --- a/src/npe2/io_utils.py +++ b/src/npe2/io_utils.py @@ -126,8 +126,7 @@ def _read( plugin_name: Optional[str] = None, return_reader: Literal[False] = False, _pm=None, -) -> List[LayerData]: - ... +) -> List[LayerData]: ... @overload @@ -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( @@ -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 @@ -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( @@ -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] diff --git a/src/npe2/manifest/contributions/_configuration.py b/src/npe2/manifest/contributions/_configuration.py index 0a9f03c3..4411f8b3 100644 --- a/src/npe2/manifest/contributions/_configuration.py +++ b/src/npe2/manifest/contributions/_configuration.py @@ -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.", diff --git a/src/npe2/manifest/contributions/_json_schema.py b/src/npe2/manifest/contributions/_json_schema.py index 0bb44831..2d8f7071 100644 --- a/src/npe2/manifest/contributions/_json_schema.py +++ b/src/npe2/manifest/contributions/_json_schema.py @@ -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) diff --git a/src/npe2/manifest/contributions/_sample_data.py b/src/npe2/manifest/contributions/_sample_data.py index 05917a24..e5be462d 100644 --- a/src/npe2/manifest/contributions/_sample_data.py +++ b/src/npe2/manifest/contributions/_sample_data.py @@ -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]]): diff --git a/src/npe2/types.py b/src/npe2/types.py index 3f649005..b08ec0da 100644 --- a/src/npe2/types.py +++ b/src/npe2/types.py @@ -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[ diff --git a/tests/fixtures/my-compiled-plugin/my_module/_a.py b/tests/fixtures/my-compiled-plugin/my_module/_a.py index dc562e5c..075252e0 100644 --- a/tests/fixtures/my-compiled-plugin/my_module/_a.py +++ b/tests/fixtures/my-compiled-plugin/my_module/_a.py @@ -11,13 +11,11 @@ @implements.on_activate -def activate(ctx): - ... +def activate(ctx): ... @implements.on_deactivate -def deactivate(ctx): - ... +def deactivate(ctx): ... @implements.reader( @@ -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( @@ -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]: ... diff --git a/tests/fixtures/my-compiled-plugin/my_module/_b.py b/tests/fixtures/my-compiled-plugin/my_module/_b.py index 0f4ca72f..2f41c488 100644 --- a/tests/fixtures/my-compiled-plugin/my_module/_b.py +++ b/tests/fixtures/my-compiled-plugin/my_module/_b.py @@ -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( @@ -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( @@ -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): ... diff --git a/tests/npe1-plugin/npe1_module/__init__.py b/tests/npe1-plugin/npe1_module/__init__.py index 2dfe0fe4..a540119e 100644 --- a/tests/npe1-plugin/npe1_module/__init__.py +++ b/tests/npe1-plugin/npe1_module/__init__.py @@ -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 @@ -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, @@ -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] diff --git a/tests/sample/_with_decorators.py b/tests/sample/_with_decorators.py index f053d073..21a60392 100644 --- a/tests/sample/_with_decorators.py +++ b/tests/sample/_with_decorators.py @@ -19,13 +19,11 @@ @implements.on_activate -def activate(ctx): - ... +def activate(ctx): ... @implements.on_deactivate -def deactivate(ctx): - ... +def deactivate(ctx): ... @implements.reader( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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): ... diff --git a/tests/sample/my_plugin/__init__.py b/tests/sample/my_plugin/__init__.py index fccf180d..6165a7aa 100644 --- a/tests/sample/my_plugin/__init__.py +++ b/tests/sample/my_plugin/__init__.py @@ -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!")) @@ -72,8 +71,7 @@ class Arg(BaseModel): return [path] -class SomeWidget: - ... +class SomeWidget: ... def random_data(): @@ -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): ... diff --git a/tests/test_contributions.py b/tests/test_contributions.py index af5a778c..7693ca28 100644 --- a/tests/test_contributions.py +++ b/tests/test_contributions.py @@ -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" diff --git a/tests/test_conversion.py b/tests/test_conversion.py index 99186487..d99fe8c5 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -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] diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 60ea4ba1..5532cad2 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -73,7 +73,7 @@ def test_manifest_from_sdist(): def test_get_manifest_from_wheel(tmp_path): - url = "https://files.pythonhosted.org/packages/f0/cc/7f6fbce81be3eb73266f398e49df92859ba247134eb086704dd70b43819a/affinder-0.2.3-py3-none-any.whl" # noqa + url = "https://files.pythonhosted.org/packages/f0/cc/7f6fbce81be3eb73266f398e49df92859ba247134eb086704dd70b43819a/affinder-0.2.3-py3-none-any.whl" dest = tmp_path / "affinder-0.2.3-py3-none-any.whl" urllib.request.urlretrieve(url, dest) mf = get_manifest_from_wheel(dest) @@ -94,8 +94,8 @@ def test_get_pypi_plugins(): @pytest.mark.parametrize( "url", [ - "https://files.pythonhosted.org/packages/fb/01/e59bc1d6ac96f84ce9d7a46cc5422250e047958ead6c5693ed386cf94003/napari_dv-0.3.0.tar.gz", # noqa - "https://files.pythonhosted.org/packages/5d/ae/17779e12ce60d8329306963e1a8dec608465caee582440011ff0c1310715/example_plugin-0.0.7-py3-none-any.whl", # noqa + "https://files.pythonhosted.org/packages/fb/01/e59bc1d6ac96f84ce9d7a46cc5422250e047958ead6c5693ed386cf94003/napari_dv-0.3.0.tar.gz", + "https://files.pythonhosted.org/packages/5d/ae/17779e12ce60d8329306963e1a8dec608465caee582440011ff0c1310715/example_plugin-0.0.7-py3-none-any.whl", "git+https://github.com/napari/dummy-test-plugin.git@npe1", # this one doesn't use setuptools_scm, can check direct zip without clone "https://github.com/jo-mueller/napari-stl-exporter/archive/refs/heads/main.zip", diff --git a/tests/test_npe1_adapter.py b/tests/test_npe1_adapter.py index c941c572..2bcd69bb 100644 --- a/tests/test_npe1_adapter.py +++ b/tests/test_npe1_adapter.py @@ -157,8 +157,7 @@ def read_text(self, filename): if filename == "METADATA": return "Name: fake-plugin\nVersion: 0.1.0\n" - def locate_file(self, *_): - ... + def locate_file(self, *_): ... adapter = _npe1_adapter.NPE1Adapter(FakeDist()) diff --git a/tests/test_tmp_plugin.py b/tests/test_tmp_plugin.py index 43670bc4..a40bfc65 100644 --- a/tests/test_tmp_plugin.py +++ b/tests/test_tmp_plugin.py @@ -33,8 +33,7 @@ def make_image(x): return x @tmp_plugin.contribute.reader - def read_path(path): - ... + def read_path(path): ... # can override args ID = f"{TMP}.random_id" @@ -48,16 +47,14 @@ def some_command(): with pytest.raises(AssertionError) as e: @tmp_plugin.contribute.writer - def write_path_bad(path, layer_data): - ... + def write_path_bad(path, layer_data): ... assert "layer_types must not be empty" in str(e.value) # it didn't get added assert "tmp.write_path_bad" not in pm.commands @tmp_plugin.contribute.writer(layer_types=["image"]) - def write_path(path, layer_data): - ... + def write_path(path, layer_data): ... # now it did assert "tmp.write_path" in pm.commands