go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.41k stars 616 forks source link

Ubuntu 24 python3.12 venv activate command does not execute #1788

Open eccles opened 2 months ago

eccles commented 2 months ago

When upgrading to ubuntu 24.04 and using a python venv in a task using the builtin shell, an error occurs.

This error is because the built-in shell in go-task does not honour the 'hash' command and the python3 devs removed the conditional check in the 'activate' command.

See https://github.com/pypa/virtualenv/pull/2086

This was mitigated by explicitly using bash.

Example

  something:
    desc: runs the something command - does not work
    deps: [venv]
    cmds:
      - |
        source venvs/avid-scripts/bin/activate
        trap deactivate EXIT
        python3 -m something --option value

Fix:

  something:
    desc: runs the something command - does work
    deps: [venv]
    cmds:
      - |
        bash <<EOF
        source venvs/avid-scripts/bin/activate
        trap deactivate EXIT
        python3 -m something --option value
        EOF
eccles commented 1 month ago

Actually there is a better way of fixing this. When creating the venv simply create a dummy hash method:

 sed -i '1i function hash { :; }' bin/activate
andrewimeson commented 2 weeks ago

If you need cross platform support, the sed won't work well for BSD and Mac. I use this similar (but less concise, I may have to modify it now) approach, but I read the file in and then write it out again to avoid sed.

- cmd: |
    # The mvdan Go sh interpreter doesn't have the 'hash' builtin, which
    # newer versions of the venv activation require. Some systems have
    # 'hash' available as an external utility, but Gitea Actions doesn't.
    # In that case, we patch the venv activation script to emulate 'hash'
    # as a no-op if it's not present.
    _venv_file="$(< $VENV_ACTIVATE)"

    {
        cat << EOF
    if ! command -v hash 2>&1 > /dev/null; then
        hash(){
            true
        }
    fi
    EOF
        echo "$_venv_file"
    } > $VENV_ACTIVATE
  silent: true