Skip to content

Commit 856c279

Browse files
committed
Re-do python-plugwise scripts
1 parent a554655 commit 856c279

File tree

5 files changed

+103
-84
lines changed

5 files changed

+103
-84
lines changed

scripts/complexity.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ set -eu
33

44
my_path=$(git rev-parse --show-toplevel)
55

6-
# shellcheck disable=SC1091
7-
source "${my_path}/scripts/python-venv.sh"
8-
9-
# shellcheck disable=SC2154
10-
if [ -f "${my_venv}/bin/activate" ]; then
11-
# shellcheck disable=SC1091
12-
. "${my_venv}/bin/activate"
13-
echo "-----------------------------"
14-
echo "Running cyclomatic complexity"
15-
echo "-----------------------------"
16-
PYTHONPATH=$(pwd) radon cc plugwise/ tests/ -s -nc --no-assert
6+
if [ -n "${VIRTUAL_ENV-}" ] && [ -f "${VIRTUAL_ENV}/bin/activate" ]; then
7+
# shellcheck disable=SC1091 # ingesting virtualenv
8+
. "${VIRTUAL_ENV}/bin/activate"
179
else
18-
echo "Virtualenv available, bailing out"
19-
exit 2
10+
# other common virtualenvs
11+
my_path=$(git rev-parse --show-toplevel)
12+
13+
for venv in venv .venv .; do
14+
if [ -f "${my_path}/${venv}/bin/activate" ]; then
15+
# shellcheck disable=SC1090 # ingesting virtualenv
16+
. "${my_path}/${venv}/bin/activate"
17+
break
18+
fi
19+
done
2020
fi
21+
22+
echo "-----------------------------"
23+
echo "Running cyclomatic complexity"
24+
echo "-----------------------------"
25+
PYTHONPATH=$(pwd) radon cc plugwise/ tests/ -s -nc --no-assert

scripts/python-venv.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/run-in-env.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
2+
# 20250613 Copied from HA-Core (unchanged)
23
set -eu
34

4-
my_path=$(git rev-parse --show-toplevel)
5+
# Used in venv activate script.
6+
# Would be an error if undefined.
7+
OSTYPE="${OSTYPE-}"
58

6-
# shellcheck disable=SC1091
7-
. "${my_path}/scripts/python-venv.sh"
9+
# Activate pyenv and virtualenv if present, then run the specified command
810

9-
# shellcheck disable=SC2154
10-
if [ -f "${my_venv}/bin/activate" ]; then
11-
# shellcheck disable=SC1091
12-
. "${my_venv}/bin/activate"
13-
exec "$@"
11+
# pyenv, pyenv-virtualenv
12+
if [ -s .python-version ]; then
13+
PYENV_VERSION=$(head -n 1 .python-version)
14+
export PYENV_VERSION
15+
fi
16+
17+
if [ -n "${VIRTUAL_ENV-}" ] && [ -f "${VIRTUAL_ENV}/bin/activate" ]; then
18+
# shellcheck disable=SC1091 # ingesting virtualenv
19+
. "${VIRTUAL_ENV}/bin/activate"
1420
else
15-
echo "Virtualenv available, bailing out"
16-
exit 2
21+
# other common virtualenvs
22+
my_path=$(git rev-parse --show-toplevel)
23+
24+
for venv in venv .venv .; do
25+
if [ -f "${my_path}/${venv}/bin/activate" ]; then
26+
# shellcheck disable=SC1090 # ingesting virtualenv
27+
. "${my_path}/${venv}/bin/activate"
28+
break
29+
fi
30+
done
1731
fi
32+
33+
exec "$@"

scripts/setup.sh

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/usr/bin/env bash
2-
set -eu
2+
# 20250613 Copied from HA-core and shell-check adjusted and modified for local use
3+
set -e
34

4-
my_path=$(git rev-parse --show-toplevel)
5-
6-
# shellcheck disable=SC1091
7-
. "${my_path}/scripts/python-venv.sh"
5+
if [ -z "$VIRTUAL_ENV" ]; then
6+
if [ -x "$(command -v uv)" ]; then
7+
uv venv venv
8+
else
9+
python3 -m venv venv
10+
fi
11+
# shellcheck disable=SC1091 # ingesting virtualenv
12+
source venv/bin/activate
13+
fi
814

9-
# shellcheck disable=SC2154
10-
if [ -f "${my_venv}/bin/activate" ]; then
11-
# shellcheck disable=SC1091
12-
. "${my_venv}/bin/activate"
13-
# Install commit requirements
14-
pip install uv
15-
uv pip install wheel
16-
uv pip install --upgrade -e . -r requirements_commit.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
17-
# Install pre-commit hook
18-
"${my_venv}/bin/pre-commit" install
19-
else
20-
echo "Virtualenv available, bailing out"
21-
exit 2
15+
if ! [ -x "$(command -v uv)" ]; then
16+
python3 -m pip install uv
2217
fi
18+
19+
# Install commit requirements
20+
uv pip install --upgrade -e . -r requirements_commit.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
21+
22+
# Install pre-commit hook
23+
pre-commit install
24+

scripts/setup_test.sh

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
#!/usr/bin/env bash
2-
set -eu
2+
# 20250613 Copied from HA-core and shell-check adjusted and modified for local use
3+
set -e
34

45
my_path=$(git rev-parse --show-toplevel)
56

6-
# shellcheck disable=SC1091
7-
. "${my_path}/scripts/python-venv.sh"
8-
9-
# shellcheck disable=SC2154
10-
if [ -f "${my_venv}/bin/activate" ]; then
11-
# shellcheck disable=SC1091
12-
. "${my_venv}/bin/activate"
13-
# Install test requirements
14-
pip install uv
15-
uv pip install --upgrade -e . -r requirements_test.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
16-
# Install pre-commit hook
17-
"${my_venv}/bin/pre-commit" install
7+
if [ -z "$VIRTUAL_ENV" ]; then
8+
if [ -x "$(command -v uv)" ]; then
9+
uv venv venv
10+
else
11+
python3 -m venv venv
12+
fi
13+
# shellcheck disable=SC1091 # ingesting virtualenv
14+
source venv/bin/activate
15+
fi
16+
17+
if ! [ -x "$(command -v uv)" ]; then
18+
python3 -m pip install uv
19+
fi
20+
21+
mkdir -p ./tmp
22+
23+
# Install test requirements
24+
uv pip install --upgrade -e . -r requirements_test.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
25+
26+
# Prepare biomejs
27+
echo "Fetching/updating biome cli"
28+
if uname -a | grep -q arm64; then
29+
curl -sL "https://github.com/biomejs/biome/releases/latest/download/biome-darwin-arm64" -o "${my_path}/tmp/biome"
30+
elif uname -a | grep -q x86_64; then
31+
curl -sL "https://github.com/biomejs/biome/releases/latest/download/biome-linux-x64" -o "${my_path}/tmp/biome"
1832
else
19-
echo "Virtualenv available, bailing out"
20-
exit 2
33+
echo "Unable to determine processor and as such to install packaged biome cli version, bailing out"
34+
exit 2
2135
fi
36+
37+
# Make biome executable (if necessary)
38+
chmod +x "${my_path}/tmp/biome"
39+
40+
# Install pre-commit hook unless running from within pre-commit
41+
if [ "$#" -eq 0 ]; then
42+
pre-commit install
43+
fi
44+

0 commit comments

Comments
 (0)