Skip to content

Commit

Permalink
Reformat all python script with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsbuild committed Oct 31, 2023
1 parent 9f0a15b commit d64ce05
Show file tree
Hide file tree
Showing 183 changed files with 17,313 additions and 13,154 deletions.
52 changes: 24 additions & 28 deletions DMWM/AggregatePylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
label = args[0]

try:
with open('pylintReport.json', 'r') as reportFile:
with open("pylintReport.json", "r") as reportFile:
report = json.load(reportFile)
except IOError:
report = {}
Expand All @@ -24,22 +24,22 @@
refactors = 0
score = 0

with open('pylint.out', 'r') as pylintFile:
with open("pylint.out", "r") as pylintFile:
for line in pylintFile:
if line.startswith('Your code has been rated at '):
scorePart = line.strip('Your code has been rated at ')
score = scorePart.split('/')[0]
if line.startswith("Your code has been rated at "):
scorePart = line.strip("Your code has been rated at ")
score = scorePart.split("/")[0]
try:
if not filename in report:
report[filename] = {}
if not label in report[filename]:
report[filename][label] = {}
if filename and label:
report[filename][label]['score'] = score
report[filename][label]["score"] = score
except NameError:
print("Score of %s found, but no filename" % score)

parts = line.split(':')
parts = line.split(":")
if len(parts) != 3:
continue
try:
Expand All @@ -49,47 +49,43 @@
continue
lineNumber = int(lineNumber)
filename = newFilename
rmParts = rawMessage.split(']', 1)
rmParts = rawMessage.split("]", 1)
rawCode = rmParts[0].strip()
message = rmParts[1].strip()
severity = rawCode[1:2]
code = rawCode[2:6]
shortMsg = rawCode[7:]
msgParts = shortMsg.split(',')
msgParts = shortMsg.split(",")
objectName = msgParts[1].strip()

if severity == 'R':
if severity == "R":
refactors += 1
elif severity == 'W':
elif severity == "W":
warnings += 1
elif severity == 'E':
elif severity == "E":
errors += 1
elif severity == 'C':
elif severity == "C":
comments += 1

if not filename in report:
report[filename] = {}

if not label in report[filename]:
report[filename][label] = {}
if not 'events' in report[filename][label]:
report[filename][label]['events'] = []
report[filename][label]['events'].append((lineNumber, severity, code, objectName, message))
if not "events" in report[filename][label]:
report[filename][label]["events"] = []
report[filename][label]["events"].append(
(lineNumber, severity, code, objectName, message)
)

report[filename][label]['refactors'] = refactors
report[filename][label]['warnings'] = warnings
report[filename][label]['errors'] = errors
report[filename][label]['comments'] = comments
report[filename][label]["refactors"] = refactors
report[filename][label]["warnings"] = warnings
report[filename][label]["errors"] = errors
report[filename][label]["comments"] = comments

except ValueError:
continue

with open('pylintReport.json', 'w') as reportFile:
with open("pylintReport.json", "w") as reportFile:
json.dump(report, reportFile, indent=2)
reportFile.write('\n')






reportFile.write("\n")
38 changes: 20 additions & 18 deletions DMWM/AnalyzePy27.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,60 @@

from github import Github

summaryMessage = ''
summaryMessage = ""
reportOn = {}
failed = False

with open('added.message', 'r') as messageFile:
with open("added.message", "r") as messageFile:
lines = messageFile.readlines()

if len(lines):
summaryMessage += 'Imports for Python3 compatability missing in new files. Please fix this:\n'
summaryMessage += (
"Imports for Python3 compatability missing in new files. Please fix this:\n"
)

summaryMessage += ''.join(lines)
summaryMessage += "".join(lines)
summaryMessage += "\n\n"
failed = True

with open('test.patch', 'r') as patchFile:
with open("test.patch", "r") as patchFile:
lines = patchFile.readlines()

if len(lines):
summaryMessage += 'Pre-python 2.6 constructs are introduced by this pull request. This must be fixed. Suggested patch follows:\n\n'
summaryMessage += "Pre-python 2.6 constructs are introduced by this pull request. This must be fixed. Suggested patch follows:\n\n"

summaryMessage += "```diff\n"
summaryMessage += ''.join(lines)
summaryMessage += "".join(lines)
summaryMessage += "\n```\n\n"
failed = True

with open('idioms.patch', 'r') as patchFile:
with open("idioms.patch", "r") as patchFile:
lines = patchFile.readlines()

if len(lines):
summaryMessage += 'Pre-python 2.6 idioms found in changed files. Please consider updating the code. Suggested patch follows:\n\n'
summaryMessage += "Pre-python 2.6 idioms found in changed files. Please consider updating the code. Suggested patch follows:\n\n"

summaryMessage += "```diff\n"
summaryMessage += ''.join(lines)
summaryMessage += "".join(lines)
summaryMessage += "\n```\n\n"


