Skip to content

Commit

Permalink
Metahousekeeping - vscode, dev scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
agittins committed Aug 9, 2023
1 parent bbab6b9 commit a15a035
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 17 deletions.
42 changes: 42 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
]
}
]
}
}
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 7 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -26,4 +32,4 @@
"problemMatcher": []
}
]
}
}
18 changes: 5 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions scripts/develop
Original file line number Diff line number Diff line change
@@ -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 <root>/custom_components/integration_blueprint
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

# Start Home Assistant
hass --config "${PWD}/config" --debug
7 changes: 7 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

ruff check . --fix
12 changes: 12 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a15a035

Please sign in to comment.