Skip to content

Commit

Permalink
Created developer setup (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
legovaer authored Aug 17, 2023
1 parent f56938e commit 6a0372d
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "diyHue Dev",
"context": "..",
"dockerFile": "../Dockerfile.dev",
"postCreateCommand": "script/setup",
"postStartCommand": "script/bootstrap",
"containerEnv": {
"DEVCONTAINER": "1"
},
"appPort": [
"8080:80"
],
"runArgs": [
"-e",
"GIT_EDITOR=code --wait"
],
"customizations": {
"vscode": {
"extensions": [
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github"
],
// Please keep this file in sync with settings in home-assistant/.vscode/settings.default.json
"settings": {
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.blackPath": "/usr/local/bin/black",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.formatting.provider": "black",
"python.testing.pytestArgs": [
"--no-cov"
],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"yaml.customTags": [
"!input scalar",
"!secret scalar",
"!include_dir_named scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar"
]
}
}
}
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "ms-python.python"]
}
9 changes: 9 additions & 0 deletions .vscode/settings.default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// Please keep this file in sync with settings in home-assistant/.devcontainer/devcontainer.json
"python.formatting.provider": "black",
// 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
}
47 changes: 47 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.11

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Uninstall pre-installed formatting and linting tools
# They would conflict with our pinned versions
RUN \
pipx uninstall black \
&& pipx uninstall pydocstyle \
&& pipx uninstall pycodestyle \
&& pipx uninstall mypy \
&& pipx uninstall pylint

RUN \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Additional library needed by some tests and accordingly by VScode Tests Discovery
bluez \
libudev-dev \
libavformat-dev \
libavcodec-dev \
libavdevice-dev \
libavutil-dev \
libswscale-dev \
libswresample-dev \
libavfilter-dev \
libpcap-dev \
libturbojpeg0 \
libyaml-dev \
libxml2 \
git \
cmake \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /workspaces

# Install Python dependencies from requirements
COPY requirements.txt script ./
RUN pip3 install -r requirements.txt
COPY requirements-test.txt ./
RUN pip3 install -r requirements-test.txt
RUN rm -rf requirements.txt requirements-test.txt

# Set the default shell to bash instead of sh
ENV SHELL /bin/bash
19 changes: 19 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
astral==2.2
ws4py==0.5.1
requests==2.20.0
paho-mqtt==1.6.1
email-validator==1.1.3
flask==2.0.3
flask_login==0.5.0
flask_restful==0.3.9
flask_wtf==1.0.0
jsonify==0.5
Werkzeug==2.0.3
WTForms==3.0.1
pyyaml==6.0.1
zeroconf==0.38.3
flask_cors==3.0.10
yeelight
python-kasa==0.4.1
bleak==0.14.3
rgbxy==0.5
12 changes: 12 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Resolve all dependencies that the application requires to run.

# Stop on errors
set -e

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

echo "Installing development dependencies..."
python3 -m pip install wheel --upgrade
python3 -m pip install colorlog pre-commit $(grep awesomeversion requirements.txt) --upgrade
python3 -m pip install -r requirements-test.txt --upgrade
23 changes: 23 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Setups the environment for the project (based on the setup script of home-assistant core)

# Stop on errors
set -e

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

# Add default vscode settings if not existing
SETTINGS_FILE=./.vscode/settings.json
SETTINGS_TEMPLATE_FILE=./.vscode/settings.default.json
if [ ! -f "$SETTINGS_FILE" ]; then
echo "Copy $SETTINGS_TEMPLATE_FILE to $SETTINGS_FILE."
cp "$SETTINGS_TEMPLATE_FILE" "$SETTINGS_FILE"
fi

mkdir -p config

if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ];then
python3 -m venv venv
source venv/bin/activate
fi

8 changes: 8 additions & 0 deletions script/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# Update application to run for its current checkout.

# Stop on errors
set -e

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

0 comments on commit 6a0372d

Please sign in to comment.