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) dict[str, Any] [source]¶
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: Response, error_message: str) None [source]¶
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.
- Parameters:
version (str) – The version string to convert. (e.g. “v1.0.0.1.2.3”)
- 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