Skip to content

Commit

Permalink
chores,style(maintenance_scripts: lint): sync with pikaur - 2 and f…
Browse files Browse the repository at this point in the history
…ix some of the newly-found warnings
  • Loading branch information
actionless committed Jun 16, 2024
1 parent f81bc99 commit 1a14adb
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 44 deletions.
7 changes: 6 additions & 1 deletion maintenance_scripts/get_global_expressions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
set -ue

result=$(
grep -REn "^[a-zA-Z_]+ = [^'\"].*" pikaur --color=always \
grep -REn "^[a-zA-Z_]+ = [^'\"].*" "$@" --color=always \
| grep -Ev \
-e ': Final' \
-e ' # nonfinal-ignore' \
-e ' # checkglobals-ignore' \
\
-e ' =.*\|' \
-e ' = [a-zA-Z_]+\[' \
Expand All @@ -13,6 +15,9 @@ result=$(
-e namedtuple \
\
-e 'create_logger\(|running_as_root|sudo' \
\
-e './maintenance_scripts/find_.*.py.*:.*:' \
-e '.SRCINFO' \
| sort
)
echo -n "$result"
Expand Down
6 changes: 5 additions & 1 deletion maintenance_scripts/get_non_final_expressions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
set -ue

result=$(
grep -REn "^[a-zA-Z_]+ = " pikaur --color=always \
grep -REn "^[a-zA-Z_]+ = " "$@" --color=always \
| grep -Ev \
-e ': Final' \
-e ' # nonfinal-ignore' \
\
-e '=.*\|' \
-e '=.*(dict|list|Callable)\[' \
-e TypeVar \
-e namedtuple \
\
-e 'create_logger\(|running_as_root|sudo' \
\
-e './maintenance_scripts/find_.*.py.*:.*:' \
-e '.SRCINFO' \
| sort
)
echo -n "$result"
Expand Down
56 changes: 33 additions & 23 deletions maintenance_scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ fi


PYTHON=python3

TARGET_MODULE='pikaur'
TARGETS=(
'pikaur'
'pikaur_test'
'./pikaur/'
'./pikaur_test/'
./maintenance_scripts/*.py
packaging/usr/bin/pikaur
'./packaging/usr/bin/pikaur'
)
if [[ -n "${1:-}" ]] ; then
TARGETS=("$@")
Expand All @@ -50,27 +50,29 @@ RUFF="${APP_DIR}/env/bin/ruff"
if [[ "$FIX_MODE" -eq 1 ]] ; then
"$RUFF" check --unsafe-fixes --fix "${TARGETS[@]}"
else
export PYTHONWARNINGS='ignore,error:::pikaur[.*],error:::pikaur_test[.*]'

export PYTHONWARNINGS='ignore,error:::'"$TARGET_MODULE"'[.*],error:::pikaur_test[.*]'

echo Python compile...
echo -e "\n== Running python compile:"
"$PYTHON" -O -m compileall "${TARGETS[@]}" \
| (\
grep -v -e '^Listing' -e '^Compiling' || true \
)
echo ':: python compile passed ::'

echo Python import...
#"$PYTHON" -c "import pikaur"
echo -e "\n== Running python import:"
"$PYTHON" -c "import pikaur.main"
echo ':: python import passed ::'

echo Checking for non-Final globals...
./maintenance_scripts/get_non_final_expressions.sh
echo -e "\n== Checking for non-Final globals:"
./maintenance_scripts/get_non_final_expressions.sh "${TARGETS[@]}"
echo ':: check passed ::'

echo Checking for unreasonable global vars...
./maintenance_scripts/get_global_expressions.sh
echo -e "\n== Checking for unreasonable global vars:"
./maintenance_scripts/get_global_expressions.sh "${TARGETS[@]}"
echo ':: check passed ::'

install_ruff
echo Ruff rules up-to-date...
echo -e "\n== Checking Ruff rules up-to-date:"
diff --color -u \
<(awk '/select = \[/,/]/' pyproject.toml \
| sed -e 's|", "|/|g' \
Expand All @@ -82,44 +84,51 @@ else
<("$RUFF" linter \
| awk '{print $1;}' \
| sort)
echo Ruff...
echo -e "\n== Ruff..."
"$RUFF" check "${TARGETS[@]}"
echo ':: ruff passed ::'

echo Flake8...
echo -e "\n== Running flake8:"
"$PYTHON" -m flake8 "${TARGETS[@]}"
echo ':: flake8 passed ::'

echo PyLint...
echo -e "\n== Running pylint:"
"$PYTHON" -m pylint "${TARGETS[@]}" --score no
echo ':: pylint passed ::'

echo MyPy...
echo -e "\n== Running mypy:"
"$PYTHON" -m mypy "${TARGETS[@]}" --no-error-summary
echo ':: mypy passed ::'

echo Vulture...
echo -e "\n== Running vulture:"
#--exclude argparse.py \
"$PYTHON" -m vulture "${TARGETS[@]}" \
./maintenance_scripts/vulture_whitelist.py \
--min-confidence=1 \
--sort-by-size
echo ':: vulture passed ::'

echo Bandit...
# if `grep -R nosec pikaur | grep -v noqa` would start returning nothing - bandit check might be removed safely
"$PYTHON" -m bandit "${TARGETS[@]}" --recursive --silent

echo Shellcheck...
echo -e "\n== Running shellcheck:"
(
cd "${APP_DIR}"
# shellcheck disable=SC2046
shellcheck $(find . \
-name '*.sh' \
)
)
echo Shellcheck Makefile...
echo ':: shellcheck passed ::'
echo -e "\n== Running shellcheck on Makefile..."
(
cd "${APP_DIR}"
"$PYTHON" ./maintenance_scripts/makefile_shellcheck.py
)
echo ':: shellcheck makefile passed ::'

echo Validate pyproject file...
echo -e "\n== Validate pyproject file..."
(
exit_code=0
result=$(validate-pyproject pyproject.toml 2>&1) || exit_code=$?
Expand All @@ -128,7 +137,8 @@ else
exit $exit_code
fi
)
echo ':: pyproject validation passed ::'

fi

echo '== GOOD!'
echo -e '\n== GOOD!'
13 changes: 7 additions & 6 deletions maintenance_scripts/makefile_shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import subprocess # nosec B404
import sys
import tempfile
from typing import Final

MAKEFILE = "./Makefile"
MAKEFILE: str = "./Makefile"
if len(sys.argv) > 1:
MAKEFILE = sys.argv[1]

DEFAULT_ENCODING = "utf-8"
MAKE_SHELL = os.environ.get("MAKE_SHELL", "sh")
DEFAULT_ENCODING: Final = "utf-8"
MAKE_SHELL: Final = os.environ.get("MAKE_SHELL", "sh")
# SKIP_TARGETS_WITH_CHARS = ("%", )
SKIP_TARGETS_WITH_CHARS = ("%", "/")
SKIP_TARGETS = (".PHONY", ".PRECIOUS")
SKIP_TARGETS_WITH_CHARS: Final = ("%", "/")
SKIP_TARGETS: Final = (".PHONY", ".PRECIOUS")


_ALL = "all"
_ALL: Final = "all"


def get_targets() -> list[str]:
Expand Down
4 changes: 2 additions & 2 deletions maintenance_scripts/pidowngrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import sys
from pathlib import Path

SCRIPT_DIR = Path(os.path.realpath(__file__)).parent
PARENT_DIR = os.path.realpath(
SCRIPT_DIR: Path = Path(os.path.realpath(__file__)).parent
PARENT_DIR: str = os.path.realpath(
SCRIPT_DIR / "../",
)
sys.path.insert(1, PARENT_DIR)
Expand Down
6 changes: 3 additions & 3 deletions maintenance_scripts/pikaman.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
from collections.abc import MutableMapping, Sequence
from typing import Any, Final

Token = markdown_it.token.Token
OptionsDict = markdown_it.utils.OptionsDict
OptionsType = markdown_it.utils.OptionsType
Token = markdown_it.token.Token # nonfinal-ignore
OptionsDict = markdown_it.utils.OptionsDict # nonfinal-ignore
OptionsType = markdown_it.utils.OptionsType # nonfinal-ignore


class TokenType:
Expand Down
2 changes: 1 addition & 1 deletion maintenance_scripts/vulture_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint: disable=import-error,no-name-in-module
from vulture.whitelist_utils import Whitelist # type: ignore[import-untyped]

whitelist = Whitelist()
whitelist: Whitelist = Whitelist() # type: ignore[no-any-unimported]

whitelist.Any
whitelist.BinaryIO
Expand Down
4 changes: 2 additions & 2 deletions pikaur_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from unittest import TestResult


WRITE_DB = bool(os.environ.get("WRITE_DB"))
WRITE_DB: bool = bool(os.environ.get("WRITE_DB"))


if WRITE_DB:
Expand All @@ -50,7 +50,7 @@
from mypy_extensions import DefaultArg


TEST_DIR = Path(os.path.realpath(__file__)).parent
TEST_DIR: Path = Path(os.path.realpath(__file__)).parent


def spawn(cmd: str | list[str], env: dict[str, str] | None = None) -> InteractiveSpawn:
Expand Down
12 changes: 7 additions & 5 deletions pikaur_test/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Licensed under GPLv3, see https://www.gnu.org/licenses/"""
# mypy: disable-error-code=no-untyped-def

from typing import Final

from pikaur_test.helpers import PikaurDbTestCase, pikaur

MSG_CANNOT_BE_FOUND = "cannot be found"
MSG_DEPS_MISSING = "Dependencies missing"
MSG_VERSION_MISMATCH = "Version mismatch"
MSG_MAKEPKG_FAILED_TO_EXECUTE = "Command 'makepkg --force --nocolor' failed to execute."
MSG_FAILED_TO_BUILD_PKGS = "Failed to build following packages:"
MSG_CANNOT_BE_FOUND: Final = "cannot be found"
MSG_DEPS_MISSING: Final = "Dependencies missing"
MSG_VERSION_MISMATCH: Final = "Version mismatch"
MSG_MAKEPKG_FAILED_TO_EXECUTE: Final = "Command 'makepkg --force --nocolor' failed to execute."
MSG_FAILED_TO_BUILD_PKGS: Final = "Failed to build following packages:"


class FailureTest(PikaurDbTestCase):
Expand Down

0 comments on commit 1a14adb

Please sign in to comment.