Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New devcontainer #351

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "dev-easee",
"image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.11-bullseye",
"postCreateCommand": "scripts/setup",
"appPort": ["9125:8123"],
"portsAttributes": {
"8123": {
"label": "Home Assistant internal",
"onAutoForward": "notify"
},
"9124": {
"label": "Home Assistant remote",
"onAutoForward": "notify"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.black-formatter",
"thibault-vanderseypen.i18n-json-editor"
],
"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]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.formatting.provider": "none",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"[markdown]": {
"files.trimTrailingWhitespace": false
},
"i18nJsonEditor.forceKeyUPPERCASE": false,
"i18nJsonEditor.supportedFolders": ["translations", "i18n"]
}
}
},
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
}
}
1 change: 0 additions & 1 deletion .devcontainer/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions .devcontainer/configuration.yaml

This file was deleted.

56 changes: 0 additions & 56 deletions .devcontainer/devcontainer.json

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Home Assistant config
config/

#Links for local development
/__init__.py
/manifest.json
Expand Down
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: ruff
args:
- --fix
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args:
- --quiet
files: ^((custom_components|homeassistant|pylint|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
exclude: (.vscode|.devcontainer)
- id: pretty-format-json
args: ['--autofix', '--no-ensure-ascii', '--top-keys=domain,name']
files: manifest.json
- id: pretty-format-json
args: ['--autofix', '--no-ensure-ascii', '--top-keys=name']
files: hacs.json
- id: pretty-format-json
args: ['--autofix', '--no-ensure-ascii', '--no-sort-keys']
files: (/strings\.json$|translations/.+\.json$)
- id: check-yaml
args: ['--unsafe']
- id: check-added-large-files
- id: check-shebang-scripts-are-executable
110 changes: 110 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py310"

select = [
"B002", # Python does not support the unary prefix increment
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"B023", # Function definition does not bind loop variable {name}
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
"C", # complexity
"COM818", # Trailing comma on bare tuple prohibited
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"G", # flake8-logging-format
"I", # isort
"ICN001", # import concentions; {name} should be imported as {asname}
"ISC001", # Implicitly concatenated string literals on one line
"N804", # First argument of a class method should be named cls
"N805", # First argument of a method should be named self
"N815", # Variable {name} in class scope should not be mixedCase
"PGH001", # No builtin eval() allowed
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"PLC", # pylint
"PLE", # pylint
"PLR", # pylint
"PLW", # pylint
"Q000", # Double quotes found but single quotes preferred
"RUF006", # Store a reference to the return value of asyncio.create_task
"S102", # Use of exec detected
"S103", # bad-file-permissions
"S108", # hardcoded-temp-file
"S306", # suspicious-mktemp-usage
"S307", # suspicious-eval-usage
"S313", # suspicious-xmlc-element-tree-usage
"S314", # suspicious-xml-element-tree-usage
"S315", # suspicious-xml-expat-reader-usage
"S316", # suspicious-xml-expat-builder-usage
"S317", # suspicious-xml-sax-usage
"S318", # suspicious-xml-mini-dom-usage
"S319", # suspicious-xml-pull-dom-usage
"S320", # suspicious-xmle-tree-usage
"S601", # paramiko-call
"S602", # subprocess-popen-with-shell-equals-true
"S604", # call-with-shell-equals-true
"S608", # hardcoded-sql-expression
"S609", # unix-command-wildcard-injection
"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}
"SIM208", # Use {expr} instead of not (not {expr})
"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
"T100", # Trace found: {name} used
"T20", # flake8-print
"TID251", # Banned imports
"TRY004", # Prefer TypeError exception for invalid type
"TRY200", # Use raise from to specify exception cause
"TRY302", # Remove exception handler; error is immediately re-raised
"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
"D406", # Section name should end with a newline
"D407", # Section name underlining
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
"PLC1901", # Lots of false positives
# False positives https://github.com/astral-sh/ruff/issues/5386
"PLC0208", # Use a sequence type instead of a `set` when iterating over values
"PLR0911", # Too many return statements ({returns} > {max_returns})
"PLR0912", # Too many branches ({branches} > {max_branches})
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
"PLR0915", # Too many statements ({statements} > {max_statements})
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
"UP006", # keep type annotation style as is
"UP007", # keep type annotation style as is
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`

]

[flake8-import-conventions.extend-aliases]
voluptuous = "vol"
"homeassistant.helpers.area_registry" = "ar"
"homeassistant.helpers.config_validation" = "cv"
"homeassistant.helpers.device_registry" = "dr"
"homeassistant.helpers.entity_registry" = "er"
"homeassistant.helpers.issue_registry" = "ir"
"homeassistant.util.dt" = "dt_util"

[isort]
force-sort-within-sections = true
known-first-party = ["homeassistant"]
combine-as-imports = true

[flake8-pytest-style]
fixture-parentheses = false

[mccabe]
max-complexity = 25
12 changes: 0 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/usr/local/bin/python",
"files.associations": {
"*.yaml": "home-assistant"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
56 changes: 31 additions & 25 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 9125",
"type": "shell",
"command": "container start",
"problemMatcher": []
},
{
"label": "Run Home Assistant configuration against /config",
"type": "shell",
"command": "container check",
"problemMatcher": []
},
{
"label": "Upgrade Home Assistant to latest dev",
"type": "shell",
"command": "container install",
"problemMatcher": []
},
{
"label": "Install a specific version of Home Assistant",
"type": "shell",
"command": "container set-version",
"problemMatcher": []
}
{
"label": "Run Home Assistant on port 9125",
"type": "shell",
"command": "scripts/develop",
"problemMatcher": []
},
{
"label": "Upgrade Home Assistant to latest (beta)",
"type": "shell",
"command": "scripts/upgrade",
"problemMatcher": []
},
{
"label": "Load Home Assistant from github - dev branch",
"type": "shell",
"command": "scripts/dev-branch",
"problemMatcher": []
},
{
"label": "Load specific version of Home Assistant",
"type": "shell",
"command": "scripts/specific-version",
"problemMatcher": []
},
{
"label": "Lint with ruff",
"type": "shell",
"command": "scripts/lint",
"problemMatcher": []
}
]
}
}
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ bump:
bump2version --allow-dirty --current-version $(__VERSION__) patch Makefile custom_components/easee/const.py custom_components/easee/manifest.json

lint:
isort custom_components
black custom_components
flake8 custom_components
ruff check custom_components --fix

install_dev:
pip install -r requirements-dev.txt
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,9 @@ logger:
## Development Container
One option for development is to use the VS Code Dev Container. You need to have Docker installed.

1. For best performance, make sure to clone the repo in WSL2 if running on Windows.

```console
$ git clone https://github.com/{your_user}/easee_hass
$ mkdir easee_hass_config
```
1. Open the repository in VS Code.

```console
$ code easee_hass
```
1. VS Code will ask to reopen the folder in a container
- If not, press `Ctrl`+`Shift`+`P` and select `Dev Containers: Reopen in Dev Container`.
1. Open a new blank vscode
1. Select Command palette->Dev containers: Clone repository in named container volume
1. Follow the prompts
1. Wait for the container to be built.
1. Press `Ctrl`+`Shift`+`P` and select `Tasks: Run Task` > `Run Home Assistant on port 9125`.
1. Wait for Home Assistant to start and go to http://localhost:9125/.
Expand Down
6 changes: 2 additions & 4 deletions requirements-devcontainer.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
colorlog
black
isort
flake8
colorlog==6.7.0
ruff==0.0.288
bump2version
wheel

Expand Down
Loading
Loading