io
env(name, def_val='')
¶
Access an environment variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the environment variable. |
required |
def_val |
str
|
The default value to return if not set. Defaults to empty. |
''
|
Returns:
Type | Description |
---|---|
str
|
The value of the environment variable if set otherwise the |
Source code in m/core/io.py
env_model(model)
¶
Require multiple env vars to be defined.
This can be done by defining a model::
class GithubEnvVars(BaseModel):
repo: str = Field('GITHUB_REPOSITORY')
run_id: str = Field('GITHUB_RUN_ID')
Then we use it::
print(env.repo for env in env_model(GithubEnvVars)])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
type[BaseModelT]
|
A pydantic model specifying the environment variables to fetch. |
required |
Returns:
Type | Description |
---|---|
OneOf[Issue, BaseModelT]
|
A |
Source code in m/core/io.py
format_seconds(number_of_seconds)
¶
Return a string representing the number of seconds.
The format is Xd:Xh:Xm:Xs:Xms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number_of_seconds |
int | float
|
The number of seconds to format. |
required |
Returns:
Type | Description |
---|---|
str
|
A friendly representation of the number of seconds. |
Source code in m/core/io.py
is_python_info_enabled()
¶
Return True if the python file location should be displayed.
By default this information is not displayed since the stacktrace already provides most of the info. If we need it we can set one of the env var
- DEBUG_M_PYTHON
- DEBUG
DEBUG_M_PYTHON
is accepted in case we do not want to enable the
traceback.
Returns:
Type | Description |
---|---|
bool
|
True if the python file location should be displayed. |
Source code in m/core/io.py
is_traceback_enabled()
¶
Return True if the stacktrace should be displayed.
This is true by default on a CI environment where the env var CI is set
to true
.
We can enable this locally by settings the env vars
- DEBUG_M_STACKTRACE
- DEBUG
The DEBUG_M_STACKTRACE
is provided so to only target this particular
piece of info and avoid other pieces of code that may be looking at
the DEBUG
env var from activating.
Returns:
Type | Description |
---|---|
bool
|
True if the stacktrace should be displayed. |
Source code in m/core/io.py
prompt_choices(description, choices, as_list=True)
¶
Prompt the user with a description until we get one of the choices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
The prompt to display. |
required |
choices |
Sequence[str]
|
List of accepted choices. |
required |
as_list |
bool
|
If false, it will concat the choices with |
True
|
Returns:
Type | Description |
---|---|
str
|
The string chosen by the user. |
Source code in m/core/io.py
prompt_next_version(version, release_type)
¶
Prompt the developer to select the next version.
It displays the possible major, minor and patch versions and prompts the developer to enter one of them. See https://semver.org/.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
str
|
The current version. |
required |
release_type |
str
|
If |
required |
Returns:
Type | Description |
---|---|
OneOf[Issue, str]
|
One of the versions wrapped in a OneOf. |
Source code in m/core/io.py
renv(key)
¶
Require an environment variable to be defined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The environment variable required to be defined. |
required |
Returns:
Type | Description |
---|---|
OneOf[Issue, str]
|
A |