Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eccles opened this issue Sep 6, 2024 · 2 comments
Open

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

eccles opened this issue Sep 6, 2024 · 2 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@eccles
Copy link

eccles commented Sep 6, 2024

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 pypa/virtualenv#2086

  • Task version: 3.37.2
  • Operating system: ubuntu 24.04
  • Experiments enabled: no

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
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 6, 2024
@eccles
Copy link
Author

eccles commented Sep 16, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

3 participants