diff options
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/pyluatex')
3 files changed, 42 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py index 28ec28e12e7..341c2ace04b 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py @@ -34,7 +34,30 @@ import re import os import sys +class PyLTTex: + def __init__(self): + self._log_buffer = [] + + def log(self, *objects, sep=' ', end='\n'): + try: + objects = [str(v) for v in objects] + except Exception as exc: + raise RuntimeError( + 'The object to log could not be transformed to a string.', + ) from exc + self._log_buffer.append(sep.join(objects)) + self._log_buffer.append(end) + + def _log_message(self): + msg = ''.join(self._log_buffer) + self._log_buffer = [] + return msg + class Interpreter(InteractiveInterpreter): + def __init__(self): + self.tex = PyLTTex() + super().__init__({'tex': self.tex}) + def execute_repl(self, code, ignore_errors): self.success = True output = '' @@ -60,7 +83,7 @@ class Interpreter(InteractiveInterpreter): output += out.getvalue() if not ignore_errors and not self.success: return False, output - return self.success, output + return self.success, output, self.tex._log_message() def execute(self, code): with StringIO() as out, redirect_stdout(out), redirect_stderr(out): @@ -75,7 +98,7 @@ class Interpreter(InteractiveInterpreter): except: traceback.print_exc() self.success = False - return self.success, out.getvalue() + return self.success, out.getvalue(), self.tex._log_message() def showtraceback(self): super().showtraceback() @@ -95,13 +118,17 @@ class Handler(socketserver.StreamRequestHandler): interpreter = interpreters[data['session']] code = textwrap.dedent(data['code']) if data['repl_mode']: - success, output = interpreter.execute_repl( + success, output, log_msg = interpreter.execute_repl( code, data['ignore_errors'] ) else: - success, output = interpreter.execute(code) - response = { 'success': success, 'output': output } + success, output, log_msg = interpreter.execute(code) + response = { + 'success': success, + 'output': output, + 'log_msg': log_msg + } self.wfile.write((json.dumps(response) + '\n').encode('utf-8')) if __name__ == '__main__': diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua index 9f7d5f7936b..c12faa5cc80 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua @@ -118,8 +118,7 @@ end local function request(data) tcp:send(utilities.json.tostring(data) .. "\n") local output = tcp:receive("*l") - local response = utilities.json.tolua(output) - return response.success, response.output + return utilities.json.tolua(output) end local function log_input(code) @@ -152,7 +151,7 @@ function pyluatex.execute(code, auto_print, write, repl_mode, store) if pyluatex.verbose then log_input(full_code) end - local success, output = request( + local resp = request( { session = pyluatex.session, code = full_code, @@ -160,27 +159,29 @@ function pyluatex.execute(code, auto_print, write, repl_mode, store) ignore_errors = pyluatex.ignore_errors } ) - local output_lines = split_lines(output) + local output_lines = split_lines(resp.output) if store then last_code = split_lines(code) last_output = output_lines end - if success or pyluatex.ignore_errors then - if pyluatex.verbose or not success then log_output(output) end + if resp.success or pyluatex.ignore_errors then + if pyluatex.verbose or not resp.success then log_output(resp.output) end if write then tex.print(output_lines) end else if not pyluatex.verbose then log_input(full_code) end - log_output(output) + log_output(resp.output) if write then tex.sprint(err_cmd("Python error (see above)")) end end - return success + if resp.log_msg ~= "" then texio.write(resp.log_msg) end + + return resp.success end function pyluatex.print_env() diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty index a5adf62973b..db5654e6b8c 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty @@ -9,7 +9,7 @@ %% version 2005/12/01 or later. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{pyluatex}[2023/01/03 v0.5.2 Execute Python code on the fly] +\ProvidesPackage{pyluatex}[2023/01/14 v0.6.0 Execute Python code on the fly] \RequirePackage{expl3} \ExplSyntaxOn |