conda-forge / conda-smithy

The tool for managing conda-forge feedstocks.
https://conda-forge.org/
BSD 3-Clause "New" or "Revised" License
152 stars 181 forks source link

Add SOURCE and LINENO information for debugging #1689

Open nikhilweee opened 2 years ago

nikhilweee commented 2 years ago

Comment:

I spend a couple days debugging python-feedstock. For a newbie like me, I found it pretty helpful to set PS4 in all bash scripts in the feedstock like so. I wonder what the community feels about adding something like this by default to all scripts?

export PS4='\[\e[33m\]+ ${BASH_SOURCE}:${LINENO} \[\e[0m\]'
# or maybe truncate large paths
export PS4='\[\e[33m\]+ ${BASH_SOURCE:${#BASH_SOURCE}<80?0:-80}:${LINENO} \[\e[0m\]'
nikhilweee commented 2 years ago

These PS4 variables could be exported in conda_smithy/feedstock_content/.scripts/logging_utils.sh like so

function startgroup {
    # Start a foldable group of log lines
    # Pass a single argument, quoted
    case ${CI:-} in
        azure )
            echo "##[group]$1";;
        travis )
            echo "$1"
            echo -en 'travis_fold:start:'"${1// /}"'\\r';;
        github_actions )
            echo "::group::$1";;
        * )
            export PS4='\[\e[33m\]+ ${BASH_SOURCE:${#BASH_SOURCE}<80?0:-80}:${LINENO} \[\e[0m\]'
            echo "$1";;
    esac
} 2> /dev/null

function endgroup {
    # End a foldable group of log lines
    # Pass a single argument, quoted

    case ${CI:-} in
        azure )
            echo "##[endgroup]";;
        travis )
            echo -en 'travis_fold:end:'"${1// /}"'\\r';;
        github_actions )
            echo "::endgroup::";;
        * )
            export PS4="+ "
    esac
} 2> /dev/null