<commit_before># This script should be sourced, not executed.

# `idf_tools.py export --unset` create statement, with keyword unset, but fish shell support only `set --erase variable`
function unset
    set --erase $argv
end

function __main
    if not set -q IDF_PATH
        set -x IDF_PATH (cd (dirname (status -f)); and pwd)
        echo "Chosen IDF_PATH: $IDF_PATH"
    end

    set script_dir (cd (dirname (status -f)); and pwd)
    if test "$script_dir" = "."
        set script_dir $pwd
    end
    if test "$IDF_PATH" != "$script_dir"
        # Change IDF_PATH is important when there are 2 ESP-IDF versions in different directories.
        # Sourcing this script without change, would cause sourcing wrong export script.
        echo "Resetting IDF_PATH from '$IDF_PATH' to '$script_dir'"
        set IDF_PATH "$script_dir"
    end

    set oldpath = $PATH

    echo "Detecting the Python interpreter"
    source "$IDF_PATH"/tools/detect_python.fish

    echo "Checking Python compatibility"
    "$ESP_PYTHON" "$IDF_PATH"/tools/python_version_checker.py

    echo "Checking other ESP-IDF version."
    set idf_unset ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --unset) || return 1
    eval "$idf_unset"

    echo "Adding ESP-IDF tools to PATH..."
    # Call idf_tools.py to export tool paths
    set -x IDF_TOOLS_EXPORT_CMD "$IDF_PATH"/export.fish
    set -x IDF_TOOLS_INSTALL_CMD "$IDF_PATH"/install.fish
    # Allow calling some IDF python tools without specifying the full path
    # "$IDF_PATH"/tools is already added by 'idf_tools.py export'
    set IDF_ADD_PATHS_EXTRAS "$IDF_PATH"/components/esptool_py/esptool
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/espcoredump
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update

    set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --add_paths_extras="$IDF_ADD_PATHS_EXTRAS") || return 1
    eval "$idf_exports"
    set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"

    echo "Checking if Python packages are up to date..."
    python "$IDF_PATH"/tools/idf_tools.py check-python-dependencies || return 1

    set added_path_variables
    for entry in $PATH;
        if not contains $entry $oldpath
            set -a added_path_variables $entry
        end
    end
    if set -q added_path_variables[1]
        echo "Added the following directories to PATH:"
        for entry in $added_path_variables;
            echo $entry
        end
    else<commit_msg>Tools: Auto-detect IDF_PATH in export.fish, fix setting environmental variables<commit_after># This script should be sourced, not executed.

# `idf_tools.py export --unset` create statement, with keyword unset, but fish shell support only `set --erase variable`
function unset
    set --erase $argv
end

function __main
    if not set -q IDF_PATH
        set -gx IDF_PATH (cd (dirname (status -f)); and pwd)
        echo "Setting IDF_PATH to '$IDF_PATH'"
    end

    set script_dir (cd (dirname (status -f)); and pwd)
    if test "$script_dir" = "."
        set script_dir $pwd
    end
    if test "$IDF_PATH" != "$script_dir"
        # Change IDF_PATH is important when there are 2 ESP-IDF versions in different directories.
        # Sourcing this script without change, would cause sourcing wrong export script.
        echo "Resetting IDF_PATH from '$IDF_PATH' to '$script_dir'"
        set IDF_PATH "$script_dir"
    end

    set oldpath = $PATH

    echo "Detecting the Python interpreter"
    source "$IDF_PATH"/tools/detect_python.fish

    echo "Checking Python compatibility"
    "$ESP_PYTHON" "$IDF_PATH"/tools/python_version_checker.py

    echo "Checking other ESP-IDF version."
    set idf_unset ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --unset) || return 1
    eval "$idf_unset"

    echo "Adding ESP-IDF tools to PATH..."
    # Call idf_tools.py to export tool paths
    set -gx IDF_TOOLS_EXPORT_CMD "$IDF_PATH"/export.fish
    set -gx IDF_TOOLS_INSTALL_CMD "$IDF_PATH"/install.fish
    # Allow calling some IDF python tools without specifying the full path
    # "$IDF_PATH"/tools is already added by 'idf_tools.py export'
    set IDF_ADD_PATHS_EXTRAS "$IDF_PATH"/components/esptool_py/esptool
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/espcoredump
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update

    set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --add_paths_extras="$IDF_ADD_PATHS_EXTRAS") || return 1
    eval "$idf_exports"
    set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"

    echo "Checking if Python packages are up to date..."
    python "$IDF_PATH"/tools/idf_tools.py check-python-dependencies || return 1

    set added_path_variables
    for entry in $PATH;
        if not contains $entry $oldpath
            set -a added_path_variables $entry
        end
    end
    if set -q added_path_variables[1]
        echo "Added the following directories to PATH:"
        for entry in $added_path_variables;
            echo $entry
        end
    else
{'fraction_non_alphanumeric': 0.09233978005309064, 'fraction_numerical': 0.0018960940462646946, 'mean_word_length': 3.3237704918032787, 'pattern_counts': {'":': 8, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4170165', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1747, 'n_words': 508}