summaryrefslogtreecommitdiff
path: root/lib/spack/spack/context.py
blob: de3311da22b0ff14b0fc67732dc2c0f02b643f85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
"""This module provides classes used in user and build environment"""

from enum import Enum


class Context(Enum):
    """Enum used to indicate the context in which an environment has to be setup: build,
    run or test."""

    BUILD = 1
    RUN = 2
    TEST = 3

    def __str__(self):
        return ("build", "run", "test")[self.value - 1]

    @classmethod
    def from_string(cls, s: str):
        if s == "build":
            return Context.BUILD
        elif s == "run":
            return Context.RUN
        elif s == "test":
            return Context.TEST
        raise ValueError(f"context should be one of 'build', 'run', 'test', got {s}")