11#! /usr/bin/env bash
22set -e
33
4+ # By default assumes running against 'master' branch of Core-HA
5+ # as requested by @bouwew for on-par development with the releases
6+ # version of HA
7+ #
8+ # Override by setting HABRANCH environment variable to run against
9+ # a different branch of core
10+ #
11+ # Github flows are run against both 'dev' and 'master'
12+ core_branch=" master"
13+ if [ " x${BRANCH} " != " x" ]; then
14+ core_branch=" ${BRANCH} "
15+ fi
16+ echo " Working on HA-core branch ${core_branch} "
17+
418# If you want full pytest output run as
519# DEBUG=1 scripts/core-testing.sh
620
@@ -26,7 +40,7 @@ which git || ( echo "You should have git installed, exiting"; exit 1)
2640
2741which jq || ( echo " You should have jq installed, exiting" ; exit 1)
2842
29- # Cloned/adjusted code from python- plugwise-usb , note that we don't actually
43+ # Cloned/adjusted code from plugwise-beta , note that we don't actually
3044# use the 'venv', but instantiate it to ensure it works in the
3145# ha-core testing later on
3246
@@ -37,41 +51,16 @@ which jq || ( echo "You should have jq installed, exiting"; exit 1)
3751# - quality
3852
3953
40- pyversions=(" 3.11" " 3.10" 3.9 dummy)
4154my_path=$( git rev-parse --show-toplevel)
42- my_venv=${my_path} /venv
43-
44- if [ -z " ${GITHUB_ACTIONS} " ] ; then
45- # Ensures a python virtualenv is available at the highest available python3 version
46- for pv in " ${pyversions[@]} ;" ; do
47- if [ " $( which " python$pv " ) " ]; then
48- # If not (yet) available instantiate python virtualenv
49- if [ ! -d " ${my_venv} " ]; then
50- " python${pv} " -m venv " ${my_venv} "
51- # Ensure wheel is installed (preventing local issues)
52- # shellcheck disable=SC1091
53- . " ${my_venv} /bin/activate"
54- fi
55- break
56- fi
57- done
58-
59- # shellcheck source=/dev/null
60- . " ${my_venv} /bin/activate"
61- # shellcheck disable=2145
62- which python3 || ( echo " You should have python3 (${pyversions[@]} ) installed, or change the script yourself, exiting" ; exit 1)
63- python3 --version
6455
65- # Failsafe
66- if [ ! -d " ${my_venv} " ]; then
67- echo " Unable to instantiate venv, check your base python3 version and if you have python3-venv installed"
68- exit 1
69- fi
70- # /Cloned code
71- fi
56+ # Ensure environment is set-up
57+ # shellcheck disable=SC1091
58+ source " ${my_path} /scripts/setup.sh"
59+ # shellcheck disable=SC1091
60+ source " ${my_path} /scripts/python-venv.sh"
7261
73- # Skip targeting for github
7462# i.e. args used for functions, not directions
63+ set +u
7564if [ -z " ${GITHUB_ACTIONS} " ] ; then
7665 # Handle variables
7766 subject=" "
8675
8776# Ensure ha-core exists
8877coredir=" ${my_path} /ha-core/"
78+ manualdir=" ${my_path} /manual_clone_ha/"
8979mkdir -p " ${coredir} "
9080
81+ set +u
9182if [ -z " ${GITHUB_ACTIONS} " ] || [ " $1 " == " core_prep" ] ; then
9283 # If only dir exists, but not cloned yet
9384 if [ ! -f " ${coredir} /requirements_test_all.txt" ]; then
@@ -120,49 +111,44 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "core_prep" ] ; then
120111 fi
121112 cd " ${coredir} " || exit
122113 echo " "
123- echo " ** Resetting to dev **"
124- echo " "
125114 git config pull.rebase true
126- git checkout dev
127- echo " "
128- echo " ** Running setup script from HA core **"
129- echo " "
130- if [ -z " ${GITHUB_ACTIONS} " ] ; then
131- # shellcheck source=/dev/null
132- . " ${my_path} /venv/bin/activate"
133- python3 -m venv venv
134- fi
135- python3 -m pip install --upgrade pip
136- # Not a typo, core setup script resets back to pip 20.3
137- script/setup || python3 -m pip install --upgrade pip
138- if [ -z " ${GITHUB_ACTIONS} " ] ; then
139- # shellcheck source=/dev/null
140- . venv/bin/activate
141- fi
142- echo " "
143- echo " ** Installing test requirements **"
144- echo " "
145- pip install --upgrade -r requirements_test.txt
115+ echo " ** Resetting to ${core_branch} (just cloned) **"
116+ git reset --hard || echo " - Should have nothing to reset to after cloning"
117+ git checkout " ${core_branch} "
146118 else
147119 cd " ${coredir} " || exit
148120 echo " "
149121 echo " ** Resetting/rebasing core (reusing clone)**"
150122 echo " "
151- # Always start from dev , dropping any leftovers
123+ # Always start from ${core_branch} , dropping any leftovers
152124 git stash || echo " - Nothing to stash"
153- git stash drop -q || echo " - Nothing in stash"
154- git checkout dev || echo " - Already in dev-branch"
125+ git stash drop -q || echo " - Nothing to stash drop"
126+ git clean -nfd || echo " - Nothing to clean up (show/dry-run)"
127+ git clean -fd || echo " - Nothing to clean up (clean)"
128+ git checkout " ${core_branch} " || echo " - Already in ${core_branch} -branch"
155129 git branch -D fake_branch || echo " - No fake_branch to delete"
156130 # Force pull
157131 git config pull.rebase true
158132 git reset --hard
159133 git pull
160134 fi
135+ cd " ${coredir} " || exit
161136 # Add tracker
162137 git log -1 | head -1 > " ${coredir} /.git/plugwise_usb-tracking"
163138 # Fake branch
164139 git checkout -b fake_branch
165140
141+ echo " "
142+ echo " Ensure HA-core venv"
143+ # shellcheck disable=SC1091
144+ source " ${my_path} /scripts/python-venv.sh"
145+ # shellcheck disable=SC1091
146+ source ./venv/bin/activate
147+
148+ echo " Bootstrap pip parts of HA-core"
149+ grep -v " ^#" " ${coredir} /script/bootstrap" | grep " pip install" | sed ' s/python3 -m pip install/uv pip install/g' | sh
150+ uv pip install -e . --config-settings editable_mode=compat --constraint homeassistant/package_constraints.txt
151+
166152 echo " "
167153 echo " Cleaning existing plugwise_usb from HA core"
168154 echo " "
@@ -180,60 +166,78 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "core_prep" ] ; then
180166 echo " "
181167fi # core_prep
182168
169+ set +u
183170if [ -z " ${GITHUB_ACTIONS} " ] || [ " $1 " == " pip_prep" ] ; then
184171 cd " ${coredir} " || exit
185- if [ -z " ${GITHUB_ACTIONS} " ] ; then
186- echo " Activating venv and installing selected test modules (pyserial, etc)"
187- echo " "
188- # shellcheck source=/dev/null
189- . venv/bin/activate
190- echo " "
191- fi
192- python3 -m pip install -q --upgrade pip
172+ echo " "
173+ echo " Ensure HA-core venv"
174+ # shellcheck disable=SC1091
175+ source " ./venv/bin/activate"
193176 mkdir -p ./tmp
194177 echo " "
195- echo " Installing pip modules"
178+ echo " Ensure translations are there"
179+ echo " "
180+ python3 -m script.translations develop --all > /dev/null 2>&1
181+ echo " "
182+ echo " Ensure uv is there"
183+ echo " "
184+ python3 -m pip install pip uv
185+ echo " Installing pip modules (using uv)"
196186 echo " "
197187 echo " - HA requirements (core and test)"
198- pip install --upgrade -q --disable-pip-version-check -r requirements.txt -r requirements_test.txt
188+ uv pip install --upgrade -r requirements.txt -r requirements_test.txt
199189 grep -hEi " ${pip_packages} " requirements_test_all.txt > ./tmp/requirements_test_extra.txt
200190 echo " - extra's required for plugwise_usb"
201- pip install --upgrade -q --disable-pip-version-check -r ./tmp/requirements_test_extra.txt
191+ uv pip install --upgrade -r ./tmp/requirements_test_extra.txt
192+ echo " - home assistant basics"
193+ uv pip install -e . --config-settings editable_mode=compat --constraint homeassistant/package_constraints.txt
202194 echo " "
203195 # When using test.py prettier makes multi-line, so use jq
204196 # module=$(grep require ../custom_components/plugwise_usb/manifest.json | cut -f 4 -d '"')
205197 module=$( jq ' .requirements[]' ../custom_components/plugwise_usb/manifest.json | tr -d ' "' )
206198 echo " Checking manifest for current python-plugwise-usb to install: ${module} "
207199 echo " "
208- pip install --upgrade -q --disable-pip-version-check " ${module} "
200+ uv pip install --upgrade " ${module} "
209201fi # pip_prep
210202
211203if [ -z " ${GITHUB_ACTIONS} " ] || [ " $1 " == " testing" ] ; then
204+ set +u
212205 cd " ${coredir} " || exit
213206 echo " "
207+ echo " Ensure HA-core venv"
208+ # shellcheck disable=SC1091
209+ source " ./venv/bin/activate"
210+ echo " "
214211 echo " Test commencing ..."
215212 echo " "
216213 debug_params=" "
217214 if [ ! " ${DEBUG} " == " " ] ; then
218215 debug_params=" -rpP --log-cli-level=DEBUG"
219216 fi
220217 # shellcheck disable=SC2086
221- pytest ${debug_params} ${subject} -- cov=homeassistant/components/plugwise_usb/ --cov-report term-missing -- " tests/components/plugwise_usb/ ${basedir} " || exit
218+ pytest ${debug_params} ${subject} tests/components/plugwise_usb/ ${basedir} --snapshot-update -- cov=homeassistant/components/plugwise_usb/ --cov-report term-missing || exit
222219fi # testing
223220
224221if [ -z " ${GITHUB_ACTIONS} " ] || [ " $1 " == " quality" ] ; then
225222 cd " ${coredir} " || exit
226223 echo " "
224+ echo " Ensure HA-core venv"
225+ # shellcheck disable=SC1091
226+ source " ./venv/bin/activate"
227+ echo " "
227228 set +e
228229 echo " ... ruff-ing component..."
229230 ruff check --fix homeassistant/components/plugwise_usb/* py || echo " Ruff applied autofixes"
230231 echo " ... ruff-ing tests..."
231232 ruff check --fix tests/components/plugwise_usb/* py || echo " Ruff applied autofixes"
232233 set -e
233- # echo "... black-ing ..."
234- # black homeassistant/components/plugwise_usb/*py tests/components/plugwise_usb/*py || exit
235- # echo "... mypy ..."
236- # script/run-in-env.sh mypy homeassistant/components/plugwise_usb/*.py || exit
234+ echo " ***"
235+ echo " ***"
236+ echo " ... mypy ..."
237+ # script/run-in-env.sh mypy homeassistant/components/plugwise_usb/*.py || exit
238+ echo " NOT RUNNING MYPY (i.e. not up to par any longer)"
239+ echo " ***"
240+ echo " ***"
237241 cd ..
238242 echo " ... markdownlint ..."
239243 pre-commit run --all-files --hook-stage manual markdownlint
@@ -244,6 +248,10 @@ fi # quality
244248if [ -z " ${GITHUB_ACTIONS} " ]; then
245249 cd " ${coredir} " || exit
246250 echo " "
251+ echo " Ensure HA-core venv"
252+ # shellcheck disable=SC1091
253+ source " ./venv/bin/activate"
254+ echo " "
247255 echo " Copy back modified files ..."
248256 echo " "
249257 cp -r ./homeassistant/components/plugwise_usb ../custom_components/
@@ -260,11 +268,13 @@ if [ -z "${GITHUB_ACTIONS}" ]; then
260268 sed -i" .sedbck" ' s/http.*test-files.pythonhosted.*#//g' ./homeassistant/components/plugwise_usb/manifest.json
261269 )
262270
263- # Hassfest already runs on Github
264- if [ -n " ${GITHUB_ACTIONS} " ] ; then
265- echo -e " ${CINFO} Running hassfest for plugwise${CNORM} "
266- python3 -m script.hassfest --requirements --action validate
267- fi
271+ # Hassfest already runs on Github
272+ if [ -n " ${GITHUB_ACTIONS} " ] ; then
273+ echo " Running hassfest for plugwise_usb"
274+ # 20240804 Apparently running --requirements in hassfest now checks 'all'? (Or at least a lot and it takes a lot of time)
275+ # python3 -m script.hassfest --requirements --action validate
276+ python3 -m script.hassfest --action validate
277+ fi
268278fi
269279
270280# pylint was removed from 'quality' some time ago
0 commit comments