Skip to content

Commit fc22ec0

Browse files
committed
Untangle shapeflow/__init__ & shapeflow/core/__init__
1 parent 5b4c06b commit fc22ec0

30 files changed

Lines changed: 1171 additions & 1148 deletions

shapeflow/__init__.py

Lines changed: 6 additions & 625 deletions
Large diffs are not rendered by default.

shapeflow/api.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from typing import Dict, Optional, List, Callable, Tuple, Type, Any
22
import numpy as np
3-
import shortuuid
43

5-
from shapeflow.core import Dispatcher, Endpoint, stream_image, stream_json, stream_plain
6-
from shapeflow.util.meta import bind
7-
from shapeflow.maths.colors import HsvColor
8-
from shapeflow.core.streaming import BaseStreamer, EventStreamer, PlainFileStreamer
4+
from shapeflow.core.dispatching import Endpoint, Dispatcher
5+
from shapeflow.core.streaming import BaseStreamer, EventStreamer, \
6+
PlainFileStreamer, Stream
97

108

119
# todo: also specify http methods maybe?
1210
class _VideoAnalyzerDispatcher(Dispatcher):
1311
"""Dispatches ``/api/va/<id>/<endpoint>``
1412
"""
15-
status = Endpoint(Callable[[], dict], stream_json)
13+
status = Endpoint(Callable[[], dict], Stream.json)
1614
"""Get the analyzer's status
1715
1816
:func:`shapeflow.core.backend.BaseAnalyzer.status`
@@ -52,7 +50,7 @@ class _VideoAnalyzerDispatcher(Dispatcher):
5250
5351
:func:`shapeflow.core.backend.BaseAnalyzer.cancel`
5452
"""
55-
get_config = Endpoint(Callable[[], dict], stream_json)
53+
get_config = Endpoint(Callable[[], dict], Stream.json)
5654
"""Return the analyzer's configuration
5755
5856
:func:`shapeflow.core.backend.BaseAnalyzer.get_config`
@@ -107,7 +105,7 @@ class _VideoAnalyzerDispatcher(Dispatcher):
107105
108106
:func:`shapeflow.video.VideoAnalyzer.get_overlay_png`
109107
"""
110-
get_frame = Endpoint(Callable[[Optional[int]], np.ndarray], stream_image)
108+
get_frame = Endpoint(Callable[[Optional[int]], np.ndarray], Stream.image)
111109
"""Return the transformed frame at the provided frame number
112110
(or the current frame number if ``None``)
113111
@@ -119,18 +117,18 @@ class _VideoAnalyzerDispatcher(Dispatcher):
119117
120118
:func:`shapeflow.video.VideoAnalyzer.set_filter_click`
121119
"""
122-
get_inverse_transformed_overlay = Endpoint(Callable[[], np.ndarray], stream_image)
120+
get_inverse_transformed_overlay = Endpoint(Callable[[], np.ndarray], Stream.image)
123121
"""Return the inverse transformed overlay image
124122
125123
:func:`shapeflow.video.VideoAnalyzer.get_inverse_transformed_overlay`
126124
"""
127-
get_inverse_overlaid_frame = Endpoint(Callable[[Optional[int]], np.ndarray], stream_image)
125+
get_inverse_overlaid_frame = Endpoint(Callable[[Optional[int]], np.ndarray], Stream.image)
128126
"""Return the inverse overlaid frame at the provided frame number
129127
(or the current frame number if ``None``)
130128
131129
:func:`shapeflow.video.VideoAnalyzer.get_inverse_overlaid_frame`
132130
"""
133-
get_state_frame = Endpoint(Callable[[Optional[int], Optional[int]], np.ndarray], stream_image)
131+
get_state_frame = Endpoint(Callable[[Optional[int], Optional[int]], np.ndarray], Stream.image)
134132
"""Return the state frame at the provided frame number
135133
(or the current frame number if ``None``)
136134
@@ -183,7 +181,7 @@ class _VideoAnalyzerDispatcher(Dispatcher):
183181
184182
:func:`shapeflow.video.VideoAnalyzer.get_fps`
185183
"""
186-
get_raw_frame = Endpoint(Callable[[Optional[int]], np.ndarray], stream_image)
184+
get_raw_frame = Endpoint(Callable[[Optional[int]], np.ndarray], Stream.image)
187185
"""Return the raw frame at the provided frame number
188186
(or the current frame number if ``None``)
189187
@@ -381,7 +379,7 @@ class ApiDispatcher(Dispatcher):
381379
382380
:func:`shapeflow.main._Main.set_settings`
383381
"""
384-
events = Endpoint(Callable[[], EventStreamer], stream_json)
382+
events = Endpoint(Callable[[], EventStreamer], Stream.json)
385383
"""Open an event stream
386384
387385
:func:`shapeflow.main._Main.events`
@@ -391,7 +389,7 @@ class ApiDispatcher(Dispatcher):
391389
392390
:func:`shapeflow.main._Main.stop_events`
393391
"""
394-
log = Endpoint(Callable[[], PlainFileStreamer], stream_plain)
392+
log = Endpoint(Callable[[], PlainFileStreamer], Stream.plain)
395393
"""Open a log stream
396394
397395
:func:`shapeflow.main._Main.log`

shapeflow/cli.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010
import socket
1111
import json
1212
import requests
13-
import re
1413
import abc
1514
from pathlib import Path
1615
import argparse
17-
import textwrap
18-
from typing import List, Callable, Optional, Tuple, Union
16+
from typing import List, Callable, Optional, Tuple
17+
18+
from shapeflow import __version__
19+
from shapeflow.settings import settings
20+
from shapeflow.core import get_logger, RootException
1921

20-
from shapeflow import __version__, get_logger, settings
2122
log = get_logger(__name__)
2223

2324
# type aliases
2425
OptArgs = Optional[List[str]]
2526
Parsing = Callable[[OptArgs], None]
2627

2728

28-
class CliError(Exception):
29+
class CliError(RootException):
2930
pass
3031

3132

@@ -37,7 +38,7 @@ class IterCommand(abc.ABCMeta):
3738
"""
3839
__command__: str
3940
"""Command name. This is how the command is addressed from the commandline.
40-
""" # todo: nope, doesn't work'
41+
"""
4142

4243
def __str__(cls):
4344
try:
@@ -277,7 +278,7 @@ class Dump(Command):
277278
)
278279

279280
def command(self):
280-
from shapeflow.config import schemas
281+
from shapeflow.main import schemas
281282

282283
if not self.args.dir.is_dir():
283284
log.warning(f"making directory '{self.args.dir}'")

shapeflow/config.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from typing import Optional, Tuple, Dict, Any, Type, Union
1+
from typing import Optional, Tuple, Dict, Any
22
import json
33

44
from pydantic import Field, validator
55

6-
from shapeflow import __version__, settings
6+
from shapeflow import __version__
77

88
from shapeflow.core.config import extend, ConfigType, \
99
log, VERSION, CLASS, untag, BaseConfig
1010
from shapeflow.core.backend import BaseAnalyzerConfig, \
11-
FeatureType, FeatureConfig, AnalyzerState, QueueState
11+
FeatureType, FeatureConfig
1212
from shapeflow.core import EnforcedStr
1313
from shapeflow.core.interface import FilterType, TransformType, TransformConfig, \
1414
FilterConfig, HandlerConfig
@@ -267,24 +267,6 @@ def _validate_parameters(cls, value, values):
267267
_validate_fis = validator('frame_interval_setting')(BaseConfig._resolve_enforcedstr)
268268

269269

270-
def schemas() -> Dict[str, dict]:
271-
"""Get the JSON schemas of
272-
273-
* :class:`shapeflow.video.VideoAnalyzerConfig`
274-
275-
* :class:`shapeflow.Settings`
276-
277-
* :class:`shapeflow.core.backend.AnalyzerState`
278-
279-
* :class:`shapeflow.core.backend.QueueState`
280-
"""
281-
return {
282-
'config': VideoAnalyzerConfig.schema(),
283-
'settings': settings.schema(),
284-
'analyzer_state': dict(AnalyzerState.__members__),
285-
'queue_state': dict(QueueState.__members__),
286-
}
287-
288270
def loads(config: str) -> BaseConfig:
289271
"""Load a configuration object from a JSON string.
290272

0 commit comments

Comments
 (0)