stouputils 1.2.12__tar.gz → 1.2.14__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.
- {stouputils-1.2.12 → stouputils-1.2.14}/PKG-INFO +1 -1
- {stouputils-1.2.12 → stouputils-1.2.14}/pyproject.toml +1 -1
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/__init__.py +1 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/all_doctests.py +11 -2
- stouputils-1.2.14/stouputils/image.py +70 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/.gitignore +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/LICENSE +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/README.md +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/applications/__init__.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/applications/automatic_docs.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/archive.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/backup.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/collections.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/continuous_delivery/__init__.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/continuous_delivery/cd_utils.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/continuous_delivery/github.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/continuous_delivery/pypi.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/continuous_delivery/pyproject.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/ctx.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/decorators.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/dont_look/zip_file_override.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/io.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/parallel.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/print.py +0 -0
- {stouputils-1.2.12 → stouputils-1.2.14}/stouputils/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stouputils
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.14
|
|
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
|
Project-URL: Homepage, https://github.com/Stoupy51/stouputils
|
|
6
6
|
Project-URL: Issues, https://github.com/Stoupy51/stouputils/issues
|
|
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "stouputils"
|
|
8
|
-
version = "1.2.
|
|
8
|
+
version = "1.2.14"
|
|
9
9
|
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."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.10"
|
|
@@ -23,7 +23,7 @@ def test_module_with_progress(module: ModuleType, separator: str) -> TestResults
|
|
|
23
23
|
return internal()
|
|
24
24
|
|
|
25
25
|
# Main program
|
|
26
|
-
def launch_tests(root_dir: str, importing_errors: LogLevels = LogLevels.WARNING_TRACEBACK, strict: bool = True) ->
|
|
26
|
+
def launch_tests(root_dir: str, importing_errors: LogLevels = LogLevels.WARNING_TRACEBACK, strict: bool = True) -> int:
|
|
27
27
|
""" Main function to launch tests for all modules in the given directory.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
@@ -31,6 +31,9 @@ def launch_tests(root_dir: str, importing_errors: LogLevels = LogLevels.WARNING_
|
|
|
31
31
|
importing_errors (LogLevels): Log level for the errors when importing modules
|
|
32
32
|
strict (bool): Modify the force_raise_exception variable to True in the decorators module
|
|
33
33
|
|
|
34
|
+
Returns:
|
|
35
|
+
int: The number of failed tests
|
|
36
|
+
|
|
34
37
|
Examples:
|
|
35
38
|
>>> launch_tests("unknown_dir")
|
|
36
39
|
Traceback (most recent call last):
|
|
@@ -39,7 +42,8 @@ def launch_tests(root_dir: str, importing_errors: LogLevels = LogLevels.WARNING_
|
|
|
39
42
|
|
|
40
43
|
.. code-block:: python
|
|
41
44
|
|
|
42
|
-
> launch_tests("/path/to/source")
|
|
45
|
+
> if launch_tests("/path/to/source") > 0:
|
|
46
|
+
sys.exit(1)
|
|
43
47
|
[PROGRESS HH:MM:SS] Importing module 'module1' took 0.001s
|
|
44
48
|
[PROGRESS HH:MM:SS] Importing module 'module2' took 0.002s
|
|
45
49
|
[PROGRESS HH:MM:SS] Importing module 'module3' took 0.003s
|
|
@@ -89,10 +93,15 @@ def launch_tests(root_dir: str, importing_errors: LogLevels = LogLevels.WARNING_
|
|
|
89
93
|
results: list[TestResults] = [test_module_with_progress(module, separator) for module, separator in zip(modules, separators)]
|
|
90
94
|
|
|
91
95
|
# Display any error lines for each module at the end of the script
|
|
96
|
+
nb_failed_tests: int = 0
|
|
92
97
|
for module, result in zip(modules, results):
|
|
93
98
|
if result.failed > 0:
|
|
94
99
|
error(f"Errors in module {module.__name__}", exit=False)
|
|
100
|
+
nb_failed_tests += result.failed
|
|
95
101
|
|
|
96
102
|
# Reset force_raise_exception back
|
|
97
103
|
decorators.force_raise_exception = strict
|
|
98
104
|
|
|
105
|
+
# Return the number of failed tests
|
|
106
|
+
return nb_failed_tests
|
|
107
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
# Imports
|
|
3
|
+
from PIL import Image
|
|
4
|
+
from typing import Callable
|
|
5
|
+
from numpy.typing import NDArray
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Functions
|
|
10
|
+
def image_resize(
|
|
11
|
+
image: Image.Image | NDArray[np.uint8],
|
|
12
|
+
max_result_size: int,
|
|
13
|
+
resampling: Image.Resampling = Image.Resampling.LANCZOS,
|
|
14
|
+
min_or_max: Callable[[int, int], int] = max,
|
|
15
|
+
return_type: type[Image.Image | NDArray[np.uint8]] = Image.Image,
|
|
16
|
+
) -> Image.Image | NDArray[np.uint8]:
|
|
17
|
+
""" Resize an image while preserving its aspect ratio.
|
|
18
|
+
Scales the image so that its largest dimension equals max_result_size.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
image (Image.Image | np.ndarray): The image to resize.
|
|
22
|
+
max_result_size (int): Maximum size for the largest dimension.
|
|
23
|
+
resampling (Image.Resampling): PIL resampling filter to use.
|
|
24
|
+
min_or_max (Callable): Function to use to get the minimum or maximum of the two ratios.
|
|
25
|
+
return_type (type): Type of the return value (Image.Image or np.ndarray).
|
|
26
|
+
Returns:
|
|
27
|
+
Image.Image: The resized image with preserved aspect ratio.
|
|
28
|
+
Examples:
|
|
29
|
+
>>> # Test with (height x width x channels) numpy array
|
|
30
|
+
>>> import numpy as np
|
|
31
|
+
>>> array: np.ndarray = np.random.randint(0, 255, (100, 50, 3), dtype=np.uint8)
|
|
32
|
+
>>> image_resize(array, 100).size
|
|
33
|
+
(50, 100)
|
|
34
|
+
>>> image_resize(array, 100, min_or_max=max).size
|
|
35
|
+
(50, 100)
|
|
36
|
+
>>> image_resize(array, 100, min_or_max=min).size
|
|
37
|
+
(100, 200)
|
|
38
|
+
|
|
39
|
+
>>> # Test with PIL Image
|
|
40
|
+
>>> from PIL import Image
|
|
41
|
+
>>> pil_image: Image.Image = Image.new('RGB', (200, 100))
|
|
42
|
+
>>> image_resize(pil_image, 50).size
|
|
43
|
+
(50, 25)
|
|
44
|
+
>>> # Test with different return types
|
|
45
|
+
>>> resized_array = image_resize(array, 50, return_type=np.ndarray)
|
|
46
|
+
>>> isinstance(resized_array, np.ndarray)
|
|
47
|
+
True
|
|
48
|
+
>>> resized_array.shape
|
|
49
|
+
(50, 25, 3)
|
|
50
|
+
>>> # Test with different resampling methods
|
|
51
|
+
>>> image_resize(pil_image, 50, resampling=Image.Resampling.NEAREST).size
|
|
52
|
+
(50, 25)
|
|
53
|
+
"""
|
|
54
|
+
if isinstance(image, np.ndarray):
|
|
55
|
+
image = Image.fromarray(image) # type: ignore
|
|
56
|
+
|
|
57
|
+
width: int = image.size[0]
|
|
58
|
+
height: int = image.size[1]
|
|
59
|
+
max_dimension: int = min_or_max(width, height)
|
|
60
|
+
scale: float = max_result_size / max_dimension
|
|
61
|
+
|
|
62
|
+
new_width: int = int(width * scale)
|
|
63
|
+
new_height: int = int(height * scale)
|
|
64
|
+
new_image: Image.Image = image.resize((new_width, new_height), resampling)
|
|
65
|
+
|
|
66
|
+
if return_type == np.ndarray:
|
|
67
|
+
return np.array(new_image)
|
|
68
|
+
else:
|
|
69
|
+
return new_image
|
|
70
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|