<commit_before>import os

from acbs.const import AUTOBUILD_CONF_DIR
from acbs import bashvar
from pyparsing import ParseException # type: ignore


def is_in_stage2() -> bool:
    ab3cfg_path: str = os.path.join(AUTOBUILD_CONF_DIR, 'ab3cfg.sh')
    try:
        with open(ab3cfg_path) as f:
            vars = bashvar.eval_bashvar(f.read(), filename=ab3cfg_path)
            stage2_val: str = vars.get('ABSTAGE2')
            return True if stage2_val == '1' else False
    except OSError as e:
        raise RuntimeError(f'Unable to read Autobuild config file {ab3cfg_path}.') from e
    except ParseException as e:
        raise RuntimeError(f'Error occurred while parsing Autobuild config file {ab3cfg_path}.') from e
    except Exception as e:
        raise RuntimeError(f'Error occurred while checking whether stage 2 mode is enabled.') from e
<commit_msg>ab3cfg: simplify stage2 detection logic<commit_after>import os

from acbs.const import AUTOBUILD_CONF_DIR
from acbs import bashvar
from pyparsing import ParseException # type: ignore


def is_in_stage2() -> bool:
    ab3cfg_path: str = os.path.join(AUTOBUILD_CONF_DIR, 'ab3cfg.sh')
    try:
        with open(ab3cfg_path) as f:
            vars = bashvar.eval_bashvar(f.read(), filename=ab3cfg_path)
            stage2_val: str = vars.get('ABSTAGE2')
            return stage2_val == '1'
    except OSError as e:
        raise RuntimeError(f'Unable to read Autobuild config file {ab3cfg_path}.') from e
    except ParseException as e:
        raise RuntimeError(f'Error occurred while parsing Autobuild config file {ab3cfg_path}.') from e
    except Exception as e:
        raise RuntimeError(f'Error occurred while checking whether stage 2 mode is enabled.') from e

{'fraction_non_alphanumeric': 0.0781702374059062, 'fraction_numerical': 0.015055008685581933, 'mean_word_length': 3.419437340153453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1248660', 'n_tokens_mistral': 546, 'n_tokens_neox': 536, 'n_words': 174}