Skip to content

Commit 6e39bf2

Browse files
committed
Code refactoring and cleanup
1 parent f8f45c1 commit 6e39bf2

File tree

8 files changed

+31
-198
lines changed

8 files changed

+31
-198
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pip install "napari-stream[all]"
4444
```
4545

4646

47-
4847
## Contributing
4948

5049
Contributions are very welcome. Tests can be run with [tox], please ensure

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ requires-python = ">=3.10"
3030
# See best practices: https://napari.org/stable/plugins/building_a_plugin/best_practices.html
3131
dependencies = [
3232
"numpy",
33-
"magicgui",
34-
"qtpy",
35-
"scikit-image",
33+
"pyzmq",
3634
]
3735

3836
[project.optional-dependencies]
@@ -52,8 +50,6 @@ dev = [
5250
[project.entry-points."napari.manifest"]
5351
napari-stream = "napari_stream:napari.yaml"
5452

55-
56-
5753
[build-system]
5854
requires = ["setuptools>=42.0.0", "setuptools_scm"]
5955
build-backend = "setuptools.build_meta"

src/napari_stream/_listener.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
from __future__ import annotations
22
import json
3-
import os
4-
import sys
5-
import socket
63
from typing import Optional
7-
84
import numpy as np
95
import zmq
10-
from qtpy.QtCore import QObject, QThread, Signal
11-
12-
13-
DEFAULT_TCP_PORT = 5556
6+
from qtpy.QtCore import QObject, Signal
7+
from ._utils import default_endpoint
148

159

1610
class ZMQImageListener(QObject):
@@ -77,15 +71,6 @@ def _teardown(self):
7771
self.status.emit("Listener stopped.")
7872

7973

80-
def default_endpoint(public: bool = False) -> str:
81-
if public:
82-
return f"tcp://{_preferred_ip()}:{DEFAULT_TCP_PORT}"
83-
if os.name == "nt": # Windows: prefer TCP
84-
return f"tcp://127.0.0.1:{DEFAULT_TCP_PORT}"
85-
# Unix: fast local IPC
86-
return "ipc:///tmp/napari_stream.sock"
87-
88-
8974
def bind_endpoint_for_public(endpoint: str) -> str:
9075
"""Convert a TCP endpoint to bind on all interfaces."""
9176
if not endpoint.startswith("tcp://"):
@@ -101,18 +86,6 @@ def bind_endpoint_for_public(endpoint: str) -> str:
10186
return f"tcp://*:{port_int}"
10287

10388

104-
def _preferred_ip() -> str:
105-
"""Best-effort guess of a non-loopback IPv4 address for sharing endpoints."""
106-
try:
107-
infos = socket.getaddrinfo(socket.gethostname(), None, family=socket.AF_INET)
108-
for _, _, _, _, (addr, *_rest) in infos:
109-
if not addr.startswith("127."):
110-
return addr
111-
except Exception:
112-
pass
113-
return "127.0.0.1"
114-
115-
11689
def _from_bytes(buf: bytes, meta: dict) -> np.ndarray:
11790
"""Reconstruct ndarray from raw bytes and metadata.
11891

src/napari_stream/_receiver_widget.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22
import traceback
33
from typing import Optional
4-
54
import numpy as np
65
from qtpy.QtCore import QThread
76
from qtpy.QtGui import QGuiApplication

src/napari_stream/_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
import os
3+
import socket
4+
5+
DEFAULT_TCP_PORT = 5556
6+
7+
8+
def default_endpoint(public: bool = False) -> str:
9+
if public:
10+
return f"tcp://{_preferred_ip()}:{DEFAULT_TCP_PORT}"
11+
if os.name == "nt": # Windows: prefer TCP
12+
return f"tcp://127.0.0.1:{DEFAULT_TCP_PORT}"
13+
# Unix: fast local IPC
14+
return "ipc:///tmp/napari_stream.sock"
15+
16+
17+
def _preferred_ip() -> str:
18+
"""Best-effort guess of a non-loopback IPv4 address for sharing endpoints."""
19+
try:
20+
infos = socket.getaddrinfo(socket.gethostname(), None, family=socket.AF_INET)
21+
for _, _, _, _, (addr, *_rest) in infos:
22+
if not addr.startswith("127."):
23+
return addr
24+
except Exception:
25+
pass
26+
return "127.0.0.1"

src/napari_stream/_widget.py

Lines changed: 0 additions & 128 deletions
This file was deleted.

src/napari_stream/napari.yaml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,6 @@ display_name: Napari Stream
44
visibility: public
55
# see https://napari.org/stable/plugins/technical_references/manifest.html#fields for valid categories
66
# categories: []
7-
# contributions:
8-
# commands:
9-
# - id: napari-stream.make_container_widget
10-
# python_name: napari_stream:ImageThreshold
11-
# title: Make threshold Container widget
12-
# - id: napari-stream.make_magic_widget
13-
# python_name: napari_stream:threshold_magic_widget
14-
# title: Make threshold magic widget
15-
# - id: napari-stream.make_function_widget
16-
# python_name: napari_stream:threshold_autogenerate_widget
17-
# title: Make threshold function widget
18-
# - id: napari-stream.make_qwidget
19-
# python_name: napari_stream:ExampleQWidget
20-
# title: Make example QWidget
21-
# widgets:
22-
# - command: napari-stream.make_container_widget
23-
# display_name: Container Threshold
24-
# - command: napari-stream.make_magic_widget
25-
# display_name: Magic Threshold
26-
# - command: napari-stream.make_function_widget
27-
# autogenerate: true
28-
# display_name: Autogenerate Threshold
29-
# - command: napari-stream.make_qwidget
30-
# display_name: Example QWidget
31-
# menus:
32-
# napari/layers/segment:
33-
# - command: napari-stream.make_container_widget
34-
# - command: napari-stream.make_magic_widget
35-
# - command: napari-stream.make_function_widget
36-
# - command: napari-stream.make_qwidget
377
contributions:
388
widgets:
399
- command: napari-stream.start_receiver

src/napari_stream/sender.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
import json
33
import os
44
import time
5-
from typing import Optional, Sequence, Any, Iterable
5+
from typing import Optional, Sequence, Any
66
from collections.abc import Mapping
7-
87
import numpy as np
98
import zmq
10-
from ._listener import default_endpoint
11-
from numpy.typing import ArrayLike
9+
from ._utils import default_endpoint
1210

1311

1412
class StreamSender:

0 commit comments

Comments
 (0)