tensorneko-util 0.3.14__tar.gz → 0.3.16__tar.gz

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 (128) hide show
  1. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/PKG-INFO +6 -8
  2. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/README.md +24 -3
  3. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/setup.py +10 -2
  4. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/setup_util.py +2 -1
  5. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/__init__.py +7 -0
  6. tensorneko_util-0.3.16/src/tensorneko_util/_rich.py +2 -0
  7. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/json/json_writer.py +3 -2
  8. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/video/video_writer.py +2 -1
  9. tensorneko_util-0.3.16/src/tensorneko_util/msg/__init__.py +3 -0
  10. tensorneko_util-0.3.16/src/tensorneko_util/msg/gotify.py +48 -0
  11. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/eventbus/bus.py +16 -13
  12. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/eventbus/event.py +1 -16
  13. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/registry.py +2 -2
  14. tensorneko_util-0.3.16/src/tensorneko_util/version.txt +1 -0
  15. tensorneko_util-0.3.16/src/tensorneko_util/visualization/watcher/web/dist/assets/index.ae750248.js +188 -0
  16. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/web/dist/index.html +1 -1
  17. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util.egg-info/PKG-INFO +6 -8
  18. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util.egg-info/SOURCES.txt +4 -2
  19. tensorneko_util-0.3.14/LICENSE +0 -21
  20. tensorneko_util-0.3.14/src/tensorneko_util/version.txt +0 -1
  21. tensorneko_util-0.3.14/src/tensorneko_util/visualization/watcher/web/dist/assets/index.493c52c5.js +0 -188
  22. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/setup.cfg +0 -0
  23. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/__init__.py +0 -0
  24. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/audio_lib.py +0 -0
  25. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/blocking.py +0 -0
  26. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/parallel.py +0 -0
  27. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/tqdm.py +0 -0
  28. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/backend/visual_lib.py +0 -0
  29. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/debug/__init__.py +0 -0
  30. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/debug/logger.py +0 -0
  31. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/debug/parser.py +0 -0
  32. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/__init__.py +0 -0
  33. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/_default_backends.py +0 -0
  34. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/audio/__init__.py +0 -0
  35. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/audio/audio_data.py +0 -0
  36. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/audio/audio_reader.py +0 -0
  37. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/audio/audio_writer.py +0 -0
  38. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/hdf5/__init__.py +0 -0
  39. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/hdf5/hdf5_reader.py +0 -0
  40. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/hdf5/hdf5_writer.py +0 -0
  41. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/image/__init__.py +0 -0
  42. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/image/image_reader.py +0 -0
  43. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/image/image_writer.py +0 -0
  44. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/json/__init__.py +0 -0
  45. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/json/json_data.py +0 -0
  46. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/json/json_reader.py +0 -0
  47. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/matlab/__init__.py +0 -0
  48. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/matlab/mat_reader.py +0 -0
  49. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/matlab/mat_writer.py +0 -0
  50. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/npy/__init__.py +0 -0
  51. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/npy/npy_reader.py +0 -0
  52. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/npy/npy_writer.py +0 -0
  53. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/pickle/__init__.py +0 -0
  54. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/pickle/pickle_reader.py +0 -0
  55. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/pickle/pickle_writer.py +0 -0
  56. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/reader.py +0 -0
  57. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/text/__init__.py +0 -0
  58. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/text/text_reader.py +0 -0
  59. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/text/text_writer.py +0 -0
  60. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/toml/__init__.py +0 -0
  61. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/toml/toml_reader.py +0 -0
  62. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/toml/toml_writer.py +0 -0
  63. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/video/__init__.py +0 -0
  64. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/video/video_data.py +0 -0
  65. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/video/video_reader.py +0 -0
  66. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/writer.py +0 -0
  67. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/yaml/__init__.py +0 -0
  68. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/yaml/yaml_reader.py +0 -0
  69. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/io/yaml/yaml_writer.py +0 -0
  70. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/notebook/__init__.py +0 -0
  71. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/notebook/display.py +0 -0
  72. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/__init__.py +0 -0
  73. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/crop.py +0 -0
  74. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/__init__.py +0 -0
  75. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/_utils.py +0 -0
  76. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/abstract_face_detector.py +0 -0
  77. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/anime_face_detector.py +0 -0
  78. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/facexzoo_face_detector.py +0 -0
  79. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/face_detector/opencv_face_detector.py +0 -0
  80. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/ffmpeg.py +0 -0
  81. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/image.py +0 -0
  82. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/preprocess/video.py +0 -0
  83. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/__init__.py +0 -0
  84. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/average_meter.py +0 -0
  85. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/bimap.py +0 -0
  86. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/dispatched_misc.py +0 -0
  87. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/dispatcher.py +0 -0
  88. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/downloader.py +0 -0
  89. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/eventbus/__init__.py +0 -0
  90. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/eventbus/decorator.py +0 -0
  91. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/__init__.py +0 -0
  92. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/args.py +0 -0
  93. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/array/__init__.py +0 -0
  94. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/array/abstract_seq.py +0 -0
  95. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/array/seq.py +0 -0
  96. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/array/stream.py +0 -0
  97. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/func.py +0 -0
  98. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/monad/__init__.py +0 -0
  99. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/monad/eval.py +0 -0
  100. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/monad/monad.py +0 -0
  101. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/monad/option.py +0 -0
  102. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/fp/underscore.py +0 -0
  103. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/misc.py +0 -0
  104. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/ref.py +0 -0
  105. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/server.py +0 -0
  106. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/singleton.py +0 -0
  107. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/timer.py +0 -0
  108. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/type.py +0 -0
  109. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/util/window_merger.py +0 -0
  110. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/__init__.py +0 -0
  111. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/color.py +0 -0
  112. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/image_browser/__init__.py +0 -0
  113. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/image_browser/server.py +0 -0
  114. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/image_browser/web/index.html +0 -0
  115. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/matplotlib.py +0 -0
  116. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/multi_plots.py +0 -0
  117. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/seaborn.py +0 -0
  118. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/tensorboard.py +0 -0
  119. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/__init__.py +0 -0
  120. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/component.py +0 -0
  121. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/server.py +0 -0
  122. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/view.py +0 -0
  123. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util/visualization/watcher/web/dist/assets/index.cf95019d.css +0 -0
  124. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util.egg-info/dependency_links.txt +0 -0
  125. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util.egg-info/requires.txt +1 -1
  126. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/src/tensorneko_util.egg-info/top_level.txt +0 -0
  127. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/test/test_library_info.py +0 -0
  128. {tensorneko_util-0.3.14 → tensorneko_util-0.3.16}/test/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko_util
