Skip to content

Commit

Permalink
add graph layer (#292)
Browse files Browse the repository at this point in the history
Hi.

This PR adds "graph" to the list of existing layers.
It's required by PR napari/napari#5861 which adds a new napari graph
layer.

---------

Co-authored-by: Jonas Windhager <jonas.windhager@uzh.ch>
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Nathan Clack <nclack@chanzuckerberg.com>
Co-authored-by: Nathan Clack <nclack@gmail.com>
Co-authored-by: Jonas Windhager <jonas@windhager.io>
  • Loading branch information
7 people authored Jul 6, 2023
1 parent 7816fd3 commit 520ddfb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _docs/templates/_npe2_writers_guide.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ by the corresponding writer contribution in the manifest).
```python
DataType = Any # usually something like a numpy array, but varies by layer
LayerAttributes = dict
LayerName = Literal["image", "labels", "points", "shapes", "surface", "tracks", "vectors"]
LayerName = Literal["graph", "image", "labels", "points", "shapes", "surface", "tracks", "vectors"]
FullLayerData = Tuple[DataType, LayerAttributes, LayerName]
MultiWriterFunction = Callable[[str, List[FullLayerData]], List[str]]
```
Expand Down
3 changes: 3 additions & 0 deletions src/npe2/_inspection/_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ def napari_get_writer(self, node: ast.FunctionDef):
# we can't convert this to an npe2 command contribution
pass # pragma: no cover

def napari_write_graph(self, node: ast.FunctionDef):
self._parse_writer(node, "graph") # pragma: no cover

def napari_write_image(self, node: ast.FunctionDef):
self._parse_writer(node, "image")

Expand Down
1 change: 1 addition & 0 deletions src/npe2/manifest/contributions/_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class LayerType(str, Enum):
graph = "graph"
image = "image"
labels = "labels"
points = "points"
Expand Down
2 changes: 1 addition & 1 deletion src/npe2/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __array__(self) -> "np.ndarray":


LayerName = Literal[
"image", "labels", "points", "shapes", "surface", "tracks", "vectors"
"graph", "image", "labels", "points", "shapes", "surface", "tracks", "vectors"
]
Metadata = Dict
DataType = Union[ArrayLike, Sequence[ArrayLike]]
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class HookSpecs:
def napari_provide_sample_data(): ... # type: ignore
def napari_get_reader(path): ...
def napari_get_writer(path, layer_types): ...
def napari_write_graph(path, data, meta): ...
def napari_write_image(path, data, meta): ...
def napari_write_labels(path, data, meta): ...
def napari_write_points(path, data, meta): ...
Expand Down

0 comments on commit 520ddfb

Please sign in to comment.