-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathdevenv.nix
106 lines (93 loc) · 2.84 KB
/
devenv.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
pkgs,
lib,
config,
...
}: {
name = "tech-controllers";
# https://devenv.sh/basics/
env = {
GREET = "tech-controllers devenv";
};
# https://devenv.sh/packages/
packages = [
pkgs.git
pkgs.ruff
pkgs.ffmpeg
];
# https://devenv.sh/languages/
languages.python = {
enable = true;
version = "3.12";
uv.enable = true;
venv.enable = true;
venv.requirements = builtins.readFile ./requirements.txt + "\n" + builtins.readFile ./requirements_test_api.txt;
};
# https://devenv.sh/scripts/
scripts.setup = {
exec = ''
echo '🛠️ Running setup'
python3 -m pip install --requirement requirements.txt --requirement requirements_test_api.txt
'';
description = "Install dependencies";
};
scripts.develop = {
exec = ''
# Create config dir if not present
if [[ ! -d "$PWD/config" ]]; then
mkdir -p "$PWD/config"
ln -s "$PWD/custom_components/" "$PWD/config/custom_components"
hass --config "$PWD/config" --script ensure_config
fi
if [ ! -L "$PWD/config/custom_components" ]; then
ln -s "$PWD/custom_components/" "$PWD/config/custom_components"
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
'';
description = "Start Home Assistant";
};
scripts.tests = {
exec = ''
echo '🧪 Running tests'
pytest tests/tests_api --cov-report=term-missing --cov=custom_components.tech.tech tests/
'';
description = "Test integration";
};
scripts.lint = {
exec = ''
echo '🚨 Run lint'
ruff check . --fix
'';
description = "Run lint";
};
enterShell = ''
echo Entering development environment for tech-controllers...
export PYTHONPATH="$PYTHONPATH:$PWD/custom_components"
echo $PYTHONPATH
echo
echo 🦾 Available scripts:
echo 🦾
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g'
${lib.generators.toKeyValue {} (lib.mapAttrs (name: value: value.description) config.scripts)}
EOF
echo
'';
tasks."app:setup" = {
exec = ''
echo '🛠️ Running setup'
python3 -m pip install --requirement requirements.txt --requirement requirements_test_api.txt
'';
after = ["devenv:enterShell"];
};
# https://devenv.sh/tests/
enterTest = ''
echo '🧪 Running tests'
pytest tests/tests_api --cov-report=term-missing --cov=custom_components.tech.tech tests/
'';
}