Skip to content

Commit

Permalink
flake8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaigh0 committed Dec 10, 2024
1 parent 210c195 commit 7a30848
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
4 changes: 2 additions & 2 deletions web/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

exclude =
services/migrations,
services/github_issue_manager/test_search_for_matching_stacktrace.py,
services/github_issue_manager/test_trim_stacktrace.py,
services/utils/test_search_for_matching_stacktrace.py,
services/utils/test_trim_stacktrace.py,

10 changes: 7 additions & 3 deletions web/services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from django.db.models import signals
from services.tasks import send_notification_to_slack
from services.constants import input_box_max_length, free_text_max_length
from services.utils.handel_compressed_cpp_traces import extract_mantid_code_threads_from_cpp_traces
from services.utils.handel_compressed_cpp_traces import (
extract_mantid_code_threads_from_cpp_traces
)
import logging
import threading

Expand Down Expand Up @@ -51,7 +53,8 @@ class ErrorReport(models.Model):
default="",
null="True")
stacktrace = models.CharField(max_length=10000, default="")
cppCompressedTraces = models.CharField(max_length=10000, default="", blank=True)
cppCompressedTraces = models.CharField(max_length=10000, default="",
blank=True)
githubIssue = models.ForeignKey('GithubIssue',
on_delete=models.SET_NULL,
blank=True,
Expand Down Expand Up @@ -106,7 +109,8 @@ def notify_report_received(sender, instance, signal, *args, **kwargs):
stacktrace = instance.stacktrace

if instance.cppCompressedTraces != "":
stacktrace = "\n\n".join(extract_mantid_code_threads_from_cpp_traces(instance.cppCompressedTraces))
stacktrace = "\n\n".join(extract_mantid_code_threads_from_cpp_traces(
instance.cppCompressedTraces))

if instance.user is None:

Expand Down
4 changes: 2 additions & 2 deletions web/services/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class Meta:
fields = ['osReadable', 'application', 'url', 'uid',
'host', 'dateTime', 'osName', 'osArch', 'osVersion',
'ParaView', 'mantidVersion', 'mantidSha1', 'facility',
'exitCode', 'upTime', 'textBox', 'stacktrace', 'cppCompressedTraces'
'name', 'email']
'exitCode', 'upTime', 'textBox', 'stacktrace',
'cppCompressedTraces', 'name', 'email']
9 changes: 6 additions & 3 deletions web/services/utils/github_issue_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from services.models import ErrorReport, GithubIssue
from services.utils.handel_compressed_cpp_traces import extract_mantid_code_threads_from_cpp_traces
from services.utils.handel_compressed_cpp_traces import (
extract_mantid_code_threads_from_cpp_traces
)

import re
import pathlib
Expand Down Expand Up @@ -62,7 +64,7 @@ def get_or_create_github_issue(report) -> GithubIssue | None:
stacktrace = report.get('stacktrace')
text_box = report.get('textBox')
cpp_compressed_traces = report.get('cppCompressedTraces')
if stacktrace is None and text_box is None and cpp_compressed_traces is None:
if not any([stacktrace, text_box, cpp_compressed_traces]):
logger.info('No stacktrace or info in the report; skipping github'
' issue interaction')
return None
Expand Down Expand Up @@ -99,7 +101,8 @@ def get_or_create_github_issue(report) -> GithubIssue | None:
else:
trace = stacktrace
if cpp_compressed_traces:
trace = "\n\n".join(extract_mantid_code_threads_from_cpp_traces(cpp_compressed_traces))
trace = "\n\n".join(extract_mantid_code_threads_from_cpp_traces(
cpp_compressed_traces))

