stouputils 1.14.2__tar.gz → 1.14.3__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 (170) hide show
  1. {stouputils-1.14.2 → stouputils-1.14.3}/PKG-INFO +1 -1
  2. {stouputils-1.14.2 → stouputils-1.14.3}/pyproject.toml +1 -1
  3. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/pypi.py +1 -1
  4. stouputils-1.14.2/stouputils/continuous_delivery/pypi.pyi +0 -52
  5. stouputils-1.14.2/stouputils/decorators.pyi +0 -242
  6. stouputils-1.14.2/stouputils/parallel.pyi +0 -211
  7. stouputils-1.14.2/stouputils/print.pyi +0 -136
  8. stouputils-1.14.2/stouputils/stouputils/__init__.pyi +0 -15
  9. stouputils-1.14.2/stouputils/stouputils/_deprecated.pyi +0 -12
  10. stouputils-1.14.2/stouputils/stouputils/all_doctests.pyi +0 -46
  11. stouputils-1.14.2/stouputils/stouputils/applications/__init__.pyi +0 -2
  12. stouputils-1.14.2/stouputils/stouputils/applications/automatic_docs.pyi +0 -106
  13. stouputils-1.14.2/stouputils/stouputils/applications/upscaler/__init__.pyi +0 -3
  14. stouputils-1.14.2/stouputils/stouputils/applications/upscaler/config.pyi +0 -18
  15. stouputils-1.14.2/stouputils/stouputils/applications/upscaler/image.pyi +0 -109
  16. stouputils-1.14.2/stouputils/stouputils/applications/upscaler/video.pyi +0 -60
  17. stouputils-1.14.2/stouputils/stouputils/archive.pyi +0 -67
  18. stouputils-1.14.2/stouputils/stouputils/backup.pyi +0 -109
  19. stouputils-1.14.2/stouputils/stouputils/collections.pyi +0 -86
  20. stouputils-1.14.2/stouputils/stouputils/continuous_delivery/__init__.pyi +0 -5
  21. stouputils-1.14.2/stouputils/stouputils/continuous_delivery/cd_utils.pyi +0 -129
  22. stouputils-1.14.2/stouputils/stouputils/continuous_delivery/github.pyi +0 -162
  23. stouputils-1.14.2/stouputils/stouputils/continuous_delivery/pyproject.pyi +0 -67
  24. stouputils-1.14.2/stouputils/stouputils/continuous_delivery/stubs.pyi +0 -39
  25. stouputils-1.14.2/stouputils/stouputils/ctx.pyi +0 -211
  26. stouputils-1.14.2/stouputils/stouputils/image.pyi +0 -172
  27. stouputils-1.14.2/stouputils/stouputils/installer/__init__.pyi +0 -5
  28. stouputils-1.14.2/stouputils/stouputils/installer/common.pyi +0 -39
  29. stouputils-1.14.2/stouputils/stouputils/installer/downloader.pyi +0 -24
  30. stouputils-1.14.2/stouputils/stouputils/installer/linux.pyi +0 -39
  31. stouputils-1.14.2/stouputils/stouputils/installer/main.pyi +0 -57
  32. stouputils-1.14.2/stouputils/stouputils/installer/windows.pyi +0 -31
  33. stouputils-1.14.2/stouputils/stouputils/io.pyi +0 -213
  34. stouputils-1.14.2/stouputils/version_pkg.pyi +0 -15
  35. {stouputils-1.14.2 → stouputils-1.14.3}/README.md +0 -0
  36. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/__init__.py +0 -0
  37. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/__init__.pyi +0 -0
  38. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/__main__.py +0 -0
  39. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/_deprecated.py +0 -0
  40. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/_deprecated.pyi +0 -0
  41. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/all_doctests.py +0 -0
  42. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/all_doctests.pyi +0 -0
  43. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/__init__.py +0 -0
  44. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/__init__.pyi +0 -0
  45. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/automatic_docs.py +0 -0
  46. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/automatic_docs.pyi +0 -0
  47. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/__init__.py +0 -0
  48. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/__init__.pyi +0 -0
  49. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/config.py +0 -0
  50. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/config.pyi +0 -0
  51. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/image.py +0 -0
  52. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/image.pyi +0 -0
  53. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/video.py +0 -0
  54. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/applications/upscaler/video.pyi +0 -0
  55. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/archive.py +0 -0
  56. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/archive.pyi +0 -0
  57. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/backup.py +0 -0
  58. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/backup.pyi +0 -0
  59. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/collections.py +0 -0
  60. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/collections.pyi +0 -0
  61. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/__init__.py +0 -0
  62. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/__init__.pyi +0 -0
  63. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/cd_utils.py +0 -0
  64. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/cd_utils.pyi +0 -0
  65. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/github.py +0 -0
  66. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/github.pyi +0 -0
  67. {stouputils-1.14.2/stouputils → stouputils-1.14.3}/stouputils/continuous_delivery/pypi.pyi +0 -0
  68. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/pyproject.py +0 -0
  69. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/pyproject.pyi +0 -0
  70. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/stubs.py +0 -0
  71. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/continuous_delivery/stubs.pyi +0 -0
  72. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/ctx.py +0 -0
  73. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/ctx.pyi +0 -0
  74. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/config/get.py +0 -0
  75. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/config/set.py +0 -0
  76. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/__init__.py +0 -0
  77. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/auto_contrast.py +0 -0
  78. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/axis_flip.py +0 -0
  79. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/bias_field_correction.py +0 -0
  80. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/binary_threshold.py +0 -0
  81. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/blur.py +0 -0
  82. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/brightness.py +0 -0
  83. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/canny.py +0 -0
  84. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/clahe.py +0 -0
  85. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/common.py +0 -0
  86. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/contrast.py +0 -0
  87. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/curvature_flow_filter.py +0 -0
  88. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/denoise.py +0 -0
  89. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/histogram_equalization.py +0 -0
  90. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/invert.py +0 -0
  91. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/laplacian.py +0 -0
  92. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/median_blur.py +0 -0
  93. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/noise.py +0 -0
  94. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/normalize.py +0 -0
  95. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/random_erase.py +0 -0
  96. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/resize.py +0 -0
  97. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/rotation.py +0 -0
  98. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/salt_pepper.py +0 -0
  99. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/sharpening.py +0 -0
  100. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/shearing.py +0 -0
  101. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/threshold.py +0 -0
  102. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/translation.py +0 -0
  103. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image/zoom.py +0 -0
  104. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image_augmentation.py +0 -0
  105. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/image_preprocess.py +0 -0
  106. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/prosthesis_detection.py +0 -0
  107. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/data_processing/technique.py +0 -0
  108. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/__init__.py +0 -0
  109. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/dataset.py +0 -0
  110. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/dataset_loader.py +0 -0
  111. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/grouping_strategy.py +0 -0
  112. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/image_loader.py +0 -0
  113. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/dataset/xy_tuple.py +0 -0
  114. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/metric_dictionnary.py +0 -0
  115. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/metric_utils.py +0 -0
  116. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/mlflow_utils.py +0 -0
  117. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/abstract_model.py +0 -0
  118. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/all.py +0 -0
  119. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/base_keras.py +0 -0
  120. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/all.py +0 -0
  121. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/convnext.py +0 -0
  122. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/densenet.py +0 -0
  123. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/efficientnet.py +0 -0
  124. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/mobilenet.py +0 -0
  125. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/resnet.py +0 -0
  126. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/squeezenet.py +0 -0
  127. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/vgg.py +0 -0
  128. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras/xception.py +0 -0
  129. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/__init__.py +0 -0
  130. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/colored_progress_bar.py +0 -0
  131. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/learning_rate_finder.py +0 -0
  132. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/model_checkpoint_v2.py +0 -0
  133. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/progressive_unfreezing.py +0 -0
  134. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/callbacks/warmup_scheduler.py +0 -0
  135. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/losses/__init__.py +0 -0
  136. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/losses/next_generation_loss.py +0 -0
  137. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/keras_utils/visualizations.py +0 -0
  138. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/model_interface.py +0 -0
  139. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/models/sandbox.py +0 -0
  140. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/range_tuple.py +0 -0
  141. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/scripts/augment_dataset.py +0 -0
  142. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/scripts/exhaustive_process.py +0 -0
  143. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/scripts/preprocess_dataset.py +0 -0
  144. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/scripts/routine.py +0 -0
  145. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/data_science/utils.py +0 -0
  146. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/decorators.py +0 -0
  147. {stouputils-1.14.2/stouputils → stouputils-1.14.3}/stouputils/decorators.pyi +0 -0
  148. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/image.py +0 -0
  149. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/image.pyi +0 -0
  150. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/__init__.py +0 -0
  151. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/__init__.pyi +0 -0
  152. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/common.py +0 -0
  153. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/common.pyi +0 -0
  154. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/downloader.py +0 -0
  155. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/downloader.pyi +0 -0
  156. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/linux.py +0 -0
  157. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/linux.pyi +0 -0
  158. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/main.py +0 -0
  159. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/main.pyi +0 -0
  160. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/windows.py +0 -0
  161. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/installer/windows.pyi +0 -0
  162. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/io.py +0 -0
  163. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/io.pyi +0 -0
  164. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/parallel.py +0 -0
  165. {stouputils-1.14.2/stouputils → stouputils-1.14.3}/stouputils/parallel.pyi +0 -0
  166. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/print.py +0 -0
  167. {stouputils-1.14.2/stouputils → stouputils-1.14.3}/stouputils/print.pyi +0 -0
  168. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/py.typed +0 -0
  169. {stouputils-1.14.2 → stouputils-1.14.3}/stouputils/version_pkg.py +0 -0
  170. {stouputils-1.14.2/stouputils → stouputils-1.14.3}/stouputils/version_pkg.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: stouputils
