From a15a03531ce1a62b5eb5768446f67d7b4a8089a0 Mon Sep 17 00:00:00 2001 From: Ashley Gittins Date: Wed, 9 Aug 2023 20:14:16 +0000 Subject: [PATCH] Metahousekeeping - vscode, dev scripts --- .devcontainer.json | 42 ++++++++++++++++++++++++++++++++++++++++++ .vscode/launch.json | 2 +- .vscode/settings.json | 8 ++++++-- .vscode/tasks.json | 8 +++++++- CONTRIBUTING.md | 18 +++++------------- scripts/develop | 20 ++++++++++++++++++++ scripts/lint | 7 +++++++ scripts/setup | 12 ++++++++++++ scripts/test | 9 +++++++++ 9 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 .devcontainer.json create mode 100755 scripts/develop create mode 100755 scripts/lint create mode 100755 scripts/setup create mode 100755 scripts/test diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..b8f58ef --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,42 @@ +{ + "name": "ludeeus/integration_blueprint", + "image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.11", + "postCreateCommand": "scripts/setup", + "forwardPorts": [ + 8123 + ], + "portsAttributes": { + "8123": { + "label": "Home Assistant" + //"onAutoForward": "notify" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "github.vscode-pull-request-github", + "ryanluker.vscode-coverage-gutters", + "ms-python.vscode-pylance" + ], + "settings": { + "files.eol": "\n", + "editor.tabSize": 4, + "python.pythonPath": "/usr/bin/python3", + "python.analysis.autoSearchPaths": false, + //"python.linting.pylintEnabled": true, + //"python.linting.enabled": true, + //"python.formatting.provider": "black", + //"python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true + } + } + }, + "remoteUser": "vscode", + "features": { + "ghcr.io/devcontainers/features/rust:1": {} + } +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index cc5337a..27adb82 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -31,4 +31,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index a18dc56..bc29c3f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,9 @@ "python.pythonPath": "venv/bin/python", "files.associations": { "*.yaml": "home-assistant" - } -} + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 47f1210..f9c43f6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,12 @@ { "version": "2.0.0", "tasks": [ + { + "label": "Run Home Assistant using devscript on port 9123", + "type": "shell", + "command": "scripts/develop", + "problemMatcher": [] + }, { "label": "Run Home Assistant on port 9123", "type": "shell", @@ -26,4 +32,4 @@ "problemMatcher": [] } ] -} +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 079ffb3..3c33f8c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,25 +57,17 @@ This custom component is based on [integration_blueprint template](https://githu It comes with development environment in a container, easy to launch if you use Visual Studio Code. With this container you will have a stand alone Home Assistant instance running and already configured with the included -[`.devcontainer/configuration.yaml`](./.devcontainer/configuration.yaml) +[`.devcontainer.json`](./.devcontainer.json) file. You can use the `pre-commit` settings implemented in this repository to have -linting tool checking your contributions (see deicated section below). +linting tool checking your contributions (see dedicated section below). You should also verify that existing [tests](./tests) are still working and you are encouraged to add new ones. -You can run the tests using the following commands from the root folder: - -```bash -# Create a virtual environment -python3 -m venv venv -source venv/bin/activate -# Install requirements -pip install -r requirements_test.txt -# Run tests and get a summary of successes/failures and code coverage -pytest --durations=10 --cov-report term-missing --cov=custom_components.bermuda tests -``` +You can run the tests using the following command from the root folder: + +`./scripts/test` If any of the tests fail, make the necessary changes to the tests as part of your changes to the integration. diff --git a/scripts/develop b/scripts/develop new file mode 100755 index 0000000..20366e8 --- /dev/null +++ b/scripts/develop @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +# Create config dir if not present +if [[ ! -d "${PWD}/config" ]]; then + mkdir -p "${PWD}/config" + hass --config "${PWD}/config" --script ensure_config +fi + +# Set the path to custom_components +## This let's us have the structure we want /custom_components/integration_blueprint +## while at the same time have Home Assistant configuration inside /config +## without resulting to symlinks. +export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components" + +# Start Home Assistant +hass --config "${PWD}/config" --debug \ No newline at end of file diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..752d23a --- /dev/null +++ b/scripts/lint @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +ruff check . --fix \ No newline at end of file diff --git a/scripts/setup b/scripts/setup new file mode 100755 index 0000000..46be32f --- /dev/null +++ b/scripts/setup @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +# Seems to fix broken aiohttp wheel building in 3.11: +python3 -m pip install --upgrade setuptools wheel +# Fix urllib3 issue https://github.com/home-assistant/core/issues/95192 +python3 -m pip install git+https://github.com/boto/botocore + +python3 -m pip install --requirement requirements.txt \ No newline at end of file diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..bcda0d1 --- /dev/null +++ b/scripts/test @@ -0,0 +1,9 @@ +#!/bin/sh + +# Create a virtual environment +python3 -m venv venv +source venv/bin/activate +# Install requirements +pip install -r requirements_test.txt +# Run tests and get a summary of successes/failures and code coverage +pytest --durations=10 --cov-report term-missing --cov=custom_components.bermuda tests \ No newline at end of file