3
- Version: 0.3.14
3
+ Version: 0.3.16
4
4
  Summary: The Utils for Library TensorNeko.
5
5
  Home-page: https://github.com/ControlNet/tensorneko
6
6
  Author: ControlNet
@@ -8,7 +8,10 @@ Author-email: smczx@hotmail.com
8
8
  License: UNKNOWN
9
9
  Project-URL: Bug Tracker, https://github.com/ControlNet/tensorneko/issues
10
10
  Project-URL: Source Code, https://github.com/ControlNet/tensorneko
11
- Keywords: deep learning,pytorch,AI
11
+ Description:
12
+ The independent util library for TensorNeko. This library doesn't require PyTorch as a dependency.
13
+
14
+ Keywords: deep learning,pytorch,AI,data processing
12
15
  Platform: UNKNOWN
13
16
  Classifier: Programming Language :: Python :: 3
14
17
  Classifier: Programming Language :: Python :: 3.7
@@ -16,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.8
16
19
  Classifier: Programming Language :: Python :: 3.9
17
20
  Classifier: Programming Language :: Python :: 3.10
18
21
  Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
19
23
  Classifier: License :: OSI Approved :: MIT License
20
24
  Classifier: Operating System :: OS Independent
21
25
  Classifier: Intended Audience :: Developers