3
- Version: 1.14.2
3
+ Version: 1.14.3
4
4
  Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
5
5
  Keywords: utilities,tools,helpers,development,python
6
6
  Author: Stoupy51
@@ -8,7 +8,7 @@ module-root = ""
8
8
 
9
9
  [project]
10
10
  name = "stouputils"
11
- version = "1.14.2"
11
+ version = "1.14.3"
12
12
  description = "Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more."
13
13
  readme = "README.md"
14
14
  keywords = ["utilities", "tools", "helpers", "development", "python"]
@@ -110,7 +110,7 @@ def pypi_full_routine_using_uv() -> None:
110
110
  # Generate stubs unless '--no-stubs' is passed
111
111
  if "--no-stubs" not in sys.argv and "--no_stubs" not in sys.argv:
112
112
  from .stubs import stubs_full_routine
113
- stubs_full_routine(package_name, output_directory=package_dir, clean_before=True)
113
+ stubs_full_routine(package_name, output_directory=os.path.dirname(package_dir) or ".", clean_before=True)
114
114
 
115
115
  # Increment version in pyproject.toml
116
116
  if "--no-bump" not in sys.argv and "--no_bump" not in sys.argv:
@@ -1,52 +0,0 @@
1
- from ..decorators import LogLevels as LogLevels, handle_error as handle_error
2
- from .pyproject import read_pyproject as read_pyproject
3
- from collections.abc import Callable as Callable
4
-
5
- def update_pip_and_required_packages() -> int:
6
- """ Update pip and required packages.
7
-
8
- \tReturns:
9
- \t\tint: Return code of the os.system call.
10
- \t"""
11
- def build_package() -> int:
12
- """ Build the package.
13
-
14
- \tReturns:
15
- \t\tint: Return code of the os.system call.
16
- \t"""
17
- def upload_package(repository: str, filepath: str) -> int:
18
- """ Upload the package to PyPI.
19
-
20
- \tArgs:
21
- \t\trepository (str): Repository to upload to.
22
- \t\tfilepath (str): Path to the file to upload.
23
-
24
- \tReturns:
25
- \t\tint: Return code of the os.system call.
26
- \t"""
27
- def pypi_full_routine(repository: str, dist_directory: str, last_files: int = 1, endswith: str = '.tar.gz', update_all_function: Callable[[], int] = ..., build_package_function: Callable[[], int] = ..., upload_package_function: Callable[[str, str], int] = ...) -> None:
28
- ''' Upload the most recent file(s) to PyPI after updating pip and required packages and building the package.
29
-
30
- \tArgs:
31
- \t\trepository (str): Repository to upload to.
32
- \t\tdist_directory (str): Directory to upload from.
33
- \t\tlast_files (int): Number of most recent files to upload. Defaults to 1.
34
- \t\tendswith (str): End of the file name to upload. Defaults to ".tar.gz".
35
- \t\tupdate_all_function (Callable[[], int]): Function to update pip and required packages.
36
- \t\t\tDefaults to :func:`update_pip_and_required_packages`.
37
- \t\tbuild_package_function (Callable[[], int]): Function to build the package.
38
- \t\t\tDefaults to :func:`build_package`.
39
- \t\tupload_package_function (Callable[[str, str], int]): Function to upload the package.
40
- \t\t\tDefaults to :func:`upload_package`.
41
-
42
- \tReturns:
43
- \t\tint: Return code of the command.
44
- \t'''
45
- def pypi_full_routine_using_uv() -> None:
46
- """ Full build and publish routine using 'uv' command line tool.
47
-
48
- \tSteps:
49
- \t\t1. Generate stubs unless '--no-stubs' is passed
50
- \t\t2. Build the package using 'uv build'
51
- \t\t3. Upload the most recent file to PyPI using 'uv publish'
52
- \t"""
@@ -1,242 +0,0 @@
1
- from .ctx import MeasureTime as MeasureTime, Muffle as Muffle
2
- from .print import error as error, progress as progress, warning as warning
3
- from collections.abc import Callable as Callable
4
- from enum import Enum
5
- from typing import Any, Literal
6
-
7
- def measure_time(func: Callable[..., Any] | None = None, *, printer: Callable[..., None] = ..., message: str = '', perf_counter: bool = True, is_generator: bool = False) -> Callable[..., Any]:
8
- ''' Decorator that will measure the execution time of a function and print it with the given print function
9
-
10
- \tArgs:
11
- \t\tfunc\t\t\t(Callable[..., Any] | None): Function to decorate
12
- \t\tprinter\t\t\t(Callable):\tFunction to use to print the execution time (e.g. debug, info, warning, error, etc.)
13
- \t\tmessage\t\t\t(str):\t\tMessage to display with the execution time (e.g. "Execution time of Something"),
14
- \t\t\tdefaults to "Execution time of {func.__name__}"
15
- \t\tperf_counter\t(bool):\t\tWhether to use time.perf_counter_ns or time.time_ns
16
- \t\t\tdefaults to True (use time.perf_counter_ns)
17
- \t\tis_generator\t(bool):\t\tWhether the function is a generator or not (default: False)
18
- \t\t\tWhen True, the decorator will yield from the function instead of returning it.
19
-
20
- \tReturns:
21
- \t\tCallable: Decorator to measure the time of the function.
22
-
23
- \tExamples:
24
- \t\t.. code-block:: python
25
-
26
- \t\t\t> @measure_time(printer=info)
27
- \t\t\t> def test():
28
- \t\t\t> pass
29
- \t\t\t> test() # [INFO HH:MM:SS] Execution time of test: 0.000ms (400ns)
30
- \t'''
31
-
32
- class LogLevels(Enum):
33
- """ Log level for the errors in the decorator handle_error() """
34
- NONE = 0
35
- WARNING = 1
36
- WARNING_TRACEBACK = 2
37
- ERROR_TRACEBACK = 3
38
- RAISE_EXCEPTION = 4
39
-
40
- force_raise_exception: bool
41
-
42
- def handle_error(func: Callable[..., Any] | None = None, *, exceptions: tuple[type[BaseException], ...] | type[BaseException] = ..., message: str = '', error_log: LogLevels = ..., sleep_time: float = 0.0) -> Callable[..., Any]:
43
- ''' Decorator that handle an error with different log levels.
44
-
45
- \tArgs:
46
- \t\tfunc (Callable[..., Any] | None): \tFunction to decorate
47
- \t\texceptions\t(tuple[type[BaseException]], ...):\tExceptions to handle
48
- \t\tmessage\t\t(str):\t\t\t\t\t\t\t\tMessage to display with the error. (e.g. "Error during something")
49
- \t\terror_log\t(LogLevels):\t\t\t\t\t\tLog level for the errors
50
- \t\t\tLogLevels.NONE:\t\t\t\t\tNone
51
- \t\t\tLogLevels.WARNING:\t\t\t\tShow as warning
52
- \t\t\tLogLevels.WARNING_TRACEBACK:\tShow as warning with traceback
53
- \t\t\tLogLevels.ERROR_TRACEBACK:\t\tShow as error with traceback
54
- \t\t\tLogLevels.RAISE_EXCEPTION:\t\tRaise exception
55
- \t\tsleep_time\t(float):\t\t\t\t\t\t\tTime to sleep after the error (e.g. 0.0 to not sleep, 1.0 to sleep for 1 second)
56
-
57
- \tExamples:
58
- \t\t>>> @handle_error
59
- \t\t... def might_fail():
60
- \t\t... raise ValueError("Let\'s fail")
61
-
62
- \t\t>>> @handle_error(error_log=LogLevels.WARNING)
63
- \t\t... def test():
64
- \t\t... raise ValueError("Let\'s fail")
65
- \t\t>>> # test()\t# [WARNING HH:MM:SS] Error during test: (ValueError) Let\'s fail
66
- \t'''
67
- def timeout(func: Callable[..., Any] | None = None, *, seconds: float = 60.0, message: str = '') -> Callable[..., Any]:
68
- ''' Decorator that raises a TimeoutError if the function runs longer than the specified timeout.
69
-
70
- \tNote: This decorator uses SIGALRM on Unix systems, which only works in the main thread.
71
- \tOn Windows or in non-main threads, it will fall back to a polling-based approach.
72
-
73
- \tArgs:
74
- \t\tfunc\t\t(Callable[..., Any] | None):\tFunction to apply timeout to
75
- \t\tseconds\t\t(float):\t\t\t\t\t\tTimeout duration in seconds (default: 60.0)
76
- \t\tmessage\t\t(str):\t\t\t\t\t\t\tCustom timeout message (default: "Function \'{func_name}\' timed out after {seconds} seconds")
77
-
78
- \tReturns:
79
- \t\tCallable[..., Any]: Decorator that enforces timeout on the function
80
-
81
- \tRaises:
82
- \t\tTimeoutError: If the function execution exceeds the timeout duration
83
-
84
- \tExamples:
85
- \t\t>>> @timeout(seconds=2.0)
86
- \t\t... def slow_function():
87
- \t\t... time.sleep(5)
88
- \t\t>>> slow_function() # Raises TimeoutError after 2 seconds
89
- \t\tTraceback (most recent call last):
90
- \t\t\t...
91
- \t\tTimeoutError: Function \'slow_function\' timed out after 2.0 seconds
92
-
93
- \t\t>>> @timeout(seconds=1.0, message="Custom timeout message")
94
- \t\t... def another_slow_function():
95
- \t\t... time.sleep(3)
96
- \t\t>>> another_slow_function() # Raises TimeoutError after 1 second
97
- \t\tTraceback (most recent call last):
98
- \t\t\t...
99
- \t\tTimeoutError: Custom timeout message
100
- \t'''
101
- def retry(func: Callable[..., Any] | None = None, *, exceptions: tuple[type[BaseException], ...] | type[BaseException] = ..., max_attempts: int = 10, delay: float = 1.0, backoff: float = 1.0, message: str = '') -> Callable[..., Any]:
102
- ''' Decorator that retries a function when specific exceptions are raised.
103
-
104
- \tArgs:
105
- \t\tfunc\t\t\t(Callable[..., Any] | None):\t\tFunction to retry
106
- \t\texceptions\t\t(tuple[type[BaseException], ...]):\tExceptions to catch and retry on
107
- \t\tmax_attempts\t(int | None):\t\t\t\t\t\tMaximum number of attempts (None for infinite retries)
108
- \t\tdelay\t\t\t(float):\t\t\t\t\t\t\tInitial delay in seconds between retries (default: 1.0)
109
- \t\tbackoff\t\t\t(float):\t\t\t\t\t\t\tMultiplier for delay after each retry (default: 1.0 for constant delay)
110
- \t\tmessage\t\t\t(str):\t\t\t\t\t\t\t\tCustom message to display before ", retrying" (default: "{ExceptionName} encountered while running {func_name}")
111
-
112
- \tReturns:
113
- \t\tCallable[..., Any]: Decorator that retries the function on specified exceptions
114
-
115
- \tExamples:
116
- \t\t>>> import os
117
- \t\t>>> @retry(exceptions=PermissionError, max_attempts=3, delay=0.1)
118
- \t\t... def write_file():
119
- \t\t... with open("test.txt", "w") as f:
120
- \t\t... f.write("test")
121
-
122
- \t\t>>> @retry(exceptions=(OSError, IOError), delay=0.5, backoff=2.0)
123
- \t\t... def network_call():
124
- \t\t... pass
125
-
126
- \t\t>>> @retry(max_attempts=5, delay=1.0)
127
- \t\t... def might_fail():
128
- \t\t... pass
129
- \t'''
130
- def simple_cache(func: Callable[..., Any] | None = None, *, method: Literal['str', 'pickle'] = 'str') -> Callable[..., Any]:
131
- ''' Decorator that caches the result of a function based on its arguments.
132
-
133
- \tThe str method is often faster than the pickle method (by a little) but not as accurate with complex objects.
134
-
135
- \tArgs:
136
- \t\tfunc (Callable[..., Any] | None): Function to cache
137
- \t\tmethod (Literal["str", "pickle"]): The method to use for caching.
138
- \tReturns:
139
- \t\tCallable[..., Any]: A decorator that caches the result of a function.
140
- \tExamples:
141
- \t\t>>> @simple_cache
142
- \t\t... def test1(a: int, b: int) -> int:
143
- \t\t... return a + b
144
-
145
- \t\t>>> @simple_cache(method="str")
146
- \t\t... def test2(a: int, b: int) -> int:
147
- \t\t... return a + b
148
- \t\t>>> test2(1, 2)
149
- \t\t3
150
- \t\t>>> test2(1, 2)
151
- \t\t3
152
- \t\t>>> test2(3, 4)
153
- \t\t7
154
- \t'''
155
- def abstract(func: Callable[..., Any] | None = None, *, error_log: LogLevels = ...) -> Callable[..., Any]:
156
- """ Decorator that marks a function as abstract.
157
-
158
- \tContrary to the abstractmethod decorator from the abc module that raises a TypeError
159
- \twhen you try to instantiate a class that has abstract methods, this decorator raises
160
- \ta NotImplementedError ONLY when the decorated function is called, indicating that the function
161
- \tmust be implemented by a subclass.
162
-
163
- \tArgs:
164
- \t\tfunc (Callable[..., Any] | None): The function to mark as abstract
165
- \t\terror_log (LogLevels): Log level for the error handling
166
- \t\t\tLogLevels.NONE: None
167
- \t\t\tLogLevels.WARNING: Show as warning
168
- \t\t\tLogLevels.WARNING_TRACEBACK: Show as warning with traceback
169
- \t\t\tLogLevels.ERROR_TRACEBACK: Show as error with traceback
170
- \t\t\tLogLevels.RAISE_EXCEPTION: Raise exception
171
-
172
- \tReturns:
173
- \t\tCallable[..., Any]: Decorator that raises NotImplementedError when called
174
-
175
- \tExamples:
176
- \t\t>>> class Base:
177
- \t\t... @abstract
178
- \t\t... def method(self):
179
- \t\t... pass
180
- \t\t>>> Base().method()
181
- \t\tTraceback (most recent call last):
182
- \t\t\t...
183
- \t\tNotImplementedError: Function 'method' is abstract and must be implemented by a subclass
184
- \t"""
185
- def deprecated(func: Callable[..., Any] | None = None, *, message: str = '', version: str = '', error_log: LogLevels = ...) -> Callable[..., Any]:
186
- ''' Decorator that marks a function as deprecated.
187
-
188
- \tArgs:
189
- \t\tfunc (Callable[..., Any] | None): Function to mark as deprecated
190
- \t\tmessage (str): Additional message to display with the deprecation warning
191
- \t\tversion (str): Version since when the function is deprecated (e.g. "v1.2.0")
192
- \t\terror_log (LogLevels): Log level for the deprecation warning
193
- \t\t\tLogLevels.NONE: None
194
- \t\t\tLogLevels.WARNING: Show as warning
195
- \t\t\tLogLevels.WARNING_TRACEBACK: Show as warning with traceback
196
- \t\t\tLogLevels.ERROR_TRACEBACK: Show as error with traceback
197
- \t\t\tLogLevels.RAISE_EXCEPTION: Raise exception
198
- \tReturns:
199
- \t\tCallable[..., Any]: Decorator that marks a function as deprecated
200
-
201
- \tExamples:
202
- \t\t>>> @deprecated
203
- \t\t... def old_function():
204
- \t\t... pass
205
-
206
- \t\t>>> @deprecated(message="Use \'new_function()\' instead", error_log=LogLevels.WARNING)
207
- \t\t... def another_old_function():
208
- \t\t... pass
209
- \t'''
210
- def silent(func: Callable[..., Any] | None = None, *, mute_stderr: bool = False) -> Callable[..., Any]:
211
- ''' Decorator that makes a function silent (disable stdout, and stderr if specified).
212
-
213
- \tAlternative to stouputils.ctx.Muffle.
214
-
215
- \tArgs:
216
- \t\tfunc\t\t\t(Callable[..., Any] | None):\tFunction to make silent
217
- \t\tmute_stderr\t\t(bool):\t\t\t\t\t\t\tWhether to mute stderr or not
218
-
219
- \tExamples:
220
- \t\t>>> @silent
221
- \t\t... def test():
222
- \t\t... print("Hello, world!")
223
- \t\t>>> test()
224
-
225
- \t\t>>> @silent(mute_stderr=True)
226
- \t\t... def test2():
227
- \t\t... print("Hello, world!")
228
- \t\t>>> test2()
229
-
230
- \t\t>>> silent(print)("Hello, world!")
231
- \t'''
232
- def _get_func_name(func: Callable[..., Any]) -> str:
233
- ''' Get the name of a function, returns "<unknown>" if the name cannot be retrieved. '''
234
- def _get_wrapper_name(decorator_name: str, func: Callable[..., Any]) -> str:
235
- ''' Get a descriptive name for a wrapper function.
236
-
237
- \tArgs:
238
- \t\tdecorator_name\t(str):\t\t\t\t\tName of the decorator
239
- \t\tfunc\t\t\t(Callable[..., Any]):\tFunction being decorated
240
- \tReturns:
241
- \t\tstr: Combined name for the wrapper function (e.g., "stouputils.decorators.handle_error@function_name")
242
- \t'''
@@ -1,211 +0,0 @@
1
- from .ctx import SetMPStartMethod as SetMPStartMethod
2
- from .print import BAR_FORMAT as BAR_FORMAT, MAGENTA as MAGENTA
3
- from collections.abc import Callable, Iterable
4
- from typing import Any, TypeVar
5
-
6
- def doctest_square(x: int) -> int: ...
7
- def doctest_slow(x: int) -> int: ...
8
-
9
- CPU_COUNT: int
10
- T = TypeVar('T')
11
- R = TypeVar('R')
12
-
13
- def multiprocessing[T, R](func: Callable[..., R] | list[Callable[..., R]], args: Iterable[T], use_starmap: bool = False, chunksize: int = 1, desc: str = '', max_workers: int | float = ..., delay_first_calls: float = 0, color: str = ..., bar_format: str = ..., ascii: bool = False) -> list[R]:
14
- ''' Method to execute a function in parallel using multiprocessing
15
-
16
- \t- For CPU-bound operations where the GIL (Global Interpreter Lock) is a bottleneck.
17
- \t- When the task can be divided into smaller, independent sub-tasks that can be executed concurrently.
18
- \t- For computationally intensive tasks like scientific simulations, data analysis, or machine learning workloads.
19
-
20
- \tArgs:
21
- \t\tfunc\t\t\t\t(Callable | list[Callable]):\tFunction to execute, or list of functions (one per argument)
22
- \t\targs\t\t\t\t(Iterable):\t\t\tIterable of arguments to pass to the function(s)
23
- \t\tuse_starmap\t\t\t(bool):\t\t\t\tWhether to use starmap or not (Defaults to False):
24
- \t\t\tTrue means the function will be called like func(\\*args[i]) instead of func(args[i])
25
- \t\tchunksize\t\t\t(int):\t\t\t\tNumber of arguments to process at a time
26
- \t\t\t(Defaults to 1 for proper progress bar display)
27
- \t\tdesc\t\t\t\t(str):\t\t\t\tDescription displayed in the progress bar
28
- \t\t\t(if not provided no progress bar will be displayed)
29
- \t\tmax_workers\t\t\t(int | float):\t\tNumber of workers to use (Defaults to CPU_COUNT), -1 means CPU_COUNT.
30
- \t\t\tIf float between 0 and 1, it\'s treated as a percentage of CPU_COUNT.
31
- \t\t\tIf negative float between -1 and 0, it\'s treated as a percentage of len(args).
32
- \t\tdelay_first_calls\t(float):\t\t\tApply i*delay_first_calls seconds delay to the first "max_workers" calls.
33
- \t\t\tFor instance, the first process will be delayed by 0 seconds, the second by 1 second, etc.
34
- \t\t\t(Defaults to 0): This can be useful to avoid functions being called in the same second.
35
- \t\tcolor\t\t\t\t(str):\t\t\t\tColor of the progress bar (Defaults to MAGENTA)
36
- \t\tbar_format\t\t\t(str):\t\t\t\tFormat of the progress bar (Defaults to BAR_FORMAT)
37
- \t\tascii\t\t\t\t(bool):\t\t\t\tWhether to use ASCII or Unicode characters for the progress bar
38
-
39
- \tReturns:
40
- \t\tlist[object]:\tResults of the function execution
41
-
42
- \tExamples:
43
- \t\t.. code-block:: python
44
-
45
- \t\t\t> multiprocessing(doctest_square, args=[1, 2, 3])
46
- \t\t\t[1, 4, 9]
47
-
48
- \t\t\t> multiprocessing(int.__mul__, [(1,2), (3,4), (5,6)], use_starmap=True)
49
- \t\t\t[2, 12, 30]
50
-
51
- \t\t\t> # Using a list of functions (one per argument)
52
- \t\t\t> multiprocessing([doctest_square, doctest_square, doctest_square], [1, 2, 3])
53
- \t\t\t[1, 4, 9]
54
-
55
- \t\t\t> # Will process in parallel with progress bar
56
- \t\t\t> multiprocessing(doctest_slow, range(10), desc="Processing")
57
- \t\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
58
-
59
- \t\t\t> # Will process in parallel with progress bar and delay the first threads
60
- \t\t\t> multiprocessing(
61
- \t\t\t. doctest_slow,
62
- \t\t\t. range(10),
63
- \t\t\t. desc="Processing with delay",
64
- \t\t\t. max_workers=2,
65
- \t\t\t. delay_first_calls=0.6
66
- \t\t\t. )
67
- \t\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
68
- \t'''
69
- def multithreading[T, R](func: Callable[..., R] | list[Callable[..., R]], args: Iterable[T], use_starmap: bool = False, desc: str = '', max_workers: int | float = ..., delay_first_calls: float = 0, color: str = ..., bar_format: str = ..., ascii: bool = False) -> list[R]:
70
- ''' Method to execute a function in parallel using multithreading, you should use it:
71
-
72
- \t- For I/O-bound operations where the GIL is not a bottleneck, such as network requests or disk operations.
73
- \t- When the task involves waiting for external resources, such as network responses or user input.
74
- \t- For operations that involve a lot of waiting, such as GUI event handling or handling user input.
75
-
76
- \tArgs:
77
- \t\tfunc\t\t\t\t(Callable | list[Callable]):\tFunction to execute, or list of functions (one per argument)
78
- \t\targs\t\t\t\t(Iterable):\t\t\tIterable of arguments to pass to the function(s)
79
- \t\tuse_starmap\t\t\t(bool):\t\t\t\tWhether to use starmap or not (Defaults to False):
80
- \t\t\tTrue means the function will be called like func(\\*args[i]) instead of func(args[i])
81
- \t\tdesc\t\t\t\t(str):\t\t\t\tDescription displayed in the progress bar
82
- \t\t\t(if not provided no progress bar will be displayed)
83
- \t\tmax_workers\t\t\t(int | float):\t\tNumber of workers to use (Defaults to CPU_COUNT), -1 means CPU_COUNT.
84
- \t\t\tIf float between 0 and 1, it\'s treated as a percentage of CPU_COUNT.
85
- \t\t\tIf negative float between -1 and 0, it\'s treated as a percentage of len(args).
86
- \t\tdelay_first_calls\t(float):\t\t\tApply i*delay_first_calls seconds delay to the first "max_workers" calls.
87
- \t\t\tFor instance with value to 1, the first thread will be delayed by 0 seconds, the second by 1 second, etc.
88
- \t\t\t(Defaults to 0): This can be useful to avoid functions being called in the same second.
89
- \t\tcolor\t\t\t\t(str):\t\t\t\tColor of the progress bar (Defaults to MAGENTA)
90
- \t\tbar_format\t\t\t(str):\t\t\t\tFormat of the progress bar (Defaults to BAR_FORMAT)
91
- \t\tascii\t\t\t\t(bool):\t\t\t\tWhether to use ASCII or Unicode characters for the progress bar
92
-
93
- \tReturns:
94
- \t\tlist[object]:\tResults of the function execution
95
-
96
- \tExamples:
97
- \t\t.. code-block:: python
98
-
99
- \t\t\t> multithreading(doctest_square, args=[1, 2, 3])
100
- \t\t\t[1, 4, 9]
101
-
102
- \t\t\t> multithreading(int.__mul__, [(1,2), (3,4), (5,6)], use_starmap=True)
103
- \t\t\t[2, 12, 30]
104
-
105
- \t\t\t> # Using a list of functions (one per argument)
106
- \t\t\t> multithreading([doctest_square, doctest_square, doctest_square], [1, 2, 3])
107
- \t\t\t[1, 4, 9]
108
-
109
- \t\t\t> # Will process in parallel with progress bar
110
- \t\t\t> multithreading(doctest_slow, range(10), desc="Threading")
111
- \t\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
112
-
113
- \t\t\t> # Will process in parallel with progress bar and delay the first threads
114
- \t\t\t> multithreading(
115
- \t\t\t. doctest_slow,
116
- \t\t\t. range(10),
117
- \t\t\t. desc="Threading with delay",
118
- \t\t\t. max_workers=2,
119
- \t\t\t. delay_first_calls=0.6
120
- \t\t\t. )
121
- \t\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
122
- \t'''
123
- def run_in_subprocess[R](func: Callable[..., R], *args: Any, timeout: float | None = None, **kwargs: Any) -> R:
124
- ''' Execute a function in a subprocess with positional and keyword arguments.
125
-
126
- \tThis is useful when you need to run a function in isolation to avoid memory leaks,
127
- \tresource conflicts, or to ensure a clean execution environment. The subprocess will
128
- \tbe created, run the function with the provided arguments, and return the result.
129
-
130
- \tArgs:
131
- \t\tfunc (Callable): The function to execute in a subprocess.
132
- \t\t\t(SHOULD BE A TOP-LEVEL FUNCTION TO BE PICKLABLE)
133
- \t\t*args (Any): Positional arguments to pass to the function.
134
- \t\ttimeout (float | None): Maximum time in seconds to wait for the subprocess.
135
- \t\t\tIf None, wait indefinitely. If the subprocess exceeds this time, it will be terminated.
136
- \t\t**kwargs (Any): Keyword arguments to pass to the function.
137
-
138
- \tReturns:
139
- \t\tR: The return value of the function.
140
-
141
- \tRaises:
142
- \t\tRuntimeError: If the subprocess exits with a non-zero exit code or times out.
143
- \t\tTimeoutError: If the subprocess exceeds the specified timeout.
144
-
145
- \tExamples:
146
- \t\t.. code-block:: python
147
-
148
- \t\t\t> # Simple function execution
149
- \t\t\t> run_in_subprocess(doctest_square, 5)
150
- \t\t\t25
151
-
152
- \t\t\t> # Function with multiple arguments
153
- \t\t\t> def add(a: int, b: int) -> int:
154
- \t\t\t. return a + b
155
- \t\t\t> run_in_subprocess(add, 10, 20)
156
- \t\t\t30
157
-
158
- \t\t\t> # Function with keyword arguments
159
- \t\t\t> def greet(name: str, greeting: str = "Hello") -> str:
160
- \t\t\t. return f"{greeting}, {name}!"
161
- \t\t\t> run_in_subprocess(greet, "World", greeting="Hi")
162
- \t\t\t\'Hi, World!\'
163
-
164
- \t\t\t> # With timeout to prevent hanging
165
- \t\t\t> run_in_subprocess(some_gpu_func, data, timeout=300.0)
166
- \t'''
167
- def _subprocess_wrapper[R](result_queue: Any, func: Callable[..., R], args: tuple[Any, ...], kwargs: dict[str, Any]) -> None:
168
- """ Wrapper function to execute the target function and store the result in the queue.
169
-
170
- \tMust be at module level to be pickable on Windows (spawn context).
171
-
172
- \tArgs:
173
- \t\tresult_queue (multiprocessing.Queue): Queue to store the result or exception.
174
- \t\tfunc (Callable): The target function to execute.
175
- \t\targs (tuple): Positional arguments for the function.
176
- \t\tkwargs (dict): Keyword arguments for the function.
177
- \t"""
178
- def _starmap[T, R](args: tuple[Callable[[T], R], list[T]]) -> R:
179
- """ Private function to use starmap using args[0](\\*args[1])
180
-
181
- \tArgs:
182
- \t\targs (tuple): Tuple containing the function and the arguments list to pass to the function
183
- \tReturns:
184
- \t\tobject: Result of the function execution
185
- \t"""
186
- def _delayed_call[T, R](args: tuple[Callable[[T], R], float, T]) -> R:
187
- """ Private function to apply delay before calling the target function
188
-
189
- \tArgs:
190
- \t\targs (tuple): Tuple containing the function, delay in seconds, and the argument to pass to the function
191
- \tReturns:
192
- \t\tobject: Result of the function execution
193
- \t"""
194
- def _handle_parameters[T, R](func: Callable[[T], R] | list[Callable[[T], R]], args: list[T], use_starmap: bool, delay_first_calls: float, max_workers: int, desc: str, color: str) -> tuple[str, Callable[[T], R], list[T]]:
195
- ''' Private function to handle the parameters for multiprocessing or multithreading functions
196
-
197
- \tArgs:
198
- \t\tfunc\t\t\t\t(Callable | list[Callable]):\tFunction to execute, or list of functions (one per argument)
199
- \t\targs\t\t\t\t(list):\t\t\t\tList of arguments to pass to the function(s)
200
- \t\tuse_starmap\t\t\t(bool):\t\t\t\tWhether to use starmap or not (Defaults to False):
201
- \t\t\tTrue means the function will be called like func(\\*args[i]) instead of func(args[i])
202
- \t\tdelay_first_calls\t(int):\t\t\t\tApply i*delay_first_calls seconds delay to the first "max_workers" calls.
203
- \t\t\tFor instance, the first process will be delayed by 0 seconds, the second by 1 second, etc. (Defaults to 0):
204
- \t\t\tThis can be useful to avoid functions being called in the same second.
205
- \t\tmax_workers\t\t\t(int):\t\t\t\tNumber of workers to use (Defaults to CPU_COUNT)
206
- \t\tdesc\t\t\t\t(str):\t\t\t\tDescription of the function execution displayed in the progress bar
207
- \t\tcolor\t\t\t\t(str):\t\t\t\tColor of the progress bar
208
-
209
- \tReturns:
210
- \t\ttuple[str, Callable[[T], R], list[T]]:\tTuple containing the description, function, and arguments
211
- \t'''
@@ -1,136 +0,0 @@
1
- from collections.abc import Callable as Callable, Iterable, Iterator
2
- from typing import Any, IO, TextIO, TypeVar
3
-
4
- RESET: str
5
- RED: str
6
- GREEN: str
7
- YELLOW: str
8
- BLUE: str
9
- MAGENTA: str
10
- CYAN: str
11
- LINE_UP: str
12
- BAR_FORMAT: str
13
- T = TypeVar('T')
14
- previous_args_kwards: tuple[Any, Any]
15
- nb_values: int
16
- import_time: float
17
-
18
- def colored_for_loop[T](iterable: Iterable[T], desc: str = 'Processing', color: str = ..., bar_format: str = ..., ascii: bool = False, **kwargs: Any) -> Iterator[T]:
19
- ''' Function to iterate over a list with a colored TQDM progress bar like the other functions in this module.
20
-
21
- \tArgs:
22
- \t\titerable\t(Iterable):\t\t\tList to iterate over
23
- \t\tdesc\t\t(str):\t\t\t\tDescription of the function execution displayed in the progress bar
24
- \t\tcolor\t\t(str):\t\t\t\tColor of the progress bar (Defaults to MAGENTA)
25
- \t\tbar_format\t(str):\t\t\t\tFormat of the progress bar (Defaults to BAR_FORMAT)
26
- \t\tascii\t\t(bool):\t\t\t\tWhether to use ASCII or Unicode characters for the progress bar (Defaults to False)
27
- \t\tverbose\t\t(int):\t\t\t\tLevel of verbosity, decrease by 1 for each depth (Defaults to 1)
28
- \t\t**kwargs:\t\t\t\t\t\tAdditional arguments to pass to the TQDM progress bar
29
-
30
- \tYields:
31
- \t\tT: Each item of the iterable
32
-
33
- \tExamples:
34
- \t\t>>> for i in colored_for_loop(range(10), desc="Time sleeping loop"):
35
- \t\t... time.sleep(0.01)
36
- \t\t>>> # Time sleeping loop: 100%|██████████████████| 10/10 [ 95.72it/s, 00:00<00:00]
37
- \t'''
38
- def info(*values: Any, color: str = ..., text: str = 'INFO ', prefix: str = '', file: TextIO | list[TextIO] | None = None, **print_kwargs: Any) -> None:
39
- ''' Print an information message looking like "[INFO HH:MM:SS] message" in green by default.
40
-
41
- \tArgs:
42
- \t\tvalues\t\t\t(Any):\t\t\t\t\tValues to print (like the print function)
43
- \t\tcolor\t\t\t(str):\t\t\t\t\tColor of the message (default: GREEN)
44
- \t\ttext\t\t\t(str):\t\t\t\t\tText of the message (default: "INFO ")
45
- \t\tprefix\t\t\t(str):\t\t\t\t\tPrefix to add to the values
46
- \t\tfile\t\t\t(TextIO|list[TextIO]):\tFile(s) to write the message to (default: sys.stdout)
47
- \t\tprint_kwargs\t(dict):\t\t\t\t\tKeyword arguments to pass to the print function
48
- \t'''
49
- def debug(*values: Any, **print_kwargs: Any) -> None:
50
- ''' Print a debug message looking like "[DEBUG HH:MM:SS] message" in cyan by default. '''
51
- def alt_debug(*values: Any, **print_kwargs: Any) -> None:
52
- ''' Print a debug message looking like "[DEBUG HH:MM:SS] message" in blue by default. '''
53
- def suggestion(*values: Any, **print_kwargs: Any) -> None:
54
- ''' Print a suggestion message looking like "[SUGGESTION HH:MM:SS] message" in cyan by default. '''
55
- def progress(*values: Any, **print_kwargs: Any) -> None:
56
- ''' Print a progress message looking like "[PROGRESS HH:MM:SS] message" in magenta by default. '''
57
- def warning(*values: Any, **print_kwargs: Any) -> None:
58
- ''' Print a warning message looking like "[WARNING HH:MM:SS] message" in yellow by default and in sys.stderr. '''
59
- def error(*values: Any, exit: bool = False, **print_kwargs: Any) -> None:
60
- """ Print an error message (in sys.stderr and in red by default)
61
- \tand optionally ask the user to continue or stop the program.
62
-
63
- \tArgs:
64
- \t\tvalues\t\t\t(Any):\t\tValues to print (like the print function)
65
- \t\texit\t\t\t(bool):\t\tWhether to ask the user to continue or stop the program,
66
- \t\t\tfalse to ignore the error automatically and continue
67
- \t\tprint_kwargs\t(dict):\t\tKeyword arguments to pass to the print function
68
- \t"""
69
- def whatisit(*values: Any, print_function: Callable[..., None] = ..., max_length: int = 250, color: str = ..., **print_kwargs: Any) -> None:
70
- ''' Print the type of each value and the value itself, with its id and length/shape.
71
-
72
- \tThe output format is: "type, <id id_number>:\t(length/shape) value"
73
-
74
- \tArgs:
75
- \t\tvalues\t\t\t(Any):\t\tValues to print
76
- \t\tprint_function\t(Callable):\tFunction to use to print the values (default: debug())
77
- \t\tmax_length\t\t(int):\t\tMaximum length of the value string to print (default: 250)
78
- \t\tcolor\t\t\t(str):\t\tColor of the message (default: CYAN)
79
- \t\tprint_kwargs\t(dict):\t\tKeyword arguments to pass to the print function
80
- \t'''
81
- def breakpoint(*values: Any, print_function: Callable[..., None] = ..., **print_kwargs: Any) -> None:
82
- """ Breakpoint function, pause the program and print the values.
83
-
84
- \tArgs:
85
- \t\tvalues\t\t\t(Any):\t\tValues to print
86
- \t\tprint_function\t(Callable):\tFunction to use to print the values (default: warning())
87
- \t\tprint_kwargs\t(dict):\t\tKeyword arguments to pass to the print function
88
- \t"""
89
-
90
- class TeeMultiOutput:
91
- ''' File-like object that duplicates output to multiple file-like objects.
92
-
93
- \tArgs:
94
- \t\t*files (IO[Any]): One or more file-like objects that have write and flush methods
95
- \t\tstrip_colors (bool): Strip ANSI color codes from output sent to non-stdout/stderr files
96
- \t\tascii_only (bool): Replace non-ASCII characters with their ASCII equivalents for non-stdout/stderr files
97
- \t\tignore_lineup (bool): Ignore lines containing LINE_UP escape sequence in non-terminal outputs
98
-
99
- \tExamples:
100
- \t\t>>> f = open("logfile.txt", "w")
101
- \t\t>>> sys.stdout = TeeMultiOutput(sys.stdout, f)
102
- \t\t>>> print("Hello World") # Output goes to both console and file
103
- \t\tHello World
104
- \t\t>>> f.close()\t# TeeMultiOutput will handle any future writes to closed files gracefully
105
- \t'''
106
- files: tuple[IO[Any], ...]
107
- strip_colors: bool
108
- ascii_only: bool
109
- ignore_lineup: bool
110
- def __init__(self, *files: IO[Any], strip_colors: bool = True, ascii_only: bool = True, ignore_lineup: bool = True) -> None: ...
111
- @property
112
- def encoding(self) -> str:
113
- ''' Get the encoding of the first file, or "utf-8" as fallback.
114
-
115
- \t\tReturns:
116
- \t\t\tstr: The encoding, ex: "utf-8", "ascii", "latin1", etc.
117
- \t\t'''
118
- def write(self, obj: str) -> int:
119
- """ Write the object to all files while stripping colors if needed.
120
-
121
- \t\tArgs:
122
- \t\t\tobj (str): String to write
123
- \t\tReturns:
124
- \t\t\tint: Number of characters written to the first file
125
- \t\t"""
126
- def flush(self) -> None:
127
- """ Flush all files. """
128
- def fileno(self) -> int:
129
- """ Return the file descriptor of the first file. """
130
-
131
- def remove_colors(text: str) -> str:
132
- """ Remove the colors from a text """
133
- def is_same_print(*args: Any, **kwargs: Any) -> bool:
134
- """ Checks if the current print call is the same as the previous one. """
135
- def current_time() -> str:
136
- ''' Get the current time as "HH:MM:SS" if less than 24 hours since import, else "YYYY-MM-DD HH:MM:SS" '''