stouputils.continuous_delivery.cd_utils module#
This module contains utilities for continuous delivery, such as loading credentials from a file. It is mainly used by the stouputils.continuous_delivery.github module.
- load_credentials(
- credentials_path: str,
Load credentials from a JSON or YAML file into a dictionary.
Loads credentials from either a JSON or YAML file and returns them as a dictionary. The file must contain the required credentials in the appropriate format.
- Parameters:
credentials_path (str) – Path to the credentials file (.json or .yml)
- Returns:
Dictionary containing the credentials
- Return type:
dict[str, Any]
Example JSON format:
{ "github": { "username": "Stoupy51", "api_key": "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX" } }
Example YAML format:
github: username: "Stoupy51" api_key: "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXX"
- handle_response(
- response: requests.Response,
- error_message: str,
Handle a response from the API by raising an error if the response is not successful (status code not in 200-299).
- Parameters:
response (requests.Response) – The response from the API
error_message (str) – The error message to raise if the response is not successful
- clean_version(version: str, keep: str = '') str[source]#
Clean a version string
- Parameters:
version (str) – The version string to clean
keep (str) – The characters to keep in the version string
- Returns:
The cleaned version string
- Return type:
str
>>> clean_version("v1.e0.zfezf0.1.2.3zefz") '1.0.0.1.2.3' >>> clean_version("v1.e0.zfezf0.1.2.3zefz", keep="v") 'v1.0.0.1.2.3' >>> clean_version("v1.2.3b", keep="ab") '1.2.3b'
- version_to_float(version: str) float[source]#
Converts a version string into a float for comparison purposes. The version string is expected to follow the format of major.minor.patch.something_else…., where each part is separated by a dot and can be extended indefinitely. Supports pre-release suffixes with numbers: devN/dN (dev), aN (alpha), bN (beta), rcN/cN (release candidate). Ordering: 1.0.0 > 1.0.0rc2 > 1.0.0rc1 > 1.0.0b2 > 1.0.0b1 > 1.0.0a2 > 1.0.0a1 > 1.0.0dev1
- Parameters:
version (str) – The version string to convert. (e.g. “v1.0.0.1.2.3”, “v2.0.0b2”, “v1.0.0rc1”)
- Returns:
The float representation of the version. (e.g. 0)
- Return type:
float
>>> version_to_float("v1.0.0") 1.0 >>> version_to_float("v1.0.0.1") 1.000000001 >>> version_to_float("v2.3.7") 2.003007 >>> version_to_float("v1.0.0.1.2.3") 1.0000000010020031 >>> version_to_float("v2.0") > version_to_float("v1.0.0.1") True >>> version_to_float("v2.0.0") > version_to_float("v2.0.0rc") > version_to_float("v2.0.0b") > version_to_float("v2.0.0a") > version_to_float("v2.0.0dev") True >>> version_to_float("v1.0.0b") > version_to_float("v1.0.0a") True >>> version_to_float("v1.0.0") > version_to_float("v1.0.0b") True >>> version_to_float("v3.0.0a") > version_to_float("v2.9.9") True >>> version_to_float("v1.2.3b") < version_to_float("v1.2.3") True >>> version_to_float("1.0.0") == version_to_float("v1.0.0") True >>> version_to_float("2.0.0.0.0.0.1b") > version_to_float("2.0.0.0.0.0.1a") True >>> version_to_float("2.0.0.0.0.0.1") > version_to_float("2.0.0.0.0.0.1b") True >>> version_to_float("v1.0.0rc") == version_to_float("v1.0.0c") True >>> version_to_float("v1.0.0c") > version_to_float("v1.0.0b") True >>> version_to_float("v1.0.0d") < version_to_float("v1.0.0a") True >>> version_to_float("v1.0.0dev") < version_to_float("v1.0.0a") True >>> version_to_float("v1.0.0dev") == version_to_float("v1.0.0d") True >>> version_to_float("v1.0.0rc2") > version_to_float("v1.0.0rc1") True >>> version_to_float("v1.0.0b2") > version_to_float("v1.0.0b1") True >>> version_to_float("v1.0.0a2") > version_to_float("v1.0.0a1") True >>> version_to_float("v1.0.0dev2") > version_to_float("v1.0.0dev1") True >>> version_to_float("v1.0.0") > version_to_float("v1.0.0rc2") > version_to_float("v1.0.0rc1") True >>> version_to_float("v1.0.0rc1") > version_to_float("v1.0.0b2") True >>> version_to_float("v1.0.0b1") > version_to_float("v1.0.0a2") True >>> version_to_float("v1.0.0a1") > version_to_float("v1.0.0dev2") True >>> versions = ["v1.0.0", "v1.0.0rc2", "v1.0.0rc1", "v1.0.0b2", "v1.0.0b1", "v1.0.0a2", "v1.0.0a1", "v1.0.0dev2", "v1.0.0dev1"] >>> sorted_versions = sorted(versions, key=version_to_float, reverse=True) >>> sorted_versions == versions True