def get_job_environment()

in submitit/core/plugins.py [0:0]


def get_job_environment() -> "JobEnvironment":
    # Don't cache this function. It makes testing harder.
    # The slow part is the plugin discovery anyway.
    envs = get_job_environments()
    # bypassing can be helful for testing
    if "_TEST_CLUSTER_" in os.environ:
        c = os.environ["_TEST_CLUSTER_"]
        assert c in envs, f"Unknown $_TEST_CLUSTER_='{c}', available: {envs.keys()}."
        return envs[c]
    for env in envs.values():
        # TODO? handle the case where several envs are valid
        if env.activated():
            return env
    raise RuntimeError(
        f"Could not figure out which environment the job is runnning in. Known environments: {', '.join(envs.keys())}."
    )