stouputils 1.5.2__tar.gz → 1.5.4__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.5.2 → stouputils-1.5.4}/LICENSE +21 -21
- {stouputils-1.5.2 → stouputils-1.5.4}/PKG-INFO +1 -1
- {stouputils-1.5.2 → stouputils-1.5.4}/pyproject.toml +1 -1
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/continuous_delivery/__init__.py +25 -25
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/continuous_delivery/cd_utils.py +141 -141
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/continuous_delivery/pypi.py +90 -90
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/continuous_delivery/pyproject.py +124 -124
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/ctx.py +286 -286
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/config/set.py +125 -125
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/base_keras.py +765 -765
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/model_checkpoint_v2.py +31 -31
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/__init__.py +18 -18
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/linux.py +144 -144
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/main.py +223 -223
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/windows.py +136 -136
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/print.py +45 -12
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/py.typed +1 -1
- {stouputils-1.5.2 → stouputils-1.5.4}/.gitignore +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/README.md +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/__main__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/all_doctests.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/automatic_docs.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/upscaler/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/upscaler/config.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/upscaler/image.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/applications/upscaler/video.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/archive.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/backup.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/collections.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/continuous_delivery/github.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/config/get.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/auto_contrast.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/axis_flip.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/bias_field_correction.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/binary_threshold.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/blur.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/brightness.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/canny.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/clahe.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/common.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/contrast.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/curvature_flow_filter.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/denoise.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/histogram_equalization.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/invert.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/laplacian.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/median_blur.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/noise.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/normalize.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/random_erase.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/resize.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/rotation.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/salt_pepper.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/sharpening.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/shearing.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/threshold.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/translation.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image/zoom.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image_augmentation.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/image_preprocess.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/prosthesis_detection.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/data_processing/technique.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/dataset.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/dataset_loader.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/grouping_strategy.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/image_loader.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/dataset/xy_tuple.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/metric_dictionnary.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/metric_utils.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/mlflow_utils.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/abstract_model.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/all.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/all.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/convnext.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/densenet.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/efficientnet.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/mobilenet.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/resnet.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/squeezenet.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/vgg.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras/xception.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/colored_progress_bar.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/learning_rate_finder.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/progressive_unfreezing.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/callbacks/warmup_scheduler.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/losses/__init__.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/losses/next_generation_loss.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/keras_utils/visualizations.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/model_interface.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/models/sandbox.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/range_tuple.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/scripts/augment_dataset.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/scripts/exhaustive_process.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/scripts/preprocess_dataset.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/scripts/routine.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/data_science/utils.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/decorators.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/image.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/common.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/installer/downloader.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/io.py +0 -0
- {stouputils-1.5.2 → stouputils-1.5.4}/stouputils/parallel.py +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Alexandre Collignon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alexandre Collignon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stouputils
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.4
|
|
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.5.
|
|
8
|
+
version = "1.5.4"
|
|
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"
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
""" Continuous delivery and deployment utilities.
|
|
2
|
-
|
|
3
|
-
This module provides tools for automating software delivery and deployment:
|
|
4
|
-
|
|
5
|
-
Key Features:
|
|
6
|
-
- GitHub release management and uploads
|
|
7
|
-
- PyPI package publishing utilities
|
|
8
|
-
- pyproject.toml file management
|
|
9
|
-
- Common CD/CI utilities
|
|
10
|
-
|
|
11
|
-
Components:
|
|
12
|
-
- cd_utils: Common utilities for continuous delivery
|
|
13
|
-
- github: GitHub-specific utilities (upload_to_github)
|
|
14
|
-
- pypi: PyPI publishing tools (pypi_full_routine)
|
|
15
|
-
- pyproject: pyproject.toml file management
|
|
16
|
-
|
|
17
|
-
"""
|
|
18
|
-
# ruff: noqa: F403
|
|
19
|
-
|
|
20
|
-
# Imports
|
|
21
|
-
from .cd_utils import *
|
|
22
|
-
from .github import *
|
|
23
|
-
from .pypi import *
|
|
24
|
-
from .pyproject import *
|
|
25
|
-
|
|
1
|
+
""" Continuous delivery and deployment utilities.
|
|
2
|
+
|
|
3
|
+
This module provides tools for automating software delivery and deployment:
|
|
4
|
+
|
|
5
|
+
Key Features:
|
|
6
|
+
- GitHub release management and uploads
|
|
7
|
+
- PyPI package publishing utilities
|
|
8
|
+
- pyproject.toml file management
|
|
9
|
+
- Common CD/CI utilities
|
|
10
|
+
|
|
11
|
+
Components:
|
|
12
|
+
- cd_utils: Common utilities for continuous delivery
|
|
13
|
+
- github: GitHub-specific utilities (upload_to_github)
|
|
14
|
+
- pypi: PyPI publishing tools (pypi_full_routine)
|
|
15
|
+
- pyproject: pyproject.toml file management
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
# ruff: noqa: F403
|
|
19
|
+
|
|
20
|
+
# Imports
|
|
21
|
+
from .cd_utils import *
|
|
22
|
+
from .github import *
|
|
23
|
+
from .pypi import *
|
|
24
|
+
from .pyproject import *
|
|
25
|
+
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
""" This module contains utilities for continuous delivery, such as loading credentials from a file.
|
|
2
|
-
It is mainly used by the `stouputils.continuous_delivery.github` module.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
# Imports
|
|
6
|
-
import os
|
|
7
|
-
from typing import Any
|
|
8
|
-
|
|
9
|
-
import requests
|
|
10
|
-
import yaml
|
|
11
|
-
|
|
12
|
-
from ..decorators import handle_error
|
|
13
|
-
from ..io import clean_path, super_json_load
|
|
14
|
-
from ..print import warning
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# Load credentials from file
|
|
18
|
-
@handle_error()
|
|
19
|
-
def load_credentials(credentials_path: str) -> dict[str, Any]:
|
|
20
|
-
""" Load credentials from a JSON or YAML file into a dictionary.
|
|
21
|
-
|
|
22
|
-
Loads credentials from either a JSON or YAML file and returns them as a dictionary.
|
|
23
|
-
The file must contain the required credentials in the appropriate format.
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
credentials_path (str): Path to the credentials file (.json or .yml)
|
|
27
|
-
Returns:
|
|
28
|
-
dict[str, Any]: Dictionary containing the credentials
|
|
29
|
-
|
|
30
|
-
Example JSON format:
|
|
31
|
-
|
|
32
|
-
.. code-block:: json
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
"github": {
|
|
36
|
-
"username": "Stoupy51",
|
|
37
|
-
"api_key": "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Example YAML format:
|
|
42
|
-
|
|
43
|
-
.. code-block:: yaml
|
|
44
|
-
|
|
45
|
-
github:
|
|
46
|
-
username: "Stoupy51"
|
|
47
|
-
api_key: "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|
48
|
-
"""
|
|
49
|
-
# Get the absolute path of the credentials file
|
|
50
|
-
warning(
|
|
51
|
-
"Be cautious when loading credentials from external sources like this, "
|
|
52
|
-
"as they might contain malicious code that could compromise your credentials without your knowledge"
|
|
53
|
-
)
|
|
54
|
-
credentials_path = clean_path(credentials_path)
|
|
55
|
-
|
|
56
|
-
# Check if the file exists
|
|
57
|
-
if not os.path.exists(credentials_path):
|
|
58
|
-
raise FileNotFoundError(f"Credentials file not found at '{credentials_path}'")
|
|
59
|
-
|
|
60
|
-
# Load the file if it's a JSON file
|
|
61
|
-
if credentials_path.endswith(".json"):
|
|
62
|
-
return super_json_load(credentials_path)
|
|
63
|
-
|
|
64
|
-
# Else, load the file if it's a YAML file
|
|
65
|
-
elif credentials_path.endswith((".yml", ".yaml")):
|
|
66
|
-
with open(credentials_path) as f:
|
|
67
|
-
return yaml.safe_load(f)
|
|
68
|
-
|
|
69
|
-
# Else, raise an error
|
|
70
|
-
else:
|
|
71
|
-
raise ValueError("Credentials file must be .json or .yml format")
|
|
72
|
-
|
|
73
|
-
# Handle a response
|
|
74
|
-
def handle_response(response: requests.Response, error_message: str) -> None:
|
|
75
|
-
""" Handle a response from the API by raising an error if the response is not successful (status code not in 200-299).
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
response (requests.Response): The response from the API
|
|
79
|
-
error_message (str): The error message to raise if the response is not successful
|
|
80
|
-
"""
|
|
81
|
-
if response.status_code < 200 or response.status_code >= 300:
|
|
82
|
-
try:
|
|
83
|
-
raise ValueError(f"{error_message}, response code {response.status_code} with response {response.json()}")
|
|
84
|
-
except requests.exceptions.JSONDecodeError as e:
|
|
85
|
-
raise ValueError(f"{error_message}, response code {response.status_code} with response {response.text}") from e
|
|
86
|
-
|
|
87
|
-
# Clean a version string
|
|
88
|
-
def clean_version(version: str, keep: str = "") -> str:
|
|
89
|
-
""" Clean a version string
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
version (str): The version string to clean
|
|
93
|
-
keep (str): The characters to keep in the version string
|
|
94
|
-
Returns:
|
|
95
|
-
str: The cleaned version string
|
|
96
|
-
|
|
97
|
-
>>> clean_version("v1.e0.zfezf0.1.2.3zefz")
|
|
98
|
-
'1.0.0.1.2.3'
|
|
99
|
-
>>> clean_version("v1.e0.zfezf0.1.2.3zefz", keep="v")
|
|
100
|
-
'v1.0.0.1.2.3'
|
|
101
|
-
>>> clean_version("v1.2.3b", keep="ab")
|
|
102
|
-
'1.2.3b'
|
|
103
|
-
"""
|
|
104
|
-
return "".join(c for c in version if c in "0123456789." + keep)
|
|
105
|
-
|
|
106
|
-
# Convert a version string to a float
|
|
107
|
-
def version_to_float(version: str) -> float:
|
|
108
|
-
""" Converts a version string into a float for comparison purposes.
|
|
109
|
-
The version string is expected to follow the format of major.minor.patch.something_else....,
|
|
110
|
-
where each part is separated by a dot and can be extended indefinitely.
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
version (str): The version string to convert. (e.g. "v1.0.0.1.2.3")
|
|
114
|
-
Returns:
|
|
115
|
-
float: The float representation of the version. (e.g. 0)
|
|
116
|
-
|
|
117
|
-
>>> version_to_float("v1.0.0")
|
|
118
|
-
1.0
|
|
119
|
-
>>> version_to_float("v1.0.0.1")
|
|
120
|
-
1.000000001
|
|
121
|
-
>>> version_to_float("v2.3.7")
|
|
122
|
-
2.003007
|
|
123
|
-
>>> version_to_float("v1.0.0.1.2.3")
|
|
124
|
-
1.0000000010020031
|
|
125
|
-
>>> version_to_float("v2.0") > version_to_float("v1.0.0.1")
|
|
126
|
-
True
|
|
127
|
-
"""
|
|
128
|
-
# Clean the version string by keeping only the numbers and dots
|
|
129
|
-
version = clean_version(version)
|
|
130
|
-
|
|
131
|
-
# Split the version string into parts
|
|
132
|
-
version_parts: list[str] = version.split(".")
|
|
133
|
-
total: float = 0.0
|
|
134
|
-
multiplier: float = 1.0
|
|
135
|
-
|
|
136
|
-
# Iterate over the parts and add lesser and lesser weight to each part
|
|
137
|
-
for part in version_parts:
|
|
138
|
-
total += int(part) * multiplier
|
|
139
|
-
multiplier /= 1_000
|
|
140
|
-
return total
|
|
141
|
-
|
|
1
|
+
""" This module contains utilities for continuous delivery, such as loading credentials from a file.
|
|
2
|
+
It is mainly used by the `stouputils.continuous_delivery.github` module.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Imports
|
|
6
|
+
import os
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
import yaml
|
|
11
|
+
|
|
12
|
+
from ..decorators import handle_error
|
|
13
|
+
from ..io import clean_path, super_json_load
|
|
14
|
+
from ..print import warning
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Load credentials from file
|
|
18
|
+
@handle_error()
|
|
19
|
+
def load_credentials(credentials_path: str) -> dict[str, Any]:
|
|
20
|
+
""" Load credentials from a JSON or YAML file into a dictionary.
|
|
21
|
+
|
|
22
|
+
Loads credentials from either a JSON or YAML file and returns them as a dictionary.
|
|
23
|
+
The file must contain the required credentials in the appropriate format.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
credentials_path (str): Path to the credentials file (.json or .yml)
|
|
27
|
+
Returns:
|
|
28
|
+
dict[str, Any]: Dictionary containing the credentials
|
|
29
|
+
|
|
30
|
+
Example JSON format:
|
|
31
|
+
|
|
32
|
+
.. code-block:: json
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
"github": {
|
|
36
|
+
"username": "Stoupy51",
|
|
37
|
+
"api_key": "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Example YAML format:
|
|
42
|
+
|
|
43
|
+
.. code-block:: yaml
|
|
44
|
+
|
|
45
|
+
github:
|
|
46
|
+
username: "Stoupy51"
|
|
47
|
+
api_key: "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|
48
|
+
"""
|
|
49
|
+
# Get the absolute path of the credentials file
|
|
50
|
+
warning(
|
|
51
|
+
"Be cautious when loading credentials from external sources like this, "
|
|
52
|
+
"as they might contain malicious code that could compromise your credentials without your knowledge"
|
|
53
|
+
)
|
|
54
|
+
credentials_path = clean_path(credentials_path)
|
|
55
|
+
|
|
56
|
+
# Check if the file exists
|
|
57
|
+
if not os.path.exists(credentials_path):
|
|
58
|
+
raise FileNotFoundError(f"Credentials file not found at '{credentials_path}'")
|
|
59
|
+
|
|
60
|
+
# Load the file if it's a JSON file
|
|
61
|
+
if credentials_path.endswith(".json"):
|
|
62
|
+
return super_json_load(credentials_path)
|
|
63
|
+
|
|
64
|
+
# Else, load the file if it's a YAML file
|
|
65
|
+
elif credentials_path.endswith((".yml", ".yaml")):
|
|
66
|
+
with open(credentials_path) as f:
|
|
67
|
+
return yaml.safe_load(f)
|
|
68
|
+
|
|
69
|
+
# Else, raise an error
|
|
70
|
+
else:
|
|
71
|
+
raise ValueError("Credentials file must be .json or .yml format")
|
|
72
|
+
|
|
73
|
+
# Handle a response
|
|
74
|
+
def handle_response(response: requests.Response, error_message: str) -> None:
|
|
75
|
+
""" Handle a response from the API by raising an error if the response is not successful (status code not in 200-299).
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
response (requests.Response): The response from the API
|
|
79
|
+
error_message (str): The error message to raise if the response is not successful
|
|
80
|
+
"""
|
|
81
|
+
if response.status_code < 200 or response.status_code >= 300:
|
|
82
|
+
try:
|
|
83
|
+
raise ValueError(f"{error_message}, response code {response.status_code} with response {response.json()}")
|
|
84
|
+
except requests.exceptions.JSONDecodeError as e:
|
|
85
|
+
raise ValueError(f"{error_message}, response code {response.status_code} with response {response.text}") from e
|
|
86
|
+
|
|
87
|
+
# Clean a version string
|
|
88
|
+
def clean_version(version: str, keep: str = "") -> str:
|
|
89
|
+
""" Clean a version string
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
version (str): The version string to clean
|
|
93
|
+
keep (str): The characters to keep in the version string
|
|
94
|
+
Returns:
|
|
95
|
+
str: The cleaned version string
|
|
96
|
+
|
|
97
|
+
>>> clean_version("v1.e0.zfezf0.1.2.3zefz")
|
|
98
|
+
'1.0.0.1.2.3'
|
|
99
|
+
>>> clean_version("v1.e0.zfezf0.1.2.3zefz", keep="v")
|
|
100
|
+
'v1.0.0.1.2.3'
|
|
101
|
+
>>> clean_version("v1.2.3b", keep="ab")
|
|
102
|
+
'1.2.3b'
|
|
103
|
+
"""
|
|
104
|
+
return "".join(c for c in version if c in "0123456789." + keep)
|
|
105
|
+
|
|
106
|
+
# Convert a version string to a float
|
|
107
|
+
def version_to_float(version: str) -> float:
|
|
108
|
+
""" Converts a version string into a float for comparison purposes.
|
|
109
|
+
The version string is expected to follow the format of major.minor.patch.something_else....,
|
|
110
|
+
where each part is separated by a dot and can be extended indefinitely.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
version (str): The version string to convert. (e.g. "v1.0.0.1.2.3")
|
|
114
|
+
Returns:
|
|
115
|
+
float: The float representation of the version. (e.g. 0)
|
|
116
|
+
|
|
117
|
+
>>> version_to_float("v1.0.0")
|
|
118
|
+
1.0
|
|
119
|
+
>>> version_to_float("v1.0.0.1")
|
|
120
|
+
1.000000001
|
|
121
|
+
>>> version_to_float("v2.3.7")
|
|
122
|
+
2.003007
|
|
123
|
+
>>> version_to_float("v1.0.0.1.2.3")
|
|
124
|
+
1.0000000010020031
|
|
125
|
+
>>> version_to_float("v2.0") > version_to_float("v1.0.0.1")
|
|
126
|
+
True
|
|
127
|
+
"""
|
|
128
|
+
# Clean the version string by keeping only the numbers and dots
|
|
129
|
+
version = clean_version(version)
|
|
130
|
+
|
|
131
|
+
# Split the version string into parts
|
|
132
|
+
version_parts: list[str] = version.split(".")
|
|
133
|
+
total: float = 0.0
|
|
134
|
+
multiplier: float = 1.0
|
|
135
|
+
|
|
136
|
+
# Iterate over the parts and add lesser and lesser weight to each part
|
|
137
|
+
for part in version_parts:
|
|
138
|
+
total += int(part) * multiplier
|
|
139
|
+
multiplier /= 1_000
|
|
140
|
+
return total
|
|
141
|
+
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
""" This module contains utilities for PyPI.
|
|
2
|
-
|
|
3
|
-
- pypi_full_routine: Upload the most recent file(s) to PyPI after updating pip and required packages and building the package
|
|
4
|
-
|
|
5
|
-
.. image:: https://raw.githubusercontent.com/Stoupy51/stouputils/refs/heads/main/assets/continuous_delivery/pypi_module.gif
|
|
6
|
-
:alt: stouputils pypi examples
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
# Imports
|
|
10
|
-
import os
|
|
11
|
-
import sys
|
|
12
|
-
from collections.abc import Callable
|
|
13
|
-
|
|
14
|
-
from ..decorators import LogLevels, handle_error
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def update_pip_and_required_packages() -> int:
|
|
18
|
-
""" Update pip and required packages.
|
|
19
|
-
|
|
20
|
-
Returns:
|
|
21
|
-
int: Return code of the os.system call.
|
|
22
|
-
"""
|
|
23
|
-
return os.system(f"{sys.executable} -m pip install --upgrade pip setuptools build twine pkginfo packaging")
|
|
24
|
-
|
|
25
|
-
def build_package() -> int:
|
|
26
|
-
""" Build the package.
|
|
27
|
-
|
|
28
|
-
Returns:
|
|
29
|
-
int: Return code of the os.system call.
|
|
30
|
-
"""
|
|
31
|
-
return os.system(f"{sys.executable} -m build")
|
|
32
|
-
|
|
33
|
-
def upload_package(repository: str, filepath: str) -> int:
|
|
34
|
-
""" Upload the package to PyPI.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
repository (str): Repository to upload to.
|
|
38
|
-
filepath (str): Path to the file to upload.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
int: Return code of the os.system call.
|
|
42
|
-
"""
|
|
43
|
-
return os.system(f"{sys.executable} -m twine upload --verbose -r {repository} {filepath}")
|
|
44
|
-
|
|
45
|
-
@handle_error(message="Error while doing the pypi full routine", error_log=LogLevels.ERROR_TRACEBACK)
|
|
46
|
-
def pypi_full_routine(
|
|
47
|
-
repository: str,
|
|
48
|
-
dist_directory: str,
|
|
49
|
-
last_files: int = 1,
|
|
50
|
-
endswith: str = ".tar.gz",
|
|
51
|
-
|
|
52
|
-
update_all_function: Callable[[], int] = update_pip_and_required_packages,
|
|
53
|
-
build_package_function: Callable[[], int] = build_package,
|
|
54
|
-
upload_package_function: Callable[[str, str], int] = upload_package,
|
|
55
|
-
) -> None:
|
|
56
|
-
""" Upload the most recent file(s) to PyPI after updating pip and required packages and building the package.
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
repository (str): Repository to upload to.
|
|
60
|
-
dist_directory (str): Directory to upload from.
|
|
61
|
-
last_files (int): Number of most recent files to upload. Defaults to 1.
|
|
62
|
-
endswith (str): End of the file name to upload. Defaults to ".tar.gz".
|
|
63
|
-
update_all_function (Callable[[], int]): Function to update pip and required packages.
|
|
64
|
-
Defaults to :func:`update_pip_and_required_packages`.
|
|
65
|
-
build_package_function (Callable[[], int]): Function to build the package.
|
|
66
|
-
Defaults to :func:`build_package`.
|
|
67
|
-
upload_package_function (Callable[[str, str], int]): Function to upload the package.
|
|
68
|
-
Defaults to :func:`upload_package`.
|
|
69
|
-
|
|
70
|
-
Returns:
|
|
71
|
-
int: Return code of the command.
|
|
72
|
-
"""
|
|
73
|
-
if update_all_function() != 0:
|
|
74
|
-
raise Exception("Error while updating pip and required packages")
|
|
75
|
-
|
|
76
|
-
if build_package_function() != 0:
|
|
77
|
-
raise Exception("Error while building the package")
|
|
78
|
-
|
|
79
|
-
# Get list of tar.gz files in dist directory sorted by modification time
|
|
80
|
-
files: list[str] = sorted(
|
|
81
|
-
[x for x in os.listdir(dist_directory) if x.endswith(endswith)], # Get list of tar.gz files in dist directory
|
|
82
|
-
key=lambda x: os.path.getmtime(f"{dist_directory}/{x}"), # Sort by modification time
|
|
83
|
-
reverse=True # Sort in reverse order
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
# Upload the most recent file(s)
|
|
87
|
-
for file in files[:last_files]:
|
|
88
|
-
upload_package_function(repository, f"{dist_directory}/{file}")
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
""" This module contains utilities for PyPI.
|
|
2
|
+
|
|
3
|
+
- pypi_full_routine: Upload the most recent file(s) to PyPI after updating pip and required packages and building the package
|
|
4
|
+
|
|
5
|
+
.. image:: https://raw.githubusercontent.com/Stoupy51/stouputils/refs/heads/main/assets/continuous_delivery/pypi_module.gif
|
|
6
|
+
:alt: stouputils pypi examples
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Imports
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
|
|
14
|
+
from ..decorators import LogLevels, handle_error
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def update_pip_and_required_packages() -> int:
|
|
18
|
+
""" Update pip and required packages.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
int: Return code of the os.system call.
|
|
22
|
+
"""
|
|
23
|
+
return os.system(f"{sys.executable} -m pip install --upgrade pip setuptools build twine pkginfo packaging")
|
|
24
|
+
|
|
25
|
+
def build_package() -> int:
|
|
26
|
+
""" Build the package.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
int: Return code of the os.system call.
|
|
30
|
+
"""
|
|
31
|
+
return os.system(f"{sys.executable} -m build")
|
|
32
|
+
|
|
33
|
+
def upload_package(repository: str, filepath: str) -> int:
|
|
34
|
+
""" Upload the package to PyPI.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
repository (str): Repository to upload to.
|
|
38
|
+
filepath (str): Path to the file to upload.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
int: Return code of the os.system call.
|
|
42
|
+
"""
|
|
43
|
+
return os.system(f"{sys.executable} -m twine upload --verbose -r {repository} {filepath}")
|
|
44
|
+
|
|
45
|
+
@handle_error(message="Error while doing the pypi full routine", error_log=LogLevels.ERROR_TRACEBACK)
|
|
46
|
+
def pypi_full_routine(
|
|
47
|
+
repository: str,
|
|
48
|
+
dist_directory: str,
|
|
49
|
+
last_files: int = 1,
|
|
50
|
+
endswith: str = ".tar.gz",
|
|
51
|
+
|
|
52
|
+
update_all_function: Callable[[], int] = update_pip_and_required_packages,
|
|
53
|
+
build_package_function: Callable[[], int] = build_package,
|
|
54
|
+
upload_package_function: Callable[[str, str], int] = upload_package,
|
|
55
|
+
) -> None:
|
|
56
|
+
""" Upload the most recent file(s) to PyPI after updating pip and required packages and building the package.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
repository (str): Repository to upload to.
|
|
60
|
+
dist_directory (str): Directory to upload from.
|
|
61
|
+
last_files (int): Number of most recent files to upload. Defaults to 1.
|
|
62
|
+
endswith (str): End of the file name to upload. Defaults to ".tar.gz".
|
|
63
|
+
update_all_function (Callable[[], int]): Function to update pip and required packages.
|
|
64
|
+
Defaults to :func:`update_pip_and_required_packages`.
|
|
65
|
+
build_package_function (Callable[[], int]): Function to build the package.
|
|
66
|
+
Defaults to :func:`build_package`.
|
|
67
|
+
upload_package_function (Callable[[str, str], int]): Function to upload the package.
|
|
68
|
+
Defaults to :func:`upload_package`.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
int: Return code of the command.
|
|
72
|
+
"""
|
|
73
|
+
if update_all_function() != 0:
|
|
74
|
+
raise Exception("Error while updating pip and required packages")
|
|
75
|
+
|
|
76
|
+
if build_package_function() != 0:
|
|
77
|
+
raise Exception("Error while building the package")
|
|
78
|
+
|
|
79
|
+
# Get list of tar.gz files in dist directory sorted by modification time
|
|
80
|
+
files: list[str] = sorted(
|
|
81
|
+
[x for x in os.listdir(dist_directory) if x.endswith(endswith)], # Get list of tar.gz files in dist directory
|
|
82
|
+
key=lambda x: os.path.getmtime(f"{dist_directory}/{x}"), # Sort by modification time
|
|
83
|
+
reverse=True # Sort in reverse order
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Upload the most recent file(s)
|
|
87
|
+
for file in files[:last_files]:
|
|
88
|
+
upload_package_function(repository, f"{dist_directory}/{file}")
|
|
89
|
+
|
|
90
|
+
|