From 3773ab9e5dbaebb7d9d47cb765db58dc4e7f576c Mon Sep 17 00:00:00 2001 From: Muka Schultze Date: Tue, 16 Jan 2024 18:18:40 -0300 Subject: [PATCH] chore: setup devcontainer and linting --- .devcontainer.json | 40 ++++++++++++++++++++++++++++++++ .gitignore | 1 - .ruff.toml | 48 +++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 2 +- config/configuration.yaml | 8 +++++++ hacs.json | 6 +++-- requirements.txt | 4 ++++ scripts/develop | 20 ++++++++++++++++ scripts/lint | 7 ++++++ scripts/setup | 7 ++++++ 10 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 .devcontainer.json create mode 100644 .ruff.toml create mode 100644 config/configuration.yaml create mode 100644 requirements.txt create mode 100755 scripts/develop create mode 100755 scripts/lint create mode 100755 scripts/setup diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..0318f80 --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "mukaschultze/ha-must-inverter", + "image": "mcr.microsoft.com/devcontainers/python:3.11-bullseye", + "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": {} + } +} diff --git a/.gitignore b/.gitignore index 94fa16c..6501f93 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ __pycache__ # misc .coverage -.vscode coverage.xml diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..7a8331a --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,48 @@ +# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml + +target-version = "py310" + +select = [ + "B007", # Loop control variable {name} not used within loop body + "B014", # Exception handler with duplicate exception + "C", # complexity + "D", # docstrings + "E", # pycodestyle + "F", # pyflakes/autoflake + "ICN001", # import concentions; {name} should be imported as {asname} + "PGH004", # Use specific rule codes when using noqa + "PLC0414", # Useless import alias. Import alias does not rename original package. + "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass + "SIM117", # Merge with-statements that use the same scope + "SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys() + "SIM201", # Use {left} != {right} instead of not {left} == {right} + "SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a} + "SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'. + "SIM401", # Use get from dict with default instead of an if block + "T20", # flake8-print + "TRY004", # Prefer TypeError exception for invalid type + "RUF006", # Store a reference to the return value of asyncio.create_task + "UP", # pyupgrade + "W", # pycodestyle +] + +ignore = [ + "D202", # No blank lines allowed after function docstring + "D203", # 1 blank line required before class docstring + "D213", # Multi-line docstring summary should start at the second line + "D404", # First word of the docstring should not be This + "D406", # Section name should end with a newline + "D407", # Section name underlining + "D411", # Missing blank line before section + "E501", # line too long + "E731", # do not assign a lambda expression, use a def +] + +[flake8-pytest-style] +fixture-parentheses = false + +[pyupgrade] +keep-runtime-typing = true + +[mccabe] +max-complexity = 25 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 048ee0f..f8f51c6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "files.associations": { - "*.yaml": "home-assistant" + "configuration.yaml": "home-assistant" }, "python.analysis.diagnosticSeverityOverrides": { "reportShadowedImports": "none" diff --git a/config/configuration.yaml b/config/configuration.yaml new file mode 100644 index 0000000..8c0d4e4 --- /dev/null +++ b/config/configuration.yaml @@ -0,0 +1,8 @@ +# https://www.home-assistant.io/integrations/default_config/ +default_config: + +# https://www.home-assistant.io/integrations/logger/ +logger: + default: info + logs: + custom_components.integration_blueprint: debug diff --git a/hacs.json b/hacs.json index cddc6b0..b59ef74 100644 --- a/hacs.json +++ b/hacs.json @@ -1,6 +1,8 @@ { "name": "Must Inverter", - "content_in_root": false, + "filename": "must_inverter.zip", + "hide_default_branch": true, "homeassistant": "2024.1.3", - "render_readme": true + "render_readme": true, + "zip_release": true } diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c3aeb03 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +colorlog==6.7.0 +homeassistant==2024.1.3 +pip>=21.0,<23.2 +ruff==0.0.292 diff --git a/scripts/develop b/scripts/develop new file mode 100755 index 0000000..6e32012 --- /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/must_inverter +## 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 diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..9b5b1df --- /dev/null +++ b/scripts/lint @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +ruff check . --fix diff --git a/scripts/setup b/scripts/setup new file mode 100755 index 0000000..141d19f --- /dev/null +++ b/scripts/setup @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +python3 -m pip install --requirement requirements.txt