Skip to content

Commit b0bc007

Browse files
committed
Biome fixes and prettier cleanup
1 parent bf9757c commit b0bc007

File tree

6 files changed

+41
-24
lines changed

6 files changed

+41
-24
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ venv
1414
*.sedbck
1515
tmp
1616
.mypy_cache
17-
node_modules/
18-
package-lock.json
1917
fixtures/updated/*/
18+
tmp

.pre-commit-config.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ci:
22
# Defer autoupdate to quarterly (there is no 'off' button) to have renovate pick up first
33
autoupdate_schedule: quarterly
4-
skip: [pylint, markdownlint, testing]
4+
skip: [setup, setup_test, pylint, markdownlint, testing]
55
submodules: true
66

77
default_language_version:
@@ -67,6 +67,14 @@ repos:
6767
# pyenv and/or virtualenv activated; it may not have been e.g. if
6868
# committing from a GUI tool that was not launched from an activated
6969
# shell.
70+
- id: setup
71+
name: Setup python
72+
entry: /usr/bin/env bash -c 'test -d ./venv || scripts/setup.sh'
73+
language: script
74+
- id: setup_tests
75+
name: Setup testing
76+
entry: /usr/bin/env bash -c 'test -f ./tmp/biome || scripts/setup_test.sh pre-commit'
77+
language: script
7078
- id: userdata
7179
name: userdata
7280
entry: scripts/pre-commit.sh
@@ -92,12 +100,10 @@ repos:
92100
entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" scripts/tests_and_coverage.sh test_and_coverage'
93101
language: script
94102
pass_filenames: false
95-
- repo: https://github.com/biomejs/pre-commit
96-
rev: v0.4.0
97-
hooks:
98-
- id: biome-lint
99-
additional_dependencies: ["@biomejs/[email protected]"]
100-
name: "Verifying/updating code with biome (improved prettier)"
103+
- id: biome
104+
name: "Local Linting - Biome"
105+
entry: ./tmp/biome check --staged --files-ignore-unknown=true --no-errors-on-unmatched
106+
language: script
101107
- repo: https://github.com/igorshubovych/markdownlint-cli
102108
rev: v0.41.0
103109
hooks:

scripts/python-venv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ my_path=$(git rev-parse --show-toplevel)
66
my_venv=${my_path}/venv
77

88
# Ensures a python virtualenv is available at the highest available python3 version
9-
for pv in "${pyversions[@]};"; do
9+
for pv in "${pyversions[@]}"; do
1010
if [ "$(which "python$pv")" ]; then
1111
# If not (yet) available instantiate python virtualenv
1212
if [ ! -d "${my_venv}" ]; then

scripts/setup.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ if [ -f "${my_venv}/bin/activate" ]; then
1313
. "${my_venv}/bin/activate"
1414
set -o nounset
1515
# Install commit requirements
16-
pip install wheel
17-
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
16+
pip install wheel uv
17+
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
1818
# Install pre-commit hook
1919
"${my_venv}/bin/pre-commit" install
20-
# Prepare node virtualenv and prettier
21-
nodeenv -p # Use node with existing python-virtual env
22-
npm install prettier
2320
else
2421
echo "Virtualenv available, bailing out"
2522
exit 2

scripts/setup_test.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@ if [ -f "${my_venv}/bin/activate" ]; then
1111
set +o nounset # Workaround https://github.com/pypa/virtualenv/issues/150 for nodeenv
1212
# shellcheck disable=SC1091
1313
. "${my_venv}/bin/activate"
14+
mkdir -p ./tmp
1415
set -o nounset
1516
# Install test requirements
16-
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
17-
# Install pre-commit hook
18-
"${my_venv}/bin/pre-commit" install
17+
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
18+
# Prepare biomejs
19+
echo "Fetching/updating biome cli"
20+
if uname -a | grep -q arm64; then
21+
curl -sL "https://github.com/biomejs/biome/releases/latest/download/biome-darwin-arm64" -o "${my_path}/tmp/biome"
22+
elif uname -a | grep -q x86_64; then
23+
curl -sL "https://github.com/biomejs/biome/releases/latest/download/biome-linux-x64" -o "${my_path}/tmp/biome"
24+
else
25+
echo "Unable to determine processor and as such to install packaged biome cli version, bailing out"
26+
exit 2
27+
fi
28+
29+
# Make biome executable (if necessary)
30+
chmod +x "${my_path}/tmp/biome"
31+
32+
# Install pre-commit hook unless running from within pre-commit
33+
if [ "$#" -eq 0 ]; then
34+
"${my_venv}/bin/pre-commit" install
35+
fi
1936
else
2037
echo "Virtualenv available, bailing out"
2138
exit 2

scripts/tests_and_coverage.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then
4343
pylint plugwise/ tests/
4444
fi
4545

46-
# As to not generated fixtures, leaving prettier to re-do them
46+
# As to not generated fixtures, leaving biome to re-do them
4747
# so no auto-generation during github run of testing
4848
# Creating todo #313 to 'gracefully' do this on merge on github action
4949
if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "fixtures" ] ; then
5050
echo "... crafting manual fixtures ..."
5151
PYTHONPATH=$(pwd) python3 scripts/manual_fixtures.py
52-
echo "... prettier-ing (fixtures and testdata) ..."
53-
npx prettier --write --list-different --ignore-unknown --log-level silent fixtures/ tests/data
54-
else
55-
echo "... prettier-ing (fixtures and testdata) ..."
56-
npx prettier --write --list-different --ignore-unknown --log-level silent fixtures/ tests/data
5752
fi
53+
echo "... biome-ing (fixtures and testdata) ..."
54+
./tmp/biome lint fixtures/ tests/data/
55+
#npx prettier --write --list-different --ignore-unknown --log-level silent fixtures/ tests/data

0 commit comments

Comments
 (0)