| 1 | #!/usr/bin/env bash |
| 2 | set -eo pipefail |
| 3 | |
| 4 | # Directory of *this* script |
| 5 | this_dir="$( cd "$( dirname "$0" )" && pwd )" |
| 6 | |
| 7 | # Base directory of repo |
| 8 | base_dir="$(realpath "${this_dir}/..")" |
| 9 | |
| 10 | # Path to virtual environment |
| 11 | : "${venv:=${base_dir}/venv}" |
| 12 | |
| 13 | if [ -d "${venv}" ]; then |
| 14 | # Activate virtual environment if available |
| 15 | source "${venv}/bin/activate" |
| 16 | fi |
| 17 | |
| 18 | intents_dir="${base_dir}/home_assistant_intents" |
| 19 | data_dir="${intents_dir}/data" |
| 20 | rm -rf "${data_dir}" |
| 21 | rm -rf "${base_dir}/dist" |
| 22 | |
| 23 | python3 "${base_dir}/script/merged_output.py" "${data_dir}" |
| 24 | python3 "${base_dir}/script/write_languages.py" "${data_dir}" > "${intents_dir}/languages.py" |
| 25 | python3 "${base_dir}/script/write_language_scores.py" "${base_dir}/intents" > "${intents_dir}/language_scores.json" |
| 26 | black "${intents_dir}/languages.py" |
| 27 | cd "${base_dir}" && python3 -m build |
| 28 | |
| 29 | # Sanity check |
| 30 | echo 'Running sanity check...' |
| 31 | latest_wheel="$(ls -t "${base_dir}/dist"/*.whl | head -n1)" |
| 32 | if [ -z "${latest_wheel}" ]; then |
| 33 | echo 'No wheel found in dist directory!' |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | test_dir="$(mktemp -d)" |
| 38 | trap 'rm -rf "${test_dir}"' EXIT |
| 39 | |
| 40 | python3 -m venv "${test_dir}" |
| 41 | test_python3="${test_dir}/bin/python3" |
| 42 | "${test_python3}" -m pip install pytest "${latest_wheel}" |
| 43 | "${test_python3}" -m pytest -vv "${base_dir}/tests/test_intents.py" |
| 44 | |
| 45 | echo "See: ${base_dir}/dist" |