@@ -23,9 +27,3 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
27
  Classifier: Topic :: Utilities
24
28
  Requires-Python: >=3.7
25
29
  Description-Content-Type: text/markdown
26
- License-File: LICENSE
27
-
28
-
29
- The independent util library for TensorNeko. This library doesn't require PyTorch as a dependency.
30
-
31
-
@@ -25,8 +25,11 @@ Tensor Neural Engine Kompanion. An util library based on PyTorch and PyTorch Lig
25
25
 
26
26
  ## Install
27
27
 
28
+ The tensorneko requires pytorch and pytorch-lightning (optional), and you can install it with below command.
29
+
28
30
  ```shell
29
- pip install tensorneko
31
+ pip install tensorneko # for PyTorch only
32
+ pip install tensorneko[lightning] # for PyTorch and Lightning
30
33
  ```
31
34
 
32
35
  To use the library without PyTorch and PyTorch Lightning, you can install the util library (support Python 3.7 ~ 3.12 with limited features) with following command.
@@ -34,11 +37,18 @@ To use the library without PyTorch and PyTorch Lightning, you can install the ut
34
37
  pip install tensorneko_util
35
38
  ```
36
39
 
37
- Some cpu bound functions are implemented by `pyo3`, and you can install the optimized version with below command.
40
+ Some cpu bound functions are implemented by rust-based `pyo3`, and you can install the optimized version with below command.
38
41
  ```shell
39
42
  pip install tensorneko_lib
