diff options
author | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-10-11 11:15:35 +0200 |
---|---|---|
committer | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-10-17 14:39:47 +0200 |
commit | 323181d020508c71c715f27a7e7b218eedf3204b (patch) | |
tree | 88c72b61a7cea1bd9c7b2e6a732eb99bb5860a4f /scripts | |
parent | .gitlab-ci.manager.yml: install optional deps (diff) | |
download | knot-resolver-323181d020508c71c715f27a7e7b218eedf3204b.tar.xz knot-resolver-323181d020508c71c715f27a7e7b218eedf3204b.zip |
scripts/poe-tasks: separate lint from other check script
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/poe-tasks/check | 50 | ||||
-rwxr-xr-x | scripts/poe-tasks/format | 12 | ||||
-rwxr-xr-x | scripts/poe-tasks/lint | 26 | ||||
-rwxr-xr-x | scripts/poe-tasks/schema (renamed from scripts/poe-tasks/doc-schema) | 2 | ||||
-rw-r--r-- | scripts/poe-tasks/utils/_env.sh | 26 |
5 files changed, 68 insertions, 48 deletions
diff --git a/scripts/poe-tasks/check b/scripts/poe-tasks/check index 248890b7..76da1209 100755 --- a/scripts/poe-tasks/check +++ b/scripts/poe-tasks/check @@ -4,16 +4,6 @@ src_dir="$(dirname "$(realpath "$0")")" source $src_dir/utils/_env.sh -aggregate_rv=0 -function check_rv { - if test "$1" -eq 0; then - echo -e " ${green}OK${reset}" - else - echo -e " ${red}FAIL${reset}" - fi - aggregate_rv=$(( $aggregate_rv + $1 )) -} - # stop failing early, because we wouldn't do anything else than fail set +e @@ -24,36 +14,12 @@ check_rv $? echo # early exit when dependencies are not installed -if test "$aggregate_rv" -ne "0"; then +if test "$aggregated_rv" -ne "0"; then echo -e "${red}Dependencies are not properly installed. Run this command to fix it:${reset}" echo -e " ${red}poetry install${reset}" exit 1 fi -# check format using ruff -echo -e "${yellow}Code format checking using ruff...${reset}" -ruff format --check --diff python/knot_resolver tests/manager scripts/poe-tasks/utils/create_setup.py -check_rv $? -echo - -# check imports using ruff -echo -e "${yellow}Imports format checking using ruff...${reset}" -ruff check --select I python/knot_resolver tests/manager scripts/poe-tasks/utils/create_setup.py -check_rv $? -echo - -# check code with ruff -echo -e "${yellow}Code linting using ruff...${reset}" -ruff check python/knot_resolver tests/pytests -check_rv $? -echo - -# check types using mypy -echo -e "${yellow}Type checking using mypy...${reset}" -mypy python/knot_resolver -check_rv $? -echo - # check that setup.py is not behind pyproject.toml echo -e "${yellow}Checking setup.py${reset}" python scripts/poe-tasks/utils/create_setup.py | diff - setup.py @@ -76,17 +42,7 @@ check_rv $? echo # fancy messages at the end :) -if test "$aggregate_rv" -eq "0"; then - echo -e "${green}Everything looks great!${reset}" -else - echo -e "${red}Failure.${reset}" - echo -e "${red}These commands might help you:${reset}" - echo -e "${red}\tpoe format${reset}" - echo -e "${red}\tpoe gen-setuppy${reset}" - echo -e "${red}\tpoe gen-constantspy${reset}" - echo -e "${red}\tpoe doc-schema${reset}" - echo -e "${red}That's not great. Could you please fix that?${reset} 😲😟" -fi +fancy_message # exit with the aggregate return value -exit $aggregate_rv +exit $aggregated_rv diff --git a/scripts/poe-tasks/format b/scripts/poe-tasks/format index 61f73818..8a8554a5 100755 --- a/scripts/poe-tasks/format +++ b/scripts/poe-tasks/format @@ -7,7 +7,19 @@ source $src_dir/utils/_env.sh dirs="python/knot_resolver/ tests/manager scripts/poe-tasks/utils/create_setup.py" # sort python import +echo -e "${yellow}Sorting Python imports using ruff...${reset}" ruff check --select I --fix $dirs +check_rv $? +echo # format python code +echo -e "${yellow}Formatting Python code using ruff...${reset}" ruff format $dirs +check_rv $? +echo + +# fancy messages at the end :) +fancy_message + +# exit with the aggregate return value +exit $aggregated_rv diff --git a/scripts/poe-tasks/lint b/scripts/poe-tasks/lint new file mode 100755 index 00000000..32bbf10b --- /dev/null +++ b/scripts/poe-tasks/lint @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# ensure consistent behaviour +src_dir="$(dirname "$(realpath "$0")")" +source $src_dir/utils/_env.sh + +# stop failing early, because we wouldn't do anything else than fail +set +e + +# check code using ruff +echo -e "${yellow}Linting using ruff...${reset}" +ruff check python/knot_resolver tests/pytests +check_rv $? +echo + +# check types using mypy +echo -e "${yellow}Checking types using mypy...${reset}" +mypy python/knot_resolver +check_rv $? +echo + +# fancy messages at the end :) +fancy_message + +# exit with the aggregate return value +exit $aggregated_rv diff --git a/scripts/poe-tasks/doc-schema b/scripts/poe-tasks/schema index 33ea3bd6..eee4f125 100755 --- a/scripts/poe-tasks/doc-schema +++ b/scripts/poe-tasks/schema @@ -10,4 +10,4 @@ meson_setup_configure > /dev/null cp $build_dir/python/knot_resolver/constants.py $gitroot/python/knot_resolver/constants.py python -m knot_resolver.client schema > $schema_file -echo New configuration JSON schem saved to $schema_file
\ No newline at end of file +echo New JSON schema saved to $schema_file
\ No newline at end of file diff --git a/scripts/poe-tasks/utils/_env.sh b/scripts/poe-tasks/utils/_env.sh index 66cece83..30e07fc1 100644 --- a/scripts/poe-tasks/utils/_env.sh +++ b/scripts/poe-tasks/utils/_env.sh @@ -36,6 +36,9 @@ fi # update PATH with node_modules PATH="$PATH:$gitroot/node_modules/.bin" +# aggregated return value +aggregated_rv=0 + # fail even on unbound variables set -o nounset @@ -102,3 +105,26 @@ function ninja_dev_install { ninja -C $build_dev_dir ninja install -C $build_dev_dir } + +function check_rv { + if test "$1" -eq 0; then + echo -e " ${green}OK${reset}" + else + echo -e " ${red}FAIL${reset}" + fi + aggregated_rv=$(( $aggregated_rv + $1 )) +} + +function fancy_message { + if test "$aggregated_rv" -eq "0"; then + echo -e "${green}Everything looks great!${reset}" + else + echo -e "${red}Failure.${reset}" + echo -e "${red}These commands might help you:${reset}" + echo -e "${red}\tpoe format${reset}" + echo -e "${red}\tpoe gen-setuppy${reset}" + echo -e "${red}\tpoe gen-constantspy${reset}" + echo -e "${red}\tpoe gen-schema${reset}" + echo -e "${red}That's not great. Could you please fix that?${reset} 😲😟" + fi +} |