Skip to content

Commit

Permalink
Change venv location and make use of direnv on gha (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 31, 2024
1 parent 8ce8361 commit 19d7d99
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
11 changes: 7 additions & 4 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Helps direnv 2.32.1+ auto activate virtualenv but we do not require
# developers to use it.
# https://github.com/direnv/direnv/wiki/Python

# This VIRTUAL_ENV value is also configured inside .vscode/settings.json:
export HOSTNAME="${HOSTNAME:-localhost}"
export VIRTUAL_ENV="out/venvs/${HOSTNAME}"
use asdf
export HOSTNAME="${HOSTNAME:-${HOST:-$(hostname)}}"
# 'vsa' is acronym for 'visual studio ansible'
# we use HOME location below to avoid polluting the project directory with,
# temporary data and to allow us to mount the codebase on multiple machines
# for build and testing purposes.
export VIRTUAL_ENV="${HOME}/.local/share/virtualenvs/vsa"

# Activate virtualenv (creates it if needed)
layout python
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ jobs:
if: "!contains(matrix.shell, 'wsl')"
uses: asdf-vm/actions/install@v3

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install asdf inside WSL
if: "contains(matrix.shell, 'wsl')"
run: |
Expand All @@ -89,17 +94,28 @@ jobs:
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
export ASDF_DIR="$HOME/.asdf"
. "$HOME/.asdf/asdf.sh"
asdf plugin add direnv
asdf plugin add nodejs
asdf plugin add python
asdf plugin add task
asdf plugin add yarn
asdf install
asdf info
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Activate direnv
run: |
set -ex
asdf direnv setup --shell bash --version latest
asdf current
asdf exec direnv allow
asdf exec direnv reload
asdf exec direnv exec . bash -c 'echo "VIRTUAL_ENV=${VIRTUAL_ENV}"' >> "$GITHUB_ENV"
asdf exec direnv exec . bash -c 'echo "${VIRTUAL_ENV}/bin"' >> "$GITHUB_PATH"
- name: Ensure virtualenv is active (direnv)
run: |
test "${VIRTUAL_ENV}" = "${HOME}/.local/share/virtualenvs/vsa"
test "$(which python3)" = "${HOME}/.local/share/virtualenvs/vsa/bin/python3"
- name: Enable caching
uses: actions/cache@v4
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
direnv 2.34.0
nodejs 18.19.1 20.11.1
task 3.33.1
yarn 1.22.19
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ env: &env
FORCE_COLOR: "true"
PRE_COMMIT_COLOR: always
# basically the same thing from .envrc file:
VIRTUAL_ENV: # "{{.VIRTUAL_ENV}}"
sh: echo "${VIRTUAL_ENV:-${PWD}/out/venvs/{{.HOSTNAME}}}"
VIRTUAL_ENV:
sh: echo "${HOME}/.local/share/virtualenvs/vsa"
vars:
HOSTNAME:
sh: echo ${HOSTNAME:-${HOST:-$(hostname)}}
Expand Down
12 changes: 0 additions & 12 deletions packages/ansible-language-server/.envrc

This file was deleted.

2 changes: 1 addition & 1 deletion packages/ansible-language-server/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"**/out/vscode-ansible": true
},
"explorerExclude.backup": null,
"python.defaultInterpreterPath": "${workspaceFolder}/out/venvs/${env:HOSTNAME}/bin/python",
"python.defaultInterpreterPath": "${userHome}/.local/share/virtualenvs/vsa/bin/python3",
"mypy.configFile": ".config/mypy.ini"
}
2 changes: 1 addition & 1 deletion packages/ansible-language-server/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vars:
EE_VERSION:
sh: ./tools/get-image-version
VIRTUAL_ENV:
sh: echo "${VIRTUAL_ENV:-${PWD}/out/venvs/${HOSTNAME:-localhost}}"
sh: echo "${HOME}/.local/share/virtualenvs/vsa"
tasks:
default:
desc: Run most commands
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if [[ "$(command -v npm || true)" == '/mnt/c/Program Files/nodejs/npm' ]]; then
fi

# if a virtualenv is already active, ensure is the expected one
EXPECTED_VENV="${PWD}/out/venvs/${HOSTNAME}"
EXPECTED_VENV="${HOME}/.local/share/virtualenvs/vsa"
if [[ -d "${VIRTUAL_ENV:-}" && "${VIRTUAL_ENV:-}" != "${EXPECTED_VENV}" ]]; then
log warning "Detected another virtualenv active ($VIRTUAL_ENV) than expected one, switching it to ${EXPECTED_VENV}"
fi
Expand Down
11 changes: 7 additions & 4 deletions tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ if [[ "$(command -v npm || true)" == '/mnt/c/Program Files/nodejs/npm' ]]; then
fi

# if a virtualenv is already active, ensure is the expected one
EXPECTED_VENV="${PWD}/out/venvs/${HOSTNAME}"
EXPECTED_VENV="${HOME}/.local/share/virtualenvs/vsa"
if [[ -d "${VIRTUAL_ENV:-}" && "${VIRTUAL_ENV:-}" != "${EXPECTED_VENV}" ]]; then
log warning "Detected another virtualenv active ($VIRTUAL_ENV) than expected one, switching it to ${EXPECTED_VENV}"
fi
Expand Down Expand Up @@ -354,8 +354,8 @@ if [[ "${DOCKER_VERSION}" != 'null' ]] && [[ "${SKIP_DOCKER:-}" != '1' ]]; then
exit 1
fi
log notice "Pull our test container image with docker."
docker pull --quiet "${IMAGE}" >/dev/null || {
log error "Failed to pull image, maybe current user is not in docker group? Run 'sudo usermod -aG docker $USER' and relogin to fix it."
pull_output=$(docker pull "${IMAGE}" 2>&1 >/dev/null) || {
log error "Failed to pull image, maybe current user is not in docker group? Run 'sudo usermod -aG docker $USER' and relogin to fix it.\n${pull_output}"
exit 1
}
# without running we will never be sure it works (no arm64 image yet)
Expand Down Expand Up @@ -413,7 +413,10 @@ fi
PODMAN_VERSION="$(get_version podman || echo null)"
if [[ "${PODMAN_VERSION}" != 'null' ]] && [[ "${SKIP_PODMAN:-}" != '1' ]]; then
log notice "Pull our test container image with podman."
podman pull --quiet "${IMAGE}" >/dev/null
pull_output=$(podman pull --quiet "${IMAGE}" 2>&1 >/dev/null) || {
log error "Failed to pull image.\n${pull_output}"
exit 1
}
# without running we will never be sure it works
log notice "Retrieving ansible version from ee"
EE_ANSIBLE_VERSION=$(get_version \
Expand Down

0 comments on commit 19d7d99

Please sign in to comment.