issue_text = ISSUE_TEXT.substitute(
name=report['name'],
Expand Down
26 changes: 18 additions & 8 deletions web/services/utils/handel_compressed_cpp_traces.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import base64
import re
from typing import List
import zlib


def extract_mantid_code_threads_from_cpp_traces(compressed_cpp_traces: str) -> List[str]:
def extract_mantid_code_threads_from_cpp_traces(compressed_cpp_traces: str):
"""
Take base64 encoded string of the compressed output from pystack core.
Return a list of trace back threads which include code from the mantid repo.
Return a list of trace back threads which includes code from
the mantid repo.
"""
cpp_traces_from_pystack = zlib.decompress(base64.standard_b64decode(compressed_cpp_traces)).decode("utf-8")
return ["Traceback for " + trace_back for trace_back in re.split(r'\nTraceback for ', cpp_traces_from_pystack)[1:] if
cpp_traces_from_pystack = zlib.decompress(
base64.standard_b64decode(compressed_cpp_traces)).decode("utf-8")
return ["Traceback for " + trace_back for trace_back in
re.split(r'\nTraceback for ', cpp_traces_from_pystack)[1:] if
_search_for_mantid_codein_trace(trace_back)]


def _search_for_mantid_codein_trace(trace_back: str) -> bool:
cpp_mantid_code = re.search(r"^\s*\(C\) File \".*/(mantid|mantidqt|mantidqtinterfaces|workbench|scripts|plugins)/.*$", trace_back, re.MULTILINE) is not None
python_mantid_code = re.search(r"^\s*\(Python\) File \".*/(mantid|mantidqt|mantidqtinterfaces|workbench|scripts|plugins)/.*$", trace_back, re.MULTILINE) is not None
return cpp_mantid_code or python_mantid_code
cpp_mantid_code = re.search(
r"^\s*\(C\) File \".*/(mantid|mantidqt|mantidqtinterfaces|workbench|"
r"scripts|plugins)/.*$",
trace_back,
re.MULTILINE) is not None
python_mantid_code = re.search(
r"^\s*\(Python\) File \".*/(mantid|"
r"mantidqt|mantidqtinterfaces|workbench|scripts|plugins)/.*$",
trace_back,
re.MULTILINE) is not None
return cpp_mantid_code or python_mantid_code
42 changes: 22 additions & 20 deletions web/services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def saveErrorReport(report):
exitCode = report["exitCode"]
textBox = report["textBox"] if "textBox" in report else ""
stacktrace = report["stacktrace"] if "stacktrace" in report else ""
cppCompressedTraces = report["cppCompressedTraces"] if "cppCompressedTraces" in report else ""
cppCompressedTraces = report["cppCompressedTraces"] \
if "cppCompressedTraces" in report else ""

if "name" in report and "email" in report:
name = report["name"]
Expand All @@ -120,25 +121,26 @@ def saveErrorReport(report):

github_issue = get_or_create_github_issue(report)

obj, created = \
ErrorReport.objects.get_or_create(osReadable=osReadable,
application=application,
uid=uid, host=host,
dateTime=dateTime,
osName=osName,
osArch=osArch,
osVersion=osVersion,
ParaView=ParaView,
mantidVersion=mantidVersion,
mantidSha1=mantidSha1,
facility=facility,
upTime=upTime,
exitCode=exitCode,
user=user,
textBox=textBox,
stacktrace=stacktrace,
cppCompressedTraces=cppCompressedTraces,
githubIssue=github_issue)
obj, created = ErrorReport.objects.get_or_create(
osReadable=osReadable,
application=application,
uid=uid, host=host,
dateTime=dateTime,
osName=osName,
osArch=osArch,
osVersion=osVersion,
ParaView=ParaView,
mantidVersion=mantidVersion,
mantidSha1=mantidSha1,
facility=facility,
upTime=upTime,
exitCode=exitCode,
user=user,
textBox=textBox,
stacktrace=stacktrace,
cppCompressedTraces=cppCompressedTraces,
githubIssue=github_issue
)
if not created:
obj.save()

Expand Down

0 comments on commit 7a30848

Please sign in to comment.