]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
scripts/poe-tasks: separate lint from other check script
authorAleš Mrázek <ales.mrazek@nic.cz>
Fri, 11 Oct 2024 09:15:35 +0000 (11:15 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Thu, 17 Oct 2024 12:39:47 +0000 (14:39 +0200)
pyproject.toml
scripts/poe-tasks/check
scripts/poe-tasks/format
scripts/poe-tasks/lint [new file with mode: 0755]
scripts/poe-tasks/schema [moved from scripts/poe-tasks/doc-schema with 86% similarity]
scripts/poe-tasks/utils/_env.sh

index 261e239bf021b086fd834ea219512afb52503efa..5e659319fa53ffaac67c91115b865503a7f1c23f 100644 (file)
@@ -72,9 +72,10 @@ configure = { cmd = "scripts/poe-tasks/configure", help = "(Re)configure Meson b
 run = { cmd = "scripts/poe-tasks/run", help = "Run Knot Resolver" }
 run-debug = { cmd = "scripts/poe-tasks/run-debug", help = "Debug Knot Resolver with debugpy" }
 doc = { cmd = "scripts/poe-tasks/doc", help = "Create Knot Resolver HTML documentation" }
-doc-schema = { cmd = "scripts/poe-tasks/doc-schema", help = "Generate a JSON schema of the Knot Resolver configuration"}
+schema = { cmd = "scripts/poe-tasks/schema", help = "Generate a JSON schema of the Knot Resolver configuration"}
 test = { cmd = "scripts/poe-tasks/test", help = "Run pytest unit tests" }
-check = { cmd = "scripts/poe-tasks/check", help = "Check that all dependencies are installed and run static code analysis" }
+lint = { cmd = "scripts/poe-tasks/lint", help = "Run static code analysis (Ruff) and check typing (Mypy)" }
+check = { cmd = "scripts/poe-tasks/check", help = "Check that all dependencies are properly installed and generated files are not behind project." }
 examples = { cmd = "scripts/poe-tasks/examples", help = "Validate all configuration examples using 'kresctl validate' utility" }
 gen-constantspy = { cmd = "scripts/poe-tasks/gen-constantspy", help = "Generate 'constants.py' module using Meson configured options" }
 gen-setuppy = { cmd = "scripts/poe-tasks/gen-setuppy", help = "Generate 'setup.py' file for backwards compatibility" }
index 248890b764bc806567ea3c7b7be178e6e23a5946..76da1209a099e19f78776a2c10d91aa10dca4b5d 100755 (executable)
@@ -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
index 61f738189a0fda29988fadde7c604559c08a8715..8a8554a51fab69a7003fa5fe6deefb6ae5a2e869 100755 (executable)
@@ -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 (executable)
index 0000000..32bbf10
--- /dev/null
@@ -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
similarity index 86%
rename from scripts/poe-tasks/doc-schema
rename to scripts/poe-tasks/schema
index 33ea3bd6d6dcc645cd77a38ee3dd313d3d6bc4a0..eee4f12549e6ac7d001a8832e640882ab628a342 100755 (executable)
@@ -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
index 66cece833168b167d477d5f2ed85d8009d5952e2..30e07fc19984404f4293bfbe4c1b5935a8054a19 100644 (file)
@@ -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
+}