Bobby R. Bruce has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/47000 )
Change subject: tests: Add Python Black style checks to pre-submit
......................................................................
tests: Add Python Black style checks to pre-submit
These will run the Python Black checks on any Python files in a
patch. Right now a Python file is defined as one with a '.py'
extension.
Change-Id: Ib4ad9cc9e3a5224a9f91f3cc0019f70350f117a1
---
M tests/jenkins/presubmit.sh
A tests/jenkins/style-checks.sh
2 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/tests/jenkins/presubmit.sh b/tests/jenkins/presubmit.sh
index 5dc5016..038e95e 100755
--- a/tests/jenkins/presubmit.sh
+++ b/tests/jenkins/presubmit.sh
@@ -40,6 +40,7 @@
DOCKER_IMAGE_ALL_DEP=gcr.io/gem5-test/ubuntu-20.04_all-dependencies
DOCKER_IMAGE_CLANG_COMPILE=gcr.io/gem5-test/clang-version-9
PRESUBMIT_STAGE2=tests/jenkins/presubmit-stage2.sh
+STYLE_CHECKS=tests/jenkins/style-checks.sh
# Move the docker base directory to tempfs.
sudo /etc/init.d/docker stop
@@ -50,6 +51,10 @@
# Move the CWD to the gem5 checkout.
cd git/jenkins-gem5-prod/
+# Run the style checks
+docker run -u $UID:$GID --volume $(pwd):$(pwd) -w $(pwd) --rm \
+ "${DOCKER_IMAGE_ALL_DEP}" "${STYLE_CHECKS}"
+
# Using a docker image with all the dependencies, we run the presubmit
tests.
docker run -u $UID:$GID --volume $(pwd):$(pwd) -w $(pwd) --rm \
"${DOCKER_IMAGE_ALL_DEP}" "${PRESUBMIT_STAGE2}"
diff --git a/tests/jenkins/style-checks.sh b/tests/jenkins/style-checks.sh
new file mode 100755
index 0000000..f958c7e
--- /dev/null
+++ b/tests/jenkins/style-checks.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# Copyright (c) 2021 The Regents of the University of California
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+is_python() {
+ extension=$(echo ${1} | rev | cut -d. -f1 | rev)
+ if [ "${extension}" == "py" ]; then
+ return 0
+ fi
+
+ return 1
+}
+
+old_rev=$(git rev-parse HEAD~)
+new_rev=$(git rev-parse HEAD)
+
+style_check_pass=0
+for file in $(git diff --name-only ${old_rev} ${new_rev}); do
+ if is_python "${file}"; then
+ black --quiet --check "${file}"
+ status=$?
+ if [ "${status}" -ne "0" ]; then
+ style_check_pass=1
+ >&2 echo "${file} : Python file fails black style check."
+ >&2 echo "The following diff should be applied:"
+ echo
+ >&2 black --diff "${file}"
+ echo
+ fi
+ fi
+done
+
+exit ${style_check_pass}
\ No newline at end of file
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/47000
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib4ad9cc9e3a5224a9f91f3cc0019f70350f117a1
Gerrit-Change-Number: 47000
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s