issueID = None

if 'ghprbPullId' in os.environ:
issueID = os.environ['ghprbPullId']
if "ghprbPullId" in os.environ:
issueID = os.environ["ghprbPullId"]

gh = Github(os.environ['DMWMBOT_TOKEN'])
codeRepo = os.environ.get('CODE_REPO', 'WMCore')
repoName = '%s/%s' % (os.environ['WMCORE_REPO'], codeRepo)
gh = Github(os.environ["DMWMBOT_TOKEN"])
codeRepo = os.environ.get("CODE_REPO", "WMCore")
repoName = "%s/%s" % (os.environ["WMCORE_REPO"], codeRepo)

issue = gh.get_repo(repoName).get_issue(int(issueID))
if len(summaryMessage) > 250000:
summaryMessage = summaryMessage[:250000]
if summaryMessage:
issue.create_comment('%s' % summaryMessage)
issue.create_comment("%s" % summaryMessage)

if failed:
print('Testing of python code. DMWM-FAIL-PY27')
print("Testing of python code. DMWM-FAIL-PY27")
else:
print('Testing of python code. DMWM-SUCCEED-PY27')
print("Testing of python code. DMWM-SUCCEED-PY27")
15 changes: 9 additions & 6 deletions DMWM/AnalyzePyFuture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

from __future__ import print_function, division

with open('addedFiles.txt', 'r') as addedFiles:
with open("addedFiles.txt", "r") as addedFiles:
for fileName in addedFiles:
fileName = fileName.strip()
if fileName.endswith('__init__.py'):
if fileName.endswith("__init__.py"):
continue
with open(fileName, 'r') as pyFile:
with open(fileName, "r") as pyFile:
pyLines = pyFile.readlines()
if fileName.endswith('.py') or 'python' in pyLines[0]:
if fileName.endswith(".py") or "python" in pyLines[0]:
foundDivision = False
for line in pyLines:
if '__future__' in line and 'division' in line:
if "__future__" in line and "division" in line:
foundDivision = True
if not foundDivision:
print ("* New file %s does not use python 3 division. Please add `from __future__ import division`.\n" % fileName)
print(
"* New file %s does not use python 3 division. Please add `from __future__ import division`.\n"
% fileName
)
134 changes: 76 additions & 58 deletions DMWM/AnalyzePylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,114 +7,132 @@

from github import Github

reportWarnings = ['0611', '0612', '0613']
reportWarnings = ["0611", "0612", "0613"]

summaryMessage = ''
longMessage = ''
summaryMessage = ""
longMessage = ""
reportOn = {}
failed = False
reportExists = False

with open('pylintReport.json', 'r') as reportFile:
with open("pylintReport.json", "r") as reportFile:
report = json.load(reportFile)
if report:
reportExists = True

for filename in sorted(report.keys()):
fileReport = report[filename]
if 'test' in fileReport and 'base' not in fileReport:
testReport = fileReport['test']
if not 'score' in testReport:
if "test" in fileReport and "base" not in fileReport:
testReport = fileReport["test"]
if not "score" in testReport:
continue
reportOn[filename] = True
summaryMessage += '* New file %s with score %s, %s warnings, and %s errors\n' % (filename, testReport['score'], testReport['warnings'], testReport['errors'])
if 'test' in fileReport and 'base' in fileReport:
testReport = fileReport['test']
baseReport = fileReport['base']
if not 'score' in testReport or not 'score' in baseReport:
summaryMessage += "* New file %s with score %s, %s warnings, and %s errors\n" % (
filename,
testReport["score"],
testReport["warnings"],
testReport["errors"],
)
if "test" in fileReport and "base" in fileReport:
testReport = fileReport["test"]
baseReport = fileReport["base"]
if not "score" in testReport or not "score" in baseReport:
continue
if float(testReport['score']) < float(baseReport['score']) or \
float(testReport['errors']) > float(baseReport['errors']) or \
float(testReport['warnings']) > float(baseReport['warnings']):
if (
float(testReport["score"]) < float(baseReport["score"])
or float(testReport["errors"]) > float(baseReport["errors"])
or float(testReport["warnings"]) > float(baseReport["warnings"])
):
reportOn[filename] = True
summaryMessage += '* Score for %s changed from %s to %s with %s (%s) total errors (warnings)\n' % (filename, baseReport['score'], testReport['score'], testReport['errors'], testReport['warnings'])
summaryMessage += (
"* Score for %s changed from %s to %s with %s (%s) total errors (warnings)\n"
% (
filename,
baseReport["score"],
testReport["score"],
testReport["errors"],
testReport["warnings"],
)
)

