Skip to content

m_env

MEnv

Bases: BaseModel

Contains all the information required for a CI run.

Attributes:

Name Type Description
config Config

...

env_vars EnvVars

...

git_env GitEnv

...

release_env ReleaseEnv

...

Source code in m/ci/m_env.py
class MEnv(BaseModel):
    """Contains all the information required for a CI run."""

    config: Config
    env_vars: EnvVars
    git_env: GitEnv
    release_env: ReleaseEnv

bashrc_snippet(m_dir)

Create a bash snippet that exports the M environment variables.

Parameters:

Name Type Description Default
m_dir str

The directory with the m configuration.

required

Returns:

Type Description
Res[str]

An issue or a bash snippet.

Source code in m/ci/m_env.py
def bashrc_snippet(m_dir: str) -> Res[str]:
    """Create a bash snippet that exports the M environment variables.

    Args:
        m_dir: The directory with the m configuration.

    Returns:
        An issue or a bash snippet.
    """
    return one_of(lambda: [
        '\n'.join([
            f'export {assignment}'
            for line in env_list
            for assignment in fp.Good(_lower_bool(line))
        ])
        for m_env in get_m_env(m_dir)
        for env_list in _m_env_vars(m_env)
    ])

get_m_env(m_dir)

Obtain the M Environment object.

Parameters:

Name Type Description Default
m_dir str

The directory containing the m configuration.

required

Returns:

Type Description
Res[MEnv]

The M Environment if it exists otherwise an issue.

Source code in m/ci/m_env.py
def get_m_env(m_dir: str) -> Res[MEnv]:
    """Obtain the M Environment object.

    Args:
        m_dir: The directory containing the m configuration.

    Returns:
        The M Environment if it exists otherwise an issue.
    """
    ci_tool = get_ci_tool()
    return one_of(lambda: [
        MEnv(
            config=config,
            env_vars=env_vars,
            git_env=git_env,
            release_env=release_env,
        )
        for config in read_config(m_dir)
        for env_vars in ci_tool.env_vars()
        for git_env in get_git_env(config, env_vars)
        for release_env in get_release_env(config, env_vars, git_env)
    ]).flat_map_bad(hone('get_m_env failure'))

write_m_env_vars(m_dir)

Write a file with the M environment variables.

Parameters:

Name Type Description Default
m_dir str

The directory with the m configuration.

required

Returns:

Type Description
Res[Any]

An issue or the m environment instance.

Source code in m/ci/m_env.py
def write_m_env_vars(m_dir: str) -> Res[Any]:
    """Write a file with the M environment variables.

    Args:
        m_dir: The directory with the m configuration.

    Returns:
        An issue or the m environment instance.
    """
    target_dir = Path(f'{m_dir}/.m')

    if not Path.exists(target_dir):
        Path.mkdir(target_dir, parents=True)
    return one_of(lambda: [
        json.loads(m_env.model_dump_json())
        for m_env in get_m_env(m_dir)
        for env_list in _m_env_vars(m_env)
        for _ in mio.write_file(f'{m_dir}/.m/env.list', '\n'.join(env_list))
    ])