<commit_before>import subprocess
import sys
from enum import Enum
from pathlib import Path
from typing import Optional, Iterable

from git import Repo

from arca.exceptions import ArcaMisconfigured, RequirementsMismatch, BuildError
from arca.utils import LazySettingProperty, logger
from .base import BaseRunInSubprocessBackend


class RequirementsStrategy(Enum):
    IGNORE = "ignore"
    RAISE = "raise"
    INSTALL_EXTRA = "install_extra"


class CurrentEnvironmentBackend(BaseRunInSubprocessBackend):

    current_environment_requirements = LazySettingProperty(key="current_environment_requirements")
    requirements_strategy = LazySettingProperty(key="requirements_strategy",
                                                default=RequirementsStrategy.RAISE,
                                                convert=RequirementsStrategy)

    def validate_settings(self):
        super().validate_settings()

        if self.current_environment_requirements is not None:
            if not Path(self.current_environment_requirements).exists():
                raise ArcaMisconfigured("Can't locate current environment requirements.")

    def install_requirements(self, *, fl: Optional[Path]=None, requirements: Optional[Iterable[str]]=None,
                             _action: str="install"):
        if _action not in ["install", "uninstall"]:
            raise ValueError(f"{_action} is invalid value for _invalid")

        cmd = [sys.executable, "-m", "pip", _action]

        if _action == "uninstall":
            cmd += ["-y"]

        if fl is not None:
            cmd += ["-r", str(fl)]
        elif requirements is not None:
            cmd += list(requirements)
        else:
            raise ValueError("Either fl or requirements has to be provided")

        logger.info("Installing requirements with command: %s", cmd)

        process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<commit_msg>Fixed an exception message in CurrentEnvironmentBackend<commit_after>import subprocess
import sys
from enum import Enum
from pathlib import Path
from typing import Optional, Iterable

from git import Repo

from arca.exceptions import ArcaMisconfigured, RequirementsMismatch, BuildError
from arca.utils import LazySettingProperty, logger
from .base import BaseRunInSubprocessBackend


class RequirementsStrategy(Enum):
    IGNORE = "ignore"
    RAISE = "raise"
    INSTALL_EXTRA = "install_extra"


class CurrentEnvironmentBackend(BaseRunInSubprocessBackend):

    current_environment_requirements = LazySettingProperty(key="current_environment_requirements")
    requirements_strategy = LazySettingProperty(key="requirements_strategy",
                                                default=RequirementsStrategy.RAISE,
                                                convert=RequirementsStrategy)

    def validate_settings(self):
        super().validate_settings()

        if self.current_environment_requirements is not None:
            if not Path(self.current_environment_requirements).exists():
                raise ArcaMisconfigured("Can't locate current environment requirements.")

    def install_requirements(self, *, fl: Optional[Path]=None, requirements: Optional[Iterable[str]]=None,
                             _action: str="install"):
        if _action not in ["install", "uninstall"]:
            raise ValueError(f"{_action} is invalid value for _action")

        cmd = [sys.executable, "-m", "pip", _action]

        if _action == "uninstall":
            cmd += ["-y"]

        if fl is not None:
            cmd += ["-r", str(fl)]
        elif requirements is not None:
            cmd += list(requirements)
        else:
            raise ValueError("Either fl or requirements has to be provided")

        logger.info("Installing requirements with command: %s", cmd)

        process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
{'fraction_non_alphanumeric': 0.08348180198523797, 'fraction_numerical': 0.0, 'mean_word_length': 2.914342629482072, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3085978', 'n_tokens_mistral': 1010, 'n_tokens_neox': 977, 'n_words': 274}