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

Implementazione DevContainer per VSCode #55

Merged
merged 4 commits into from
Oct 26, 2024
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
62 changes: 62 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "Home Assistant Integration Dev",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"postCreateCommand": ".devcontainer/scripts/setup",
"containerEnv": {
"PYTHONASYNCIODEBUG": "1"
},
"runArgs": ["-e", "GIT_EDITOR=code --wait"],
"forwardPorts": [
8123
],
"portsAttributes": {
"8123": {
"label": "Home Assistant",
"onAutoForward": "notify"
}
},
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"github.vscode-pull-request-github",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"ryanluker.vscode-coverage-gutters",
"thibault-vanderseypen.i18n-json-editor"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"pylint.importStrategy": "fromEnvironment",
//"python.pythonPath": "/usr/local/bin/python3",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.analysis.autoSearchPaths": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
},
"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": {}
//"ghcr.io/devcontainers-contrib/features/ffmpeg-apt-get:1": {}
}
}
7 changes: 7 additions & 0 deletions .devcontainer/scripts/dev-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

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

uv pip install --system --prefix "/home/vscode/.local/" --upgrade git+https://github.com/home-assistant/home-assistant.git@dev
35 changes: 35 additions & 0 deletions .devcontainer/scripts/develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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
if ! grep -R "^logger:" config/configuration.yaml >> /dev/null;then
echo -n "
logger:
default: info
logs:
homeassistant.components.viva: debug
" >> config/configuration.yaml
fi
if ! grep -R "debugpy:" config/configuration.yaml >> /dev/null;then
echo "
# Uncomment the line below if you want to use debugger
# debugpy:
" >> config/configuration.yaml
fi


# Set the path to custom_components
## This let's us have the structure we want <root>/custom_components/ake_dev
## 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
8 changes: 8 additions & 0 deletions .devcontainer/scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

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

#ruff format .
ruff check . --fix
28 changes: 28 additions & 0 deletions .devcontainer/scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e

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

# Install libpcap and libturbojpeg to avoid errors in Home Assistant
sudo apt-get update
sudo apt-get install -y libpcap-dev libturbojpeg0

# Install uv
python3 -m pip install uv --user --disable-pip-version-check

# Install Home Assistant dependencies
uv pip install --system --prefix "/home/vscode/.local/" --requirement requirements_ha.txt

# Install custom_component dependencies
uv pip install --system --prefix "/home/vscode/.local/" --requirement requirements.txt

# Set workspace directory as safe in git
git config --global --add safe.directory ${PWD}
#pre-commit install

# Restart Python Language Server in VSCode to see the correct linting
echo "*********************************************"
echo "* To fix linting in VSCode, press F1 and *"
echo "* choose 'Python: Restart Language Server' *"
echo "*********************************************"
8 changes: 8 additions & 0 deletions .devcontainer/scripts/specific-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

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

read -p 'Set Home Assistant version: ' -r version
uv pip install --system --prefix "/home/vscode/.local/" --upgrade homeassistant=="$version"
7 changes: 7 additions & 0 deletions .devcontainer/scripts/upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

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

uv pip install --system --prefix "/home/vscode/.local/" --upgrade --prerelease allow homeassistant
132 changes: 131 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,133 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
.idea/
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Home Assistant Config
/config/*
!/config/configuration.yaml
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
files: ^((homeassistant|custom_components|pylint|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.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
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"ms-python.python"
]
}
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Home Assistant",
"type": "debugpy",
"request": "launch",
"module": "homeassistant",
"justMyCode": false,
"args": [
"--debug",
"-c",
"config"
],
},
/*
{
// Example of attaching to local debug server
"name": "Python: Attach Local",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
// Example of attaching to my production server
"name": "Python: Attach Remote",
"type": "python",
"request": "attach",
"port": 5678,
"host": "homeassistant.local",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
]
}
*/
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// Please keep this file in sync with settings in home-assistant/.devcontainer/devcontainer.json
// Added --no-cov to work around TypeError: message must be set
// https://github.com/microsoft/vscode-python/issues/14067
"python.testing.pytestArgs": ["--no-cov"],
// https://code.visualstudio.com/docs/python/testing#_pytest-configuration-settings
"python.testing.pytestEnabled": false,
// https://code.visualstudio.com/docs/python/linting#_general-settings
"pylint.importStrategy": "fromEnvironment"
}
Loading