40
43
  ```
41
44
 
45
+ Some CLI tools are provided in the `tensorneko_tool` package, and you can install it with below command.
46
+ ```shell
47
+ pipx install tensorneko_tool # or `pip install tensorneko_tool`
48
+ ```
49
+
50
+ Then you can use the CLI tools `tensorneko` in the terminal.
51
+
42
52
  ## Neko Layers, Modules and Architectures
43
53
 
44
54
  Build an MLP with linear layers. The activation and normalization will be placed in the hidden layers.
@@ -481,7 +491,7 @@ This library provides event bus based reactive tools. The API integrates the Pyt
481
491
  # useful decorators for default event bus
482
492
  from tensorneko.util import subscribe
483
493
  # Event base type
484
- from tensorneko.util import Event
494
+ from tensorneko.util import Event, EventBus
485
495
 
486
496
  class LogEvent(Event):
487
497
  def __init__(self, message: str):
@@ -511,6 +521,7 @@ if __name__ == '__main__':
511
521
  # emit an event, and then the event handler will be invoked
512
522
  # The sequential order is not guaranteed
513
523
  LogEvent("Hello world!")
524
+ EventBus.default.wait() # it's not blocking, need to call wait manually before exit.
514
525
  # one possible output:
515
526
  # Hello world! in another thread
516
527
  # Hello world! async
@@ -646,3 +657,13 @@ Functions list (in `tensorneko`):
646
657
  - `with_printed_shape`
647
658
  - `is_bad_num`
648
659
  - `count_parameters`
660
+
661
+ ## TensorNeko Tools
662
+
663
+ Some CLI tools are provided in the `tensorneko_tool` package.
664
+
665
+ The `gotify` can send a message to the Gotify server, with the environment variables `GOTIFY_URL` and `GOTIFY_TOKEN` set.
666
+
667
+ ```shell
668
+ tensorneko gotify "Script finished!"
669
+ ```
@@ -5,9 +5,13 @@ with open("README.md", "r") as file:
5
5
  long_description = file.read()
6
6
 
7
7
  requirements = []
8
+ extra_requirements = []
8
9
  with open("requirements.txt", "r") as file:
9
10
  for line in file:
10
- requirements.append(line.strip())
11
+ if line.startswith("lightning") or line.startswith("tensorboard"):
12
+ extra_requirements.append(line.strip())
13
+ else:
14
+ requirements.append(line.strip())
11
15
 
12
16
 
13
17
  version = init.read_version()
@@ -27,7 +31,7 @@ setuptools.setup(
27
31
  "Bug Tracker": "https://github.com/ControlNet/tensorneko/issues",
28
32
  "Source Code": "https://github.com/ControlNet/tensorneko",
29
33
  },
30
- keywords=["deep learning", "pytorch", "AI"],
34
+ keywords=["deep learning", "pytorch", "AI", "data processing"],
31
35
  package_dir={"": "src"},
32
36
  packages=setuptools.find_packages(where="src", include=["tensorneko", "tensorneko.*"]),
33
37
  package_data={
@@ -37,12 +41,16 @@ setuptools.setup(
37
41
  },
38
42
  python_requires=">=3.8",
39
43
  install_requires=requirements,
44
+ extras_require={
45
+ "lightning": extra_requirements
46
+ },
40
47
  classifiers=[
41
48
  "Programming Language :: Python :: 3",
42
49
  "Programming Language :: Python :: 3.8",
43
50
  "Programming Language :: Python :: 3.9",
44
51
  "Programming Language :: Python :: 3.10",
45
52
  "Programming Language :: Python :: 3.11",
53
+ "Programming Language :: Python :: 3.12",
46
54
  "License :: OSI Approved :: MIT License",
47
55
  "Operating System :: OS Independent",
48
56
  "Intended Audience :: Developers",
@@ -26,7 +26,7 @@ setuptools.setup(
26
26
  "Bug Tracker": "https://github.com/ControlNet/tensorneko/issues",
27
27
  "Source Code": "https://github.com/ControlNet/tensorneko",
28
28
  },
29
- keywords=["deep learning", "pytorch", "AI"],
29
+ keywords=["deep learning", "pytorch", "AI", "data processing"],
30
30
  package_dir={"": "src"},
31
31
  packages=setuptools.find_packages(where="src", include=["tensorneko_util", "tensorneko_util.*"]),
32
32
  package_data={
@@ -46,6 +46,7 @@ setuptools.setup(
46
46
  "Programming Language :: Python :: 3.9",
47
47
  "Programming Language :: Python :: 3.10",
48
48
  "Programming Language :: Python :: 3.11",
49
+ "Programming Language :: Python :: 3.12",
49
50
  "License :: OSI Approved :: MIT License",
50
51
  "Operating System :: OS Independent",
51
52
  "Intended Audience :: Developers",
@@ -7,6 +7,7 @@ from . import visualization
7
7
  from . import preprocess
8
8
  from . import io
9
9
  from . import debug
10
+ from . import msg
10
11
  from .io import read, write
11
12
 
12
13
  __all__ = [
@@ -16,9 +17,15 @@ __all__ = [
16
17
  "preprocess",
17
18
  "io",
18
19
  "debug",
20
+ "msg",
19
21
  "read",
20
22
  "write",
21
23
  ]
22
24
 
25
+ try:
26
+ from . import _rich
27
+ except ImportError:
28
+ pass
29
+
23
30
  with open(os.path.join(dirname(__file__), "version.txt"), "r", encoding="UTF-8") as file:
24
31
  __version__ = file.read()
@@ -0,0 +1,2 @@
1
+ from rich.traceback import install
2
+ install(show_locals=False)
@@ -14,9 +14,10 @@ class JsonWriter:
14
14
  json.dump(obj, file, indent=indent, ensure_ascii=ensure_ascii)
15
15
  else:
16
16
  import orjson
17
- with open(path, "w", encoding=encoding) as file:
17
+ with open(path, "wb") as file:
18
18
  if indent == 4:
19
- option = orjson.OPT_INDENT_4
19
+ warnings.warn("orjson does not support indent 4, will use indent 2 instead.")
20
+ option = orjson.OPT_INDENT_2
20
21
  elif indent == 2:
21
22
  option = orjson.OPT_INDENT_2
22
23
  else:
@@ -1,5 +1,6 @@
1
1
  import pathlib
2
2
  import warnings
3
+ from subprocess import Popen
3
4
  from typing import Optional, Union
4
5
 
5
6
  import numpy as np
@@ -116,7 +117,7 @@ class VideoWriter:
116
117
  if not VisualLib.ffmpeg_available():
117
118
  raise ValueError("FFMPEG is not installed.")
118
119
  import ffmpeg
119
- pipe = ffmpeg.input("pipe:", format="rawvideo", pix_fmt="rgb24", s=f"{video.shape[2]}x{video.shape[1]}") \
120
+ pipe: Popen = ffmpeg.input("pipe:", format="rawvideo", pix_fmt="rgb24", s=f"{video.shape[2]}x{video.shape[1]}") \
120
121
  .output(path, format=ext[1:], pix_fmt="rgb24", r=video_fps) \
121
122
  .overwrite_output() \
122
123
  .run_async(pipe_stdin=True)
@@ -0,0 +1,3 @@
1
+ from .gotify import push_gotify
2
+
3
+ __all__ = ["push_gotify"]
@@ -0,0 +1,48 @@
1
+ import json
2
+ import os
3
+ import socket
4
+ import urllib.request
5
+ from typing import Optional
6
+ from urllib.error import HTTPError
7
+
8
+
9
+ def push_gotify(message: str, url: Optional[str] = None, token: Optional[str] = None, title: Optional[str] = None,
10
+ priority: int = 0
11
+ ):
12
+ """
13
+ Push a message to a Gotify server.
14
+
15
+ Args:
16
+ message (``str``): The message to be sent.
17
+ url (``str``, optional): The URL of the Gotify server. If not provided, it will be read from the environment variable GOTIFY_URL.
18
+ token (``str``, optional): The token for the Gotify server. If not provided, it will be read from the environment variable GOTIFY_TOKEN.
19
+ title (``str``, optional): The title of the message. Default is the hostname of the machine.
20
+ priority (``int``, optional): The priority of the message. Default is 0.
21
+
22
+ Examples::
23
+
24
+ push_gotify("This is a test message", "<URL>", "<APP_TOKEN>")
25
+ # then the message will be sent to the Gotify server.
26
+ # title = "<HOST_NAME>", message = "This is a test message", priority = 0
27
+
28
+ """
29
+ title = title or socket.gethostname()
30
+ url = url or os.environ.get("GOTIFY_URL")
31
+ if url is None:
32
+ raise ValueError("URL is not provided. Input url argument or set the environment variable GOTIFY_URL.")
33
+ token = token or os.environ.get("GOTIFY_TOKEN")
34
+ if token is None:
35
+ raise ValueError("Token is not provided. Input token argument or set the environment variable GOTIFY_TOKEN.")
36
+ url = f"{url.rstrip('/')}/message?token={token}"
37
+ data = json.dumps(
38
+ {"title": title, "message": message, "priority": priority}
39
+ ).encode("utf-8")
40
+ req = urllib.request.Request(url, data=data, method="POST", headers={
41
+ "Content-Type": "application/json",
42
+ "User-Agent": "TensorNeko"
43
+ })
44
+ try:
45
+ with urllib.request.urlopen(req) as res:
46
+ pass
47
+ except HTTPError as e:
48
+ print(e.read().decode("utf-8"))
@@ -6,7 +6,8 @@ from abc import ABC, abstractmethod
6
6
  from concurrent.futures import wait
7
7
  from dataclasses import dataclass
8
8
  from enum import Enum
9
- from typing import Dict, Type, Callable, TYPE_CHECKING, Any, Coroutine, Union, Set, TypeVar
9
+ from typing import Dict, Type, Callable, TYPE_CHECKING, Any, Coroutine, Union, Set, TypeVar, List
10
+ from concurrent.futures import Future
10
11
 
11
12
  from ...backend.parallel import ExecutorPool, ParallelType
12
13
 
@@ -99,12 +100,7 @@ class EventBus:
99
100
  .. code-block:: python
100
101
 
101
102
  # useful decorators for default event bus
102
- from tensorneko.util import (
103
- subscribe, # run in the main thread
104
- subscribe_thread, # run in a new thread
105
- subscribe_async, # run async
106
- subscribe_process # run in a new process
107
- )
103
+ from tensorneko.util import subscribe
108
104
  # Event base type
109
105
  from tensorneko.util import Event
110
106
 
@@ -117,15 +113,15 @@ class EventBus:
117
113
  def log_information(event: LogEvent):
118
114
  print(event.message)
119
115
 
120
- @subscribe_thread
116
+ @subscribe.thread
121
117
  def log_information_thread(event: LogEvent):
122
118
  print(event.message, "in another thread")
123
119
 
124
- @subscribe_async
120
+ @subscribe.coro
125
121
  async def log_information_async(event: LogEvent):
126
122
  print(event.message, "async")
127
123
 
128
- @subscribe_process
124
+ @subscribe.process
129
125
  def log_information_process(event: LogEvent):
130
126
  print(event.message, "in a new process")
131
127
 
@@ -171,6 +167,7 @@ class EventBus:
171
167
 
172
168
  def __init__(self):
173
169
  self.listeners: Dict[Type[E], Set[Listener]] = {}
170
+ self.futures: List[Future] = []
174
171
 
175
172
  def register(self,
176
173
  event_type: Type[E],
@@ -185,7 +182,7 @@ class EventBus:
185
182
  self.listeners[event_type] = set()
186
183
  self.listeners[event_type].add(Listener(func, func_name, emit_type))
187
184
 
188
- def emit(self, event: E, blocking: bool = True) -> None:
185
+ def emit(self, event: E) -> None:
189
186
  event_type: Type[E] = type(event)
190
187
  if event_type in self.listeners:
191
188
  normal_listeners = set()
@@ -216,8 +213,14 @@ class EventBus:
216
213
  for listener in normal_listeners:
217
214
  listener.func(event)
218
215
 
219
- if blocking:
220
- wait(futures)
216
+ self.futures.extend(futures)
217
+
218
+ def wait(self):
219
+ """
220
+ Wait for all the futures to be completed.
221
+ """
222
+ wait(self.futures)
223
+ self.futures.clear()
221
224
 
222
225
  @staticmethod
223
226
  async def emit_async(async_listeners: Set[Listener], event: E) -> None:
@@ -1,4 +1,3 @@
1
- from contextlib import contextmanager
2
1
  from typing import TypeVar
3
2
 
4
3
  from .bus import EventBus
@@ -9,24 +8,10 @@ class EventMeta(type):
9
8
  def __call__(cls, *args, **kwargs):
10
9
  event = super().__call__(*args, **kwargs)
11
10
  event.bus = kwargs.get("bus", EventBus.default)
12
- event.bus.emit(event, blocking=_blocking_flag)
11
+ event.bus.emit(event)
13
12
  return event
14
13
 
15
14
 
16
- _blocking_flag = True
17
-
18
-
19
- @contextmanager
20
- def no_blocking():
21
- """
22
- Context manager to disable blocking event handler.
23
- """
24
- global _blocking_flag
25
- _blocking_flag = False
26
- yield
27
- _blocking_flag = True
28
-
29
-
30
15
  class Event(metaclass=EventMeta):
31
16
  bus: EventBus
32
17
 
@@ -28,7 +28,7 @@ class Registry(Generic[T]):
28
28
  """
29
29
 
30
30
  def __init__(self):
31
- self._registry: dict[str, T] = {}
31
+ self._registry: dict[str, Type[T]] = {}
32
32
 
33
33
  def register(self, name: str) -> Callable[[Type[T]], Type[T]]:
34
34
  def wrapper(cls):
@@ -37,7 +37,7 @@ class Registry(Generic[T]):
37
37
 
38
38
  return wrapper
39
39
 
40
- def __getitem__(self, name: str) -> T:
40
+ def __getitem__(self, name: str) -> Type[T]:
41
41
  return self._registry[name]
42
42
 
43
43
  def items(self):