From bda1e03b2412d994ee4dee494895110ac183936b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:55:24 +0000 Subject: [PATCH] merge bitcoin#24982: Port `lint-all.sh` to `lint-all.py` --- ci/dash/build_src.sh | 2 +- ci/lint/06_script.sh | 2 +- test/README.md | 2 +- test/lint/README.md | 2 +- test/lint/lint-all.py | 36 +++++++++++++++++++++++++++++++++ test/lint/lint-all.sh | 46 ------------------------------------------- 6 files changed, 40 insertions(+), 50 deletions(-) create mode 100755 test/lint/lint-all.py delete mode 100755 test/lint/lint-all.sh diff --git a/ci/dash/build_src.sh b/ci/dash/build_src.sh index e940aac194..9774fecd7b 100755 --- a/ci/dash/build_src.sh +++ b/ci/dash/build_src.sh @@ -25,7 +25,7 @@ if [ "$CHECK_DOC" = 1 ]; then # TODO: Check docs (re-enable after all Bitcoin PRs have been merged and docs fully fixed) #test/lint/check-doc.py # Run all linters - test/lint/lint-all.sh + test/lint/lint-all.py fi ccache --zero-stats --max-size=$CCACHE_SIZE diff --git a/ci/lint/06_script.sh b/ci/lint/06_script.sh index edfedac64e..d4761a9df1 100755 --- a/ci/lint/06_script.sh +++ b/ci/lint/06_script.sh @@ -21,7 +21,7 @@ test/lint/git-subtree-check.sh src/minisketch test/lint/git-subtree-check.sh src/univalue test/lint/git-subtree-check.sh src/leveldb test/lint/check-doc.py -test/lint/lint-all.sh +test/lint/lint-all.py if [ "$CIRRUS_REPO_FULL_NAME" = "dashpay/dash" ] && [ -n "$CIRRUS_CRON" ]; then git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit diff --git a/test/README.md b/test/README.md index 2d04180164..f3b73eaf39 100644 --- a/test/README.md +++ b/test/README.md @@ -332,7 +332,7 @@ test/lint/lint-files.py You can run all the shell-based lint tests by running: ``` -test/lint/lint-all.sh +test/lint/lint-all.py ``` # Writing functional tests diff --git a/test/lint/README.md b/test/lint/README.md index 177356abc4..89e90fde5d 100644 --- a/test/lint/README.md +++ b/test/lint/README.md @@ -39,6 +39,6 @@ To do so, add the upstream repository as remote: git remote add --fetch secp256k1 https://github.com/bitcoin-core/secp256k1.git ``` -lint-all.sh +lint-all.py =========== Calls other scripts with the `lint-` prefix. diff --git a/test/lint/lint-all.py b/test/lint/lint-all.py new file mode 100755 index 0000000000..1774d3357b --- /dev/null +++ b/test/lint/lint-all.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017-2022 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +# +# This script runs all test/lint/lint-* files, and fails if any exit +# with a non-zero status code. + +from glob import glob +from os import path as os_path, remove +from pathlib import Path +from shutil import which +from subprocess import run + +exit_code = 0 +mod_path = Path(__file__).parent +lints = [x for x in glob(f"{mod_path}/lint-*") if x != __file__] +if which("parallel") and which("column"): + logfile = "parallel_out.log" + command = ["parallel", "--jobs", "100%", "--will-cite", "--joblog", logfile, ":::"] + lints + result = run(command) + if result.returncode != 0: + print(f"^---- failure generated") + exit_code = result.returncode + result = run(["column", "-t", logfile]) + if os_path.isfile(logfile): + remove(logfile) +else: + for lint in lints: + result = run([lint]) + if result.returncode != 0: + print(f"^---- failure generated from {lint.split('/')[-1]}") + exit_code |= result.returncode + +exit(exit_code) diff --git a/test/lint/lint-all.sh b/test/lint/lint-all.sh deleted file mode 100755 index 3472a09908..0000000000 --- a/test/lint/lint-all.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2017-2019 The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -# -# This script runs all contrib/devtools/lint-* files, and fails if any exit -# with a non-zero status code. - -# This script is intentionally locale dependent by not setting "export LC_ALL=C" -# in order to allow for the executed lint scripts to opt in or opt out of locale -# dependence themselves. - -set -u - -SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") -LINTALL=$(basename "${BASH_SOURCE[0]}") - -EXIT_CODE=0 - -if ! command -v parallel > /dev/null; then - for f in "${SCRIPTDIR}"/lint-*; do - if [ "$(basename "$f")" != "$LINTALL" ]; then - if ! "$f"; then - echo "^---- failure generated from $f" - EXIT_CODE=1 - fi - fi - done -else - SCRIPTS=() - - for f in "${SCRIPTDIR}"/lint-*; do - if [ "$(basename "$f")" != "$LINTALL" ]; then - SCRIPTS+=("$f") - fi - done - - if ! parallel --jobs 100% --will-cite --joblog parallel_out.log ::: "${SCRIPTS[@]}"; then - echo "^---- failure generated" - EXIT_CODE=1 - fi - column -t parallel_out.log && rm parallel_out.log -fi - -exit ${EXIT_CODE}