<commit_before># -*- coding: UTF-8 -*-
# FILE: features/environment.py
"""
Functionality:

  * active tags
"""

from __future__ import print_function
from behave.tag_matcher import ActiveTagMatcher, setup_active_tag_values
from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave
import six
import sys
import platform
import os.path


def require_tool(tool_name):
    """Check if a tool (an executable program) is provided on this platform.

    :params tool_name:  Name of the tool to check if it is available.
    :return: True, if tool is found.
    :return: False, if tool is not available (or not in search path).
    """
    # print("CHECK-TOOL: %s" % tool_name)
    path = os.environ.get("PATH")
    if not path:
        return False

    for searchdir in path.split(os.pathsep):
        executable1 = os.path.normpath(os.path.join(searchdir, tool_name))
        executables = [executable1]
        if sys.platform.startswith("win"):
            executables.append(executable1 + ".exe")

        for executable in executables:
            # print("TOOL-CHECK: %s" % os.path.abspath(executable))
            if os.path.isfile(executable):
                # print("TOOL-FOUND: %s" % os.path.abspath(executable))
                return True
    # -- OTHERWISE: Tool not found
    # print("TOOL-NOT-FOUND: %s" % tool_name)
    return False

def as_bool_string(value):
    if bool(value):
        return "yes"
    else:
        return "no"

def select_ci_server():
    ci_server = "none"
    CI = os.environ.get("CI").lower() == "true"
    APPVEYOR = os.environ.get("APPVEYOR").lower() == "true"
    TRAVIS = os.environ.get("TRAVIS").lower() == "true"
    if CI:
        if APPVEYOR:
            ci_server = "appveyor"
        elif TRAVIS:
            ci_server = "travis"
        else:
            ci_server = "unknown"
    return ci_server


# -- MATCHES ANY TAGS: @use.with_{category}={value}
# NOTE: active_tag_value_provider provides category values for active tags.
active_tag_value_provider = {
    "python2": str(six.PY2).lower(),
    "python3": str(six.PY3).lower(),
    # -- python.implementation: cpython, pypy, jython, ironpython
    "python.implementation": platform.python_implementation().lower(),
    "pypy":    str("__pypy__" in sys.modules).lower(),
    "os":      sys.platform,
    "xmllint": as_bool_string(require_tool("xmllint")),
    "ci": select_ci_server()
}
active_tag_matcher = ActiveTagMatcher(active_tag_value_provider)

def before_all(context):
    # -- SETUP ACTIVE-TAG MATCHER (with userdata):
    # USE: behave -D browser=safari ...<commit_msg>Add active-tag support for CI server (fix).<commit_after># -*- coding: UTF-8 -*-
# FILE: features/environment.py
"""
Functionality:

  * active tags
"""

from __future__ import print_function
from behave.tag_matcher import ActiveTagMatcher, setup_active_tag_values
from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave
import six
import sys
import platform
import os.path


def require_tool(tool_name):
    """Check if a tool (an executable program) is provided on this platform.

    :params tool_name:  Name of the tool to check if it is available.
    :return: True, if tool is found.
    :return: False, if tool is not available (or not in search path).
    """
    # print("CHECK-TOOL: %s" % tool_name)
    path = os.environ.get("PATH")
    if not path:
        return False

    for searchdir in path.split(os.pathsep):
        executable1 = os.path.normpath(os.path.join(searchdir, tool_name))
        executables = [executable1]
        if sys.platform.startswith("win"):
            executables.append(executable1 + ".exe")

        for executable in executables:
            # print("TOOL-CHECK: %s" % os.path.abspath(executable))
            if os.path.isfile(executable):
                # print("TOOL-FOUND: %s" % os.path.abspath(executable))
                return True
    # -- OTHERWISE: Tool not found
    # print("TOOL-NOT-FOUND: %s" % tool_name)
    return False

def as_bool_string(value):
    if bool(value):
        return "yes"
    else:
        return "no"

def select_ci_server():
    ci_server = "none"
    CI = os.environ.get("CI", "false").lower() == "true"
    APPVEYOR = os.environ.get("APPVEYOR", "false").lower() == "true"
    TRAVIS = os.environ.get("TRAVIS", "false").lower() == "true"
    if CI:
        if APPVEYOR:
            ci_server = "appveyor"
        elif TRAVIS:
            ci_server = "travis"
        else:
            ci_server = "unknown"
    return ci_server


# -- MATCHES ANY TAGS: @use.with_{category}={value}
# NOTE: active_tag_value_provider provides category values for active tags.
active_tag_value_provider = {
    "python2": str(six.PY2).lower(),
    "python3": str(six.PY3).lower(),
    # -- python.implementation: cpython, pypy, jython, ironpython
    "python.implementation": platform.python_implementation().lower(),
    "pypy":    str("__pypy__" in sys.modules).lower(),
    "os":      sys.platform,
    "xmllint": as_bool_string(require_tool("xmllint")),
    "ci": select_ci_server()
}
active_tag_matcher = ActiveTagMatcher(active_tag_value_provider)

def before_all(context):
    # -- SETUP ACTIVE-TAG MATCHER (with userdata):
    # USE: behave -D browser=safari ...
{'fraction_non_alphanumeric': 0.12706552706552707, 'fraction_numerical': 0.004178537511870846, 'mean_word_length': 3.044546850998464, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1528541', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1709, 'n_words': 415}