Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always evaluate the context file in a separate process #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions damnit/gui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from pyflakes.api import check as pyflakes_check

from ..backend.extract_data import get_context_file
from ..ctxsupport.ctxrunner import extract_error_info
from ..context import ContextFile


class ContextTestResult(Enum):
Expand All @@ -33,25 +31,14 @@ def __init__(self, code, db_dir, context_python, parent=None):
self.context_python = context_python

def run(self):
error_info = None

# If a different environment is not specified, we can evaluate the
# context file directly.
if self.context_python is None:
try:
ContextFile.from_str(self.code)
except:
# Extract the error information
error_info = extract_error_info(*sys.exc_info())

# Otherwise, write it to a temporary file to evaluate it from another
# Write the context to a temporary file to evaluate it from another
# process.
else:
with NamedTemporaryFile(prefix=".tmp_ctx", dir=self.db_dir) as ctx_file:
ctx_path = Path(ctx_file.name)
ctx_path.write_text(self.code)
with NamedTemporaryFile(prefix=".tmp_ctx", dir=self.db_dir) as ctx_file:
ctx_path = Path(ctx_file.name)
ctx_path.write_text(self.code)

ctx, error_info = get_context_file(ctx_path, self.context_python)
context_python = sys.executable if self.context_python is None else self.context_python
ctx, error_info = get_context_file(ctx_path, context_python)

if error_info is not None:
stacktrace, lineno, offset = error_info
Expand Down
Loading