easyannotate 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data_factory/__init__.py +82 -0
  2. data_factory/__main__.py +6 -0
  3. data_factory/annotate/__init__.py +15 -0
  4. data_factory/annotate/attach.py +398 -0
  5. data_factory/annotate/demo.py +161 -0
  6. data_factory/annotate/images.py +443 -0
  7. data_factory/annotate/labels.py +399 -0
  8. data_factory/annotate/loop.py +359 -0
  9. data_factory/annotate/projects.py +207 -0
  10. data_factory/annotate/review.py +471 -0
  11. data_factory/annotate/schema.sql +171 -0
  12. data_factory/annotate/shapes.py +488 -0
  13. data_factory/annotate/store.py +292 -0
  14. data_factory/annotate/tools/__init__.py +39 -0
  15. data_factory/annotate/tools/fake.py +170 -0
  16. data_factory/annotate/tools/install.py +254 -0
  17. data_factory/annotate/tools/local.py +389 -0
  18. data_factory/annotate/tools/postprocess.py +175 -0
  19. data_factory/annotate/tools/protocol.py +238 -0
  20. data_factory/annotate/tools/registry.py +196 -0
  21. data_factory/annotate/tools/results.py +83 -0
  22. data_factory/annotate/tools/serve.py +106 -0
  23. data_factory/cli/__init__.py +21 -0
  24. data_factory/cli/main.py +837 -0
  25. data_factory/cli/menu.py +173 -0
  26. data_factory/cli/render.py +158 -0
  27. data_factory/core/__init__.py +11 -0
  28. data_factory/core/annotations/__init__.py +5 -0
  29. data_factory/core/annotations/coco.py +394 -0
  30. data_factory/core/annotations/csvfmt.py +174 -0
  31. data_factory/core/annotations/dota.py +98 -0
  32. data_factory/core/annotations/formats.py +626 -0
  33. data_factory/core/annotations/labelme.py +153 -0
  34. data_factory/core/annotations/model.py +334 -0
  35. data_factory/core/annotations/voc.py +231 -0
  36. data_factory/core/annotations/yolo.py +283 -0
  37. data_factory/core/bktree.py +89 -0
  38. data_factory/core/fs.py +245 -0
  39. data_factory/core/imaging.py +626 -0
  40. data_factory/core/ops/__init__.py +44 -0
  41. data_factory/core/ops/analyze.py +383 -0
  42. data_factory/core/ops/annotate_export.py +326 -0
  43. data_factory/core/ops/audit.py +274 -0
  44. data_factory/core/ops/augment.py +454 -0
  45. data_factory/core/ops/collect.py +241 -0
  46. data_factory/core/ops/combine.py +582 -0
  47. data_factory/core/ops/convert.py +212 -0
  48. data_factory/core/ops/dataset.py +246 -0
  49. data_factory/core/ops/dedup.py +235 -0
  50. data_factory/core/ops/export.py +168 -0
  51. data_factory/core/ops/image.py +407 -0
  52. data_factory/core/ops/labels.py +215 -0
  53. data_factory/core/ops/pairing.py +133 -0
  54. data_factory/core/ops/rename.py +154 -0
  55. data_factory/core/ops/report.py +323 -0
  56. data_factory/core/ops/visualize.py +164 -0
  57. data_factory/core/pairs.py +144 -0
  58. data_factory/core/parallel.py +191 -0
  59. data_factory/core/provenance.py +136 -0
  60. data_factory/core/registry.py +339 -0
  61. data_factory/core/stats.py +403 -0
  62. data_factory/core/types.py +148 -0
  63. data_factory/core/writer.py +194 -0
  64. data_factory/desktop.py +207 -0
  65. data_factory/hardware.py +243 -0
  66. data_factory/pipeline.py +192 -0
  67. data_factory/py.typed +0 -0
  68. data_factory/service/__init__.py +26 -0
  69. data_factory/service/app.py +483 -0
  70. data_factory/service/binding.py +174 -0
  71. data_factory/service/deps.py +133 -0
  72. data_factory/service/jobs.py +177 -0
  73. data_factory/service/limits.py +71 -0
  74. data_factory/service/routers/__init__.py +11 -0
  75. data_factory/service/routers/annotate.py +582 -0
  76. data_factory/service/routers/local.py +464 -0
  77. data_factory/service/routers/media.py +154 -0
  78. data_factory/service/routers/predictions.py +116 -0
  79. data_factory/service/routers/promote.py +182 -0
  80. data_factory/service/routers/tools.py +308 -0
  81. data_factory/service/static/annotate/api.js +246 -0
  82. data_factory/service/static/annotate/app.js +1696 -0
  83. data_factory/service/static/annotate/assist.js +106 -0
  84. data_factory/service/static/annotate/filmstrip.js +286 -0
  85. data_factory/service/static/annotate/hit.js +146 -0
  86. data_factory/service/static/annotate/labels.js +197 -0
  87. data_factory/service/static/annotate/render.js +286 -0
  88. data_factory/service/static/annotate/scene.js +277 -0
  89. data_factory/service/static/annotate/shapelist.js +72 -0
  90. data_factory/service/static/annotate/tools/box.js +96 -0
  91. data_factory/service/static/annotate/tools/line.js +96 -0
  92. data_factory/service/static/annotate/tools/obb.js +88 -0
  93. data_factory/service/static/annotate/tools/point.js +49 -0
  94. data_factory/service/static/annotate/tools/polygon.js +110 -0
  95. data_factory/service/static/annotate/tools/select.js +227 -0
  96. data_factory/service/static/annotate/undo.js +176 -0
  97. data_factory/service/static/annotate/viewport.js +156 -0
  98. data_factory/service/static/annotate.html +390 -0
  99. data_factory/service/static/index.html +632 -0
  100. data_factory/service/workspace.py +244 -0
  101. easyannotate/__init__.py +64 -0
  102. easyannotate/__main__.py +5 -0
  103. easyannotate/project.py +181 -0
  104. easyannotate/py.typed +0 -0
  105. easyannotate-0.4.0.dist-info/METADATA +767 -0
  106. easyannotate-0.4.0.dist-info/RECORD +109 -0
  107. easyannotate-0.4.0.dist-info/WHEEL +4 -0
  108. easyannotate-0.4.0.dist-info/entry_points.txt +4 -0
  109. easyannotate-0.4.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,106 @@
1
+ """The sidecar side of the protocol: read requests, write exactly one reply.
2
+
3
+ A tool author writes a handler object and calls :func:`serve`. Everything about
4
+ framing, correlation ids and error replies is handled here, so a tool cannot
5
+ get the part wrong that hangs the editor.
6
+
7
+ The single rule this module exists to guarantee:
8
+
9
+ **every request produces exactly one reply, including when the handler
10
+ raises, and including when the handler raises something that is not an
11
+ Exception.**
12
+
13
+ The legacy SAM worker broke that rule -- it caught, printed, and looped -- and
14
+ the UI blocked forever on a read that would never return.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import os
20
+ import sys
21
+ import traceback
22
+ from typing import Any, BinaryIO, Protocol
23
+
24
+ from .protocol import ToolError, decode_message, encode_message, fail, ok
25
+
26
+
27
+ class Handler(Protocol):
28
+ """What a tool implements. Every method may raise; none may hang."""
29
+
30
+ def describe(self) -> list[dict[str, Any]]: ...
31
+ def health(self, params: dict[str, Any]) -> dict[str, Any]: ...
32
+ def prepare(self, params: dict[str, Any]) -> Any: ...
33
+ def invoke(self, params: dict[str, Any]) -> Any: ...
34
+
35
+
36
+ def serve(handler: Handler, stdin: BinaryIO | None = None, stdout: BinaryIO | None = None) -> int:
37
+ """Run the request loop until stdin closes. Returns a process exit code."""
38
+ source = stdin if stdin is not None else sys.stdin.buffer
39
+ sink = stdout if stdout is not None else _private_stdout()
40
+
41
+ for line in source:
42
+ if not line.strip():
43
+ continue
44
+
45
+ # Parsing is inside its own guard because a malformed frame has no id
46
+ # to reply against -- there is no one to answer, so we log and move on
47
+ # rather than dying and taking the healthy calls with us.
48
+ try:
49
+ payload = decode_message(line)
50
+ except ToolError as exc:
51
+ print(f"[tool] dropping unparseable frame: {exc}", file=sys.stderr, flush=True)
52
+ continue
53
+
54
+ message_id = payload.get("id")
55
+ if not isinstance(message_id, int):
56
+ print("[tool] dropping frame with no id", file=sys.stderr, flush=True)
57
+ continue
58
+
59
+ try:
60
+ result = _dispatch(handler, str(payload.get("method") or ""), payload.get("params") or {})
61
+ reply = ok(message_id, result)
62
+ except BaseException as exc: # noqa: BLE001 -- the whole point is to always reply
63
+ # BaseException, not Exception: a handler raising KeyboardInterrupt
64
+ # or a bare SystemExit must still produce a reply, or the caller
65
+ # waits for a message that is never coming.
66
+ traceback.print_exc()
67
+ reply = fail(message_id, exc if isinstance(exc, Exception) else ToolError(str(exc)))
68
+
69
+ try:
70
+ sink.write(encode_message(reply))
71
+ sink.flush()
72
+ except (BrokenPipeError, OSError):
73
+ # The parent is gone; nothing useful is left to do.
74
+ return 0
75
+
76
+ return 0
77
+
78
+
79
+ def _private_stdout() -> BinaryIO:
80
+ """Keep the real stdout for replies alone; everything else goes to stderr.
81
+
82
+ Libraries print. Ultralytics writes its download progress bar -- 13 KB of
83
+ carriage returns and no newline -- to stdout, and the next reply was
84
+ glued to the end of it and lost: on a first text prompt the editor said
85
+ "the tool exited". Measured, then fixed here for every library at once:
86
+ Python-level prints and C-level writes to fd 1 both land on stderr,
87
+ which the parent keeps as the tool's log.
88
+ """
89
+ sys.stdout.flush()
90
+ replies = os.fdopen(os.dup(sys.stdout.fileno()), "wb")
91
+ os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
92
+ sys.stdout = sys.stderr
93
+ return replies
94
+
95
+
96
+ def _dispatch(handler: Handler, method: str, params: dict[str, Any]) -> Any:
97
+ if method == "describe":
98
+ return handler.describe()
99
+ if method == "health":
100
+ return handler.health(params)
101
+ if method == "prepare":
102
+ handler.prepare(params)
103
+ return {"prepared": params.get("image_id")}
104
+ if method == "invoke":
105
+ return handler.invoke(params)
106
+ raise ToolError(f"unknown method {method!r}", code="unknown_method")
@@ -0,0 +1,21 @@
1
+ """Terminal front-end: argparse commands, the interactive menu, and rendering.
2
+
3
+ ``main`` is exposed lazily. Importing it eagerly would make
4
+ ``python -m data_factory.cli.main`` load the module twice and warn about it.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ __all__ = ["build_parser", "main"]
12
+
13
+
14
+ def __getattr__(name: str) -> Any:
15
+ if name in __all__:
16
+ # import_module, not `from . import main`: that asks this package for
17
+ # an attribute "main" first -- which is this function again, forever.
18
+ import importlib
19
+
20
+ return getattr(importlib.import_module(f"{__name__}.main"), name)
21
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")