From 2c52659ccfda5600b965b42cf55c9a357e22ce5b Mon Sep 17 00:00:00 2001 From: Jonathan Leroy Date: Tue, 21 Oct 2025 21:34:16 +0200 Subject: [PATCH 1/3] Fix some bash scripts not working with custom VENV_NAME --- .git_hooks_pre-commit | 23 ++++++++++++----------- script/changelog | 18 +++++------------- script/common.sh | 27 +++++++++++++++++++++++++++ script/coverage | 19 +++++-------------- script/format | 7 ++++--- script/generate-docs | 20 +++++--------------- script/lint | 20 +++++--------------- script/release | 19 ++++--------------- script/test | 19 +++++-------------- 9 files changed, 72 insertions(+), 100 deletions(-) create mode 100644 script/common.sh diff --git a/.git_hooks_pre-commit b/.git_hooks_pre-commit index 3b5f6ac..cb9fe46 100755 --- a/.git_hooks_pre-commit +++ b/.git_hooks_pre-commit @@ -1,13 +1,14 @@ -#!/bin/sh +#!/bin/bash -set -e +# Scripts path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )/script" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" -HOOKS=$(dirname "$0") -GIT=$(dirname "$HOOKS") -ROOT=$(dirname "$GIT") - -. "$ROOT/env/bin/activate" -"$ROOT/script/changelog" check -"$ROOT/script/lint" -"$ROOT/script/format" --check --quiet || (echo "Formatting check failed, run ./script/format" && exit 1) -"$ROOT/script/coverage" +./script/changelog check +./script/lint +./script/format --check --quiet || ( + echo "Formatting check failed, run ./script/format" && + exit 1 +) +./script/coverage diff --git a/script/changelog b/script/changelog index f981f5a..5b4a296 100755 --- a/script/changelog +++ b/script/changelog @@ -1,16 +1,8 @@ -#!/bin/sh -set -e +#!/bin/bash -cd "$(dirname "$0")/.." -ROOT=$(pwd) - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi - -ACTIVATE="$VENV_NAME/bin/activate" -if [ -f "$ACTIVATE" ]; then - . "$ACTIVATE" -fi +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" changelet "$@" diff --git a/script/common.sh b/script/common.sh new file mode 100644 index 0000000..21a416d --- /dev/null +++ b/script/common.sh @@ -0,0 +1,27 @@ +# This script contains Python's venv management features common to all shell +# scripts located in this directory and to the repository pre-commit hook. +# This script is *not* meant to be run directly. + +# Exit on any error +set -e + +# Path to OctoDNS base directory +OCTODNS_PATH="$( dirname -- "${SCRIPT_PATH}"; )" + +# Change to path OctoDNS base directory +cd "$( dirname -- "${SCRIPT_PATH}"; )" + +# If no venv name is set, set it to "env" +if [ -z "${VENV_NAME}" ]; then + VENV_NAME="${OCTODNS_PATH}/env" +fi + +ACTIVATE="${VENV_NAME}/bin/activate" +# Check that [venv_directory]/bin/activate exists. +if [ ! -f "${ACTIVATE}" ]; then + echo "${ACTIVATE} does not exist. Run ./script/bootstrap" >&2 + exit 1 +fi + +# Activate OctoDNS venv. +source "${ACTIVATE}" diff --git a/script/coverage b/script/coverage index 914a042..ce903e9 100755 --- a/script/coverage +++ b/script/coverage @@ -1,18 +1,9 @@ -#!/bin/sh -set -e +#!/bin/bash -cd "$(dirname "$0")/.." - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi - -ACTIVATE="$VENV_NAME/bin/activate" -if [ ! -f "$ACTIVATE" ]; then - echo "$ACTIVATE does not exist, run ./script/bootstrap" >&2 - exit 1 -fi -. "$ACTIVATE" +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" # Just to be sure/safe export AWS_ACCESS_KEY_ID= diff --git a/script/format b/script/format index a0d3499..4a7229b 100755 --- a/script/format +++ b/script/format @@ -1,10 +1,11 @@ #!/bin/bash -set -e +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" SOURCES="$(find *.py octodns tests docs -name '*.py') $(grep --files-with-matches '^#!.*python' script/*)" -. env/bin/activate - isort "$@" $SOURCES black "$@" $SOURCES diff --git a/script/generate-docs b/script/generate-docs index 8d73b76..51b5746 100755 --- a/script/generate-docs +++ b/script/generate-docs @@ -1,19 +1,9 @@ -#!/bin/sh -set -e +#!/bin/bash -cd "$(dirname "$0")/.." -ROOT=$(pwd) - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi - -ACTIVATE="$VENV_NAME/bin/activate" -if [ ! -f "$ACTIVATE" ]; then - echo "$ACTIVATE does not exist, run ./script/bootstrap" >&2 - exit 1 -fi -. "$ACTIVATE" +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" cd docs diff --git a/script/lint b/script/lint index f68f54d..cd42d3a 100755 --- a/script/lint +++ b/script/lint @@ -1,19 +1,9 @@ -#!/bin/sh -set -e +#!/bin/bash -cd "$(dirname "$0")/.." -ROOT=$(pwd) - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi - -ACTIVATE="$VENV_NAME/bin/activate" -if [ ! -f "$ACTIVATE" ]; then - echo "$ACTIVATE does not exist, run ./script/bootstrap" >&2 - exit 1 -fi -. "$ACTIVATE" +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" SOURCES="$(find *.py octodns tests docs -name '*.py') $(grep --files-with-matches '^#!.*python' script/*)" diff --git a/script/release b/script/release index 1fab0eb..f3c18a2 100755 --- a/script/release +++ b/script/release @@ -1,13 +1,9 @@ #!/bin/bash -set -e - -cd "$(dirname "$0")"/.. -ROOT=$(pwd) - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" PYPYRC="$HOME/.pypirc" if [ ! -e "$PYPYRC" ]; then @@ -22,13 +18,6 @@ EndOfMessage exit 1 fi -ACTIVATE="$VENV_NAME/bin/activate" -if [ ! -f "$ACTIVATE" ]; then - echo "$ACTIVATE does not exist, run ./script/bootstrap" >&2 - exit 1 -fi -. "$ACTIVATE" - # Set so that setup.py will create a public release style version number export OCTODNS_RELEASE=1 diff --git a/script/test b/script/test index f5e4d8e..2f0dc30 100755 --- a/script/test +++ b/script/test @@ -1,18 +1,9 @@ -#!/bin/sh -set -e +#!/bin/bash -cd "$(dirname "$0")/.." - -if [ -z "$VENV_NAME" ]; then - VENV_NAME="env" -fi - -ACTIVATE="$VENV_NAME/bin/activate" -if [ ! -f "$ACTIVATE" ]; then - echo "$ACTIVATE does not exist, run ./script/bootstrap" >&2 - exit 1 -fi -. "$ACTIVATE" +# Get current script path +SCRIPT_PATH="$( dirname -- "$( readlink -f -- "${0}"; )"; )" +# Activate OctoDNS Python venv +source "${SCRIPT_PATH}/common.sh" # Just to be sure/safe export AWS_ACCESS_KEY_ID= From 85f72ad1bb6bf1ec74ae0c58fd36b63f1119c0a2 Mon Sep 17 00:00:00 2001 From: Jonathan Leroy Date: Tue, 21 Oct 2025 21:45:33 +0200 Subject: [PATCH 2/3] Add chengelog and remove duplicate call to dirname --- .changelog/cbeaa629126c4d7bbb6f8b59e76b8835.md | 4 ++++ script/common.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .changelog/cbeaa629126c4d7bbb6f8b59e76b8835.md diff --git a/.changelog/cbeaa629126c4d7bbb6f8b59e76b8835.md b/.changelog/cbeaa629126c4d7bbb6f8b59e76b8835.md new file mode 100644 index 0000000..338be56 --- /dev/null +++ b/.changelog/cbeaa629126c4d7bbb6f8b59e76b8835.md @@ -0,0 +1,4 @@ +--- +type: none +--- +Fix venv activation not working when using a custom VENV_NAME \ No newline at end of file diff --git a/script/common.sh b/script/common.sh index 21a416d..6b57b34 100644 --- a/script/common.sh +++ b/script/common.sh @@ -9,7 +9,7 @@ set -e OCTODNS_PATH="$( dirname -- "${SCRIPT_PATH}"; )" # Change to path OctoDNS base directory -cd "$( dirname -- "${SCRIPT_PATH}"; )" +cd "${OCTODNS_PATH}" # If no venv name is set, set it to "env" if [ -z "${VENV_NAME}" ]; then From dba1eb7d27fb0e0507959791393b301e0465f12c Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Wed, 22 Oct 2025 15:27:48 -0700 Subject: [PATCH 3/3] Bootstrap during setup rather than manually install reqs --- .github/workflows/changelog.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 7dbc6c7..044ea29 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -15,10 +15,10 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: x64 - - name: Install dependencies + - name: Setup Environment run: | python -m pip install --upgrade pip - pip install -r requirements.txt -r requirements-dev.txt + ./script/bootstrap - name: Changelog Check run: | ./script/changelog check