From 3d2313c1d1270462134bb78b7a51bcef6e31c9e5 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 31 Jul 2024 13:28:06 +0200 Subject: [PATCH 1/8] Follow beta/core with uv --- requirements_test.txt | 1 + scripts/tests_and_coverage.sh | 3 ++- tests/INIT.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements_test.txt b/requirements_test.txt index 2351f0dbf..ced39a9ec 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -6,3 +6,4 @@ radon==6.0.1 types-python-dateutil # Added for prettier nodeenv==1.9.1 +uv==0.2.32 diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 3b9eca688..b8dd17c9e 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -24,7 +24,8 @@ fi # Install/update dependencies pre-commit install pre-commit install-hooks -pip install -r requirements_test.txt -r requirements_commit.txt +pip install uv +uv pip install -r requirements_test.txt -r requirements_commit.txt set +u diff --git a/tests/INIT.md b/tests/INIT.md index a9c99b84f..089e0d8c9 100644 --- a/tests/INIT.md +++ b/tests/INIT.md @@ -27,7 +27,7 @@ Once the project is ready for upload to test (i.e. version number ending in `a0` Prepare: -- [ ] `python3 -m venv venv ; source venv/bin/activate ; pip install --upgrade pip; pip install -r requirements_test.txt ; pip install --upgrade setuptools wheel twine` +- [ ] `python3 -m venv venv ; source venv/bin/activate ; pip install --upgrade pip; pip install uv; uv pip install -r requirements_test.txt ; uv pip install --upgrade setuptools wheel twine` Package: (**ensure you are in your venv**) From c51bc7028e6f9495b198ff6b969173b4e336392d Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 31 Jul 2024 13:32:49 +0200 Subject: [PATCH 2/8] loosen restrictions --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index ced39a9ec..4c6ba10dc 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -6,4 +6,4 @@ radon==6.0.1 types-python-dateutil # Added for prettier nodeenv==1.9.1 -uv==0.2.32 +uv From f56fee4a23c856e4ddb97bed9a5b49ea5fca5ad6 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:26:18 +0200 Subject: [PATCH 3/8] Workaround for aiohttp --- patch/aiohttp310.patch | 19 +++++++++++++++++++ scripts/tests_and_coverage.sh | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 patch/aiohttp310.patch diff --git a/patch/aiohttp310.patch b/patch/aiohttp310.patch new file mode 100644 index 000000000..b67728026 --- /dev/null +++ b/patch/aiohttp310.patch @@ -0,0 +1,19 @@ +--- venv/lib/python3.12/site-packages/aiohttp/web_urldispatcher.py 2024-08-01 13:01:32 ++++ /tmp/web_urldispatcher.py 2024-08-01 22:37:19 +@@ -1132,15 +1132,7 @@ + def _get_resource_index_key(self, resource: AbstractResource) -> str: + """Return a key to index the resource in the resource index.""" + # strip at the first { to allow for variables +- #return resource.canonical.partition("{")[0].rstrip("/") or "/" +- if "{" in (index_key := resource.canonical): +- # strip at the first { to allow for variables, and than +- # rpartition at / to allow for variable parts in the path +- # For example if the canonical path is `/core/locations{tail:.*}` +- # the index key will be `/core` since index is based on the +- # url parts split by `/` +- index_key = index_key.partition("{")[0].rpartition("/")[0] +- return index_key.rstrip("/") or "/" ++ return resource.canonical.partition("{")[0].rstrip("/") or "/" + + def index_resource(self, resource: AbstractResource) -> None: + """Add a resource to the resource index.""" diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index b8dd17c9e..5c280a6c9 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -26,6 +26,8 @@ pre-commit install pre-commit install-hooks pip install uv uv pip install -r requirements_test.txt -r requirements_commit.txt +# TODO: Remove after update of aiohttp beyond 3.10.0 +uv pip show aiohttp | grep -q "Version: 3.10.0" && (grep -q "core.locations" venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py && echo " *** aiohttp already patched" || ( echo "Patching aiohttp 3.10.0 for tests"; patch -tRup0 venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py < patch/aiohttp310.patch && echo " *** aiohttp Patched!" || echo " *** aiohttp patch failed?")) || ( echo " ***"; echo " *** WE CAN REMOVE THE PATCH FOR aiohttp 3.10.0 from $0"; echo " ***" ) set +u From 6ad62a6bf34562c4f586eb2b292886efee520eca Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:28:30 +0200 Subject: [PATCH 4/8] Workaround for aiohttp --- scripts/tests_and_coverage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 5c280a6c9..6949bbe06 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -27,6 +27,7 @@ pre-commit install-hooks pip install uv uv pip install -r requirements_test.txt -r requirements_commit.txt # TODO: Remove after update of aiohttp beyond 3.10.0 +# shellcheck disable=SC2015 uv pip show aiohttp | grep -q "Version: 3.10.0" && (grep -q "core.locations" venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py && echo " *** aiohttp already patched" || ( echo "Patching aiohttp 3.10.0 for tests"; patch -tRup0 venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py < patch/aiohttp310.patch && echo " *** aiohttp Patched!" || echo " *** aiohttp patch failed?")) || ( echo " ***"; echo " *** WE CAN REMOVE THE PATCH FOR aiohttp 3.10.0 from $0"; echo " ***" ) set +u From 1febde8c68c6386fe07343b5ed17a9b74db3f205 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:36:39 +0200 Subject: [PATCH 5/8] Ruff no longer accepts just path --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index edc10bb31..0236e2fec 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -97,7 +97,7 @@ jobs: - name: Ruff (with fix) run: | . venv/bin/activate - ruff plugwise/*py tests/*py + ruff check --fix plugwise/*py tests/*py - name: If needed, commit ruff changes to the pull request if: failure() run: | From f55375fafa3015b04e424f64a1e7fdd895838af6 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:44:56 +0200 Subject: [PATCH 6/8] Include aiohttp patch in verify --- .github/workflows/verify.yml | 17 +++++++++++------ CHANGELOG.md | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 0236e2fec..3e849f11f 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -45,11 +45,14 @@ jobs: - name: Create Python virtual environment if: steps.cache-venv.outputs.cache-hit != 'true' run: | - pip install virtualenv --upgrade + pip install uv + uv pip install virtualenv --upgrade python -m venv venv . venv/bin/activate - pip install -U pip setuptools wheel - pip install -r requirements_test.txt -r requirements_commit.txt + uv pip install -U pip setuptools wheel + uv pip install -r requirements_test.txt -r requirements_commit.txt + # TODO: Remove after update of aiohttp beyond 3.10.0 + uv pip show aiohttp | grep -q "Version: 3.10.0" && (grep -q "core.locations" venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py && echo " *** aiohttp already patched" || ( echo "Patching aiohttp 3.10.0 for tests"; patch -tRup0 venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py < patch/aiohttp310.patch && echo " *** aiohttp Patched!" || echo " *** aiohttp patch failed?")) || ( echo " ***"; echo " *** WE CAN REMOVE THE PATCH FOR aiohttp 3.10.0 from $0"; echo " ***" ) - name: Restore pre-commit environment from cache id: cache-precommit uses: actions/cache@v4 @@ -194,11 +197,13 @@ jobs: run: | python -m venv venv . venv/bin/activate - pip install -U pip setuptools wheel + uv pip install -U pip setuptools wheel #pip install -r requirements_test.txt # 20220124 Mimic setup_test.sh - pip install --upgrade -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 - pip install --upgrade pytest-asyncio + uv pip install --upgrade -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 + uv pip install --upgrade pytest-asyncio + # TODO: Remove after update of aiohttp beyond 3.10.0 + uv pip show aiohttp | grep -q "Version: 3.10.0" && (grep -q "core.locations" venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py && echo " *** aiohttp already patched" || ( echo "Patching aiohttp 3.10.0 for tests"; patch -tRup0 venv/lib/python*/site-packages/aiohttp/web_urldispatcher.py < patch/aiohttp310.patch && echo " *** aiohttp Patched!" || echo " *** aiohttp patch failed?")) || ( echo " ***"; echo " *** WE CAN REMOVE THE PATCH FOR aiohttp 3.10.0 from $0"; echo " ***" ) pytest: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index f4fc193c5..a75e47820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## ongoing + +- Note2self; remove aiohttp 3.10 test fixing in scripts/* and verify workflow + ## v0.38.3 - Implement fix for Core Issue [#119686](https://github.com/home-assistant/core/issues/119686) From bea10faacc267e78fc96417da3a9e755809df6f3 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:50:09 +0200 Subject: [PATCH 7/8] Include aiohttp patch in verify --- .github/workflows/verify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 3e849f11f..e161edacf 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -45,10 +45,10 @@ jobs: - name: Create Python virtual environment if: steps.cache-venv.outputs.cache-hit != 'true' run: | - pip install uv - uv pip install virtualenv --upgrade + pip install virtualenv --upgrade python -m venv venv . venv/bin/activate + pip install uv uv pip install -U pip setuptools wheel uv pip install -r requirements_test.txt -r requirements_commit.txt # TODO: Remove after update of aiohttp beyond 3.10.0 From a55e70b6dd0c40da17b5eb751dd1f2e449b1f378 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 1 Aug 2024 23:53:34 +0200 Subject: [PATCH 8/8] Include aiohttp patch in verify --- .github/workflows/verify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index e161edacf..51886ba05 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -197,6 +197,7 @@ jobs: run: | python -m venv venv . venv/bin/activate + pip install uv uv pip install -U pip setuptools wheel #pip install -r requirements_test.txt # 20220124 Mimic setup_test.sh