for filename in sorted(report.keys()):
comments = 0
warnings = 0
fileReport = report[filename]
if 'test' in fileReport:
testReport = fileReport['test']
if not 'score' in testReport:
if "test" in fileReport:
testReport = fileReport["test"]
if not "score" in testReport:
continue
if float(testReport['score']) < 8.0 or filename in reportOn:
if float(testReport['score']) < 8.0:
if float(testReport["score"]) < 8.0 or filename in reportOn:
if float(testReport["score"]) < 8.0:
failed = True
longMessage += '\n%s fails the pylint check. Report follows:\n' % filename
longMessage += "\n%s fails the pylint check. Report follows:\n" % filename
elif filename in reportOn:
longMessage += '\n%s got worse in pylint. Report follows:\n' % filename
longMessage += "\n%s got worse in pylint. Report follows:\n" % filename
else:
longMessage += '\nPylint report for %s follows:\n' % filename
for event in testReport['events']:
if event[1] == 'C': # Severity
longMessage += "\nPylint report for %s follows:\n" % filename
for event in testReport["events"]:
if event[1] == "C": # Severity
comments += 1
continue
if event[1] == 'I': # Severity
if event[1] == "I": # Severity
continue
longMessage += '* Line %s ' % (event[0])
if event[3]: # Module
longMessage += 'in %s ' % event[3]
longMessage += '%s%s %s\n' % (event[1], event[2], event[4])
longMessage += "* Line %s " % (event[0])
if event[3]: # Module
longMessage += "in %s " % event[3]
longMessage += "%s%s %s\n" % (event[1], event[2], event[4])
longMessage += "* plus %s comments on code style\n" % comments
else:
conditionalMessage = ''
for event in testReport['events']:
if event[1] == 'C': # Severity
conditionalMessage = ""
for event in testReport["events"]:
if event[1] == "C": # Severity
comments += 1
continue
if event[1] == 'I': # Severity
if event[1] == "I": # Severity
continue
if event[1] == 'E':
conditionalMessage += '* Line %s ' % (event[0])
if event[3]: # Module
conditionalMessage += 'in %s ' % event[3]
conditionalMessage += '%s%s %s\n' % (event[1], event[2], event[4])
if event[1] == 'W':
if event[1] == "E":
conditionalMessage += "* Line %s " % (event[0])
if event[3]: # Module
conditionalMessage += "in %s " % event[3]
conditionalMessage += "%s%s %s\n" % (event[1], event[2], event[4])
if event[1] == "W":
warnings += 1
if event[1] == 'W' and event[2] in reportWarnings:
conditionalMessage += '* Line %s ' % (event[0])
if event[3]: # Module
conditionalMessage += 'in %s ' % event[3]
conditionalMessage += '%s%s %s\n' % (event[1], event[2], event[4])
if event[1] == "W" and event[2] in reportWarnings:
conditionalMessage += "* Line %s " % (event[0])
if event[3]: # Module
conditionalMessage += "in %s " % event[3]
conditionalMessage += "%s%s %s\n" % (event[1], event[2], event[4])
if conditionalMessage:
longMessage += ('\nAbbreviated pylint report for %s follows:\n' % filename) + conditionalMessage
longMessage += (
"\nAbbreviated pylint report for %s follows:\n" % filename
) + conditionalMessage
longMessage += "* plus %s total warnings\n" % warnings
longMessage += "* plus %s comments on code style\n" % comments

issueID = None

if 'ghprbPullId' in os.environ:
issueID = os.environ['ghprbPullId']
if "ghprbPullId" in os.environ:
issueID = os.environ["ghprbPullId"]

if reportExists:
message = 'No pylint warnings for pull request %s.\n' % issueID
message = "No pylint warnings for pull request %s.\n" % issueID
else:
message = 'No python changes for pull request %s.\n' % issueID
message = "No python changes for pull request %s.\n" % issueID

if summaryMessage or longMessage:
message = 'Summary of pylint changes for pull request %s:\n' % issueID + summaryMessage
message = "Summary of pylint changes for pull request %s:\n" % issueID + summaryMessage
message += longMessage

gh = Github(os.environ['DMWMBOT_TOKEN'])
codeRepo = os.environ.get('CODE_REPO', 'WMCore')
repoName = '%s/%s' % (os.environ['WMCORE_REPO'], codeRepo)
gh = Github(os.environ["DMWMBOT_TOKEN"])
codeRepo = os.environ.get("CODE_REPO", "WMCore")
repoName = "%s/%s" % (os.environ["WMCORE_REPO"], codeRepo)

issue = gh.get_repo(repoName).get_issue(int(issueID))
if len(message) > 250000:
message = message[:250000]
issue.create_comment('%s' % message)
issue.create_comment("%s" % message)

if failed:
print('Testing of python code. DMWM-FAIL-PYLINT')
print("Testing of python code. DMWM-FAIL-PYLINT")
else:
print('Testing of python code. DMWM-SUCCEED-PYLINT')
print("Testing of python code. DMWM-SUCCEED-PYLINT")
Loading

0 comments on commit d64ce05

Please sign in to comment.