python: Apply Black formatter to Python files
The command executed was `black src configs tests util`. Change-Id: I8dfaa6ab04658fea37618127d6ac19270028d771 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47024 Maintainer: Bobby Bruce <bbruce@ucdavis.edu> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Giacomo Travaglini
parent
1cfaa8da83
commit
787204c92d
@@ -36,6 +36,7 @@ from maint.lib import maintainers
|
||||
|
||||
from style.repo import GitRepo
|
||||
|
||||
|
||||
def _printErrorQuit(error_message):
|
||||
"""
|
||||
Print an error message, followed my a help message and inform failure.
|
||||
@@ -45,18 +46,26 @@ def _printErrorQuit(error_message):
|
||||
"""
|
||||
print(error_message)
|
||||
|
||||
print("The commit has been cancelled, but a copy of it can be found in "
|
||||
+ sys.argv[1] + " : ")
|
||||
print(
|
||||
"The commit has been cancelled, but a copy of it can be found in "
|
||||
+ sys.argv[1]
|
||||
+ " : "
|
||||
)
|
||||
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
--------------------------------------------------------------------------
|
||||
""")
|
||||
"""
|
||||
)
|
||||
print(open(sys.argv[1], "r").read())
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
--------------------------------------------------------------------------
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
The first line of a commit must contain one or more gem5 tags separated by
|
||||
commas (see MAINTAINERS.yaml for the possible tags), followed by a colon and
|
||||
a commit title. There must be no leading nor trailing whitespaces.
|
||||
@@ -74,9 +83,11 @@ e.g.:
|
||||
mem,mem-cache: Improve packet class readability
|
||||
|
||||
The packet class...
|
||||
""")
|
||||
"""
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _validateTags(commit_header):
|
||||
"""
|
||||
Check if all tags in the commit header belong to the list of valid
|
||||
@@ -90,14 +101,15 @@ def _validateTags(commit_header):
|
||||
valid_tags = [tag for tag, _ in maintainer_dict]
|
||||
|
||||
# Remove non-tag 'pmc' and add special tags not in MAINTAINERS.yaml
|
||||
valid_tags.remove('pmc')
|
||||
valid_tags.extend(['RFC', 'WIP'])
|
||||
valid_tags.remove("pmc")
|
||||
valid_tags.extend(["RFC", "WIP"])
|
||||
|
||||
tags = ''.join(commit_header.split(':')[0].split()).split(',')
|
||||
if (any(tag not in valid_tags for tag in tags)):
|
||||
tags = "".join(commit_header.split(":")[0].split()).split(",")
|
||||
if any(tag not in valid_tags for tag in tags):
|
||||
invalid_tag = next((tag for tag in tags if tag not in valid_tags))
|
||||
_printErrorQuit("Invalid Gem5 tag: " + invalid_tag)
|
||||
|
||||
|
||||
# Go to git directory
|
||||
os.chdir(GitRepo().repo_base())
|
||||
|
||||
@@ -108,9 +120,10 @@ commit_message = open(sys.argv[1]).read()
|
||||
# a commit title
|
||||
commit_message_lines = commit_message.splitlines()
|
||||
commit_header = commit_message_lines[0]
|
||||
commit_header_match = \
|
||||
re.search("^(fixup! )?(\S[\w\-][,\s*[\w\-]+]*:.+\S$)", commit_header)
|
||||
if ((commit_header_match is None)):
|
||||
commit_header_match = re.search(
|
||||
"^(fixup! )?(\S[\w\-][,\s*[\w\-]+]*:.+\S$)", commit_header
|
||||
)
|
||||
if commit_header_match is None:
|
||||
_printErrorQuit("Invalid commit header")
|
||||
if commit_header_match.group(1) == "fixup! ":
|
||||
sys.exit(0)
|
||||
@@ -119,21 +132,29 @@ _validateTags(commit_header_match.group(2))
|
||||
# Make sure commit title does not exceed threshold. This line is limited to
|
||||
# a smaller number because version control systems may add a prefix, causing
|
||||
# line-wrapping for longer lines
|
||||
commit_title = commit_header.split(':')[1]
|
||||
commit_title = commit_header.split(":")[1]
|
||||
max_header_size = 65
|
||||
if (len(commit_header) > max_header_size):
|
||||
_printErrorQuit("The commit header (tags + title) is too long (" + \
|
||||
str(len(commit_header)) + " > " + str(max_header_size) + ")")
|
||||
if len(commit_header) > max_header_size:
|
||||
_printErrorQuit(
|
||||
"The commit header (tags + title) is too long ("
|
||||
+ str(len(commit_header))
|
||||
+ " > "
|
||||
+ str(max_header_size)
|
||||
+ ")"
|
||||
)
|
||||
|
||||
# Then there must be at least one empty line between the commit header and
|
||||
# the commit description
|
||||
if (commit_message_lines[1] != ""):
|
||||
_printErrorQuit("Please add an empty line between the commit title and " \
|
||||
"its description")
|
||||
if commit_message_lines[1] != "":
|
||||
_printErrorQuit(
|
||||
"Please add an empty line between the commit title and "
|
||||
"its description"
|
||||
)
|
||||
|
||||
# Encourage providing descriptions
|
||||
if (re.search("^(Signed-off-by|Change-Id|Reviewed-by):",
|
||||
commit_message_lines[2])):
|
||||
if re.search(
|
||||
"^(Signed-off-by|Change-Id|Reviewed-by):", commit_message_lines[2]
|
||||
):
|
||||
print("Warning: Commit does not have a description")
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user