Skip to content

Commit 6051507

Browse files
committed
Update from python-plugwise script
1 parent 856c279 commit 6051507

File tree

1 file changed

+60
-19
lines changed

1 file changed

+60
-19
lines changed

scripts/tests_and_coverage.sh

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
11
#!/usr/bin/env bash
2+
# 20250613 Copied from HA-Core: run-in-env.sh
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-
if [ ! "$(which pytest)" ]; then
14-
echo "Unable to find pytest, run setup_test.sh before this script"
15-
exit 1
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"
20+
# other common virtualenvs
21+
my_path=$(git rev-parse --show-toplevel)
22+
23+
for venv in venv .venv .; do
24+
if [ -f "${my_path}/${venv}/bin/activate" ]; then
25+
# shellcheck disable=SC1090 # ingesting virtualenv
26+
. "${my_path}/${venv}/bin/activate"
27+
break
1628
fi
17-
else
18-
echo "Virtualenv available, bailing out"
19-
exit 2
29+
done
30+
fi
31+
32+
# 20250613 End of copy
33+
34+
if ! command -v pytest >/dev/null; then
35+
echo "Unable to find pytest, run setup_test.sh before this script"
36+
exit 1
2037
fi
2138

39+
handle_command_error() {
40+
if [ $? -ne 0 ]; then
41+
echo "Error: $1 failed"
42+
exit 1
43+
fi
44+
}
45+
46+
biome_format() {
47+
./tmp/biome check plugwise_usb/ tests/ --files-ignore-unknown=true --no-errors-on-unmatched --indent-width=2 --indent-style=space --write
48+
handle_command_error "biome formatting"
49+
}
50+
51+
# Install/update dependencies
52+
pre-commit install
53+
pre-commit install-hooks
54+
uv pip install -r requirements_test.txt -r requirements_commit.txt
55+
2256
set +u
2357

2458
if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then
@@ -27,14 +61,21 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then
2761
fi
2862

2963
if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then
30-
# Black first to ensure nothings roughing up ruff
31-
echo "... black-ing ..."
32-
black plugwise_usb/ tests/
64+
echo "... biome-ing (prettier) ..."
65+
biome_format
3366

34-
# TODO: Skip ruff checks as there are too many for now (mainly missing docstrings)
35-
# echo "... ruff-ing ..."
36-
# ruff check --fix plugwise_usb/ tests/
67+
echo "... ruff checking ..."
68+
ruff check plugwise_usb/ tests/
69+
handle_command_error "ruff checking"
70+
echo "... ruff formatting ..."
71+
ruff format plugwise_usb/ tests/
72+
handle_command_error "ruff formatting"
3773

3874
echo "... pylint-ing ..."
3975
pylint plugwise_usb/ tests/
76+
handle_command_error "pylint validation"
77+
78+
echo "... mypy-ing ..."
79+
mypy plugwise_usb/
80+
handle_command_error "mypy validation"
4081
fi

0 commit comments

Comments
 (0)