From 0e33ca376dc3608120a8432ca8967d60e3c14407 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 5 Feb 2022 21:24:24 +0000 Subject: pyluatex (5feb22) git-svn-id: svn://tug.org/texlive/trunk@61901 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/lualatex/pyluatex/README.md | 2 +- .../texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf | Bin 82190 -> 84163 bytes .../texmf-dist/doc/lualatex/pyluatex/pyluatex.tex | 11 +++++--- .../tex/lualatex/pyluatex/pyluatex-interpreter.py | 7 ++++-- .../texmf-dist/tex/lualatex/pyluatex/pyluatex.lua | 6 ++++- .../texmf-dist/tex/lualatex/pyluatex/pyluatex.sty | 28 ++++++++++++++++++--- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Master/texmf-dist/doc/lualatex/pyluatex/README.md b/Master/texmf-dist/doc/lualatex/pyluatex/README.md index feb77a04bcf..a6faac70c23 100644 --- a/Master/texmf-dist/doc/lualatex/pyluatex/README.md +++ b/Master/texmf-dist/doc/lualatex/pyluatex/README.md @@ -50,7 +50,7 @@ executed. For this reason, it is recommended to compile trusted documents only. * Linux, macOS or Windows Our automated tests currently use TeX Live 2021 and Python 3.7+ on -Ubuntu 20.04, macOS Catalina 10.15 and Windows Server 2019. +Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019. ## License [LPPL 1.3c](http://www.latex-project.org/lppl.txt) for LaTeX code and diff --git a/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf b/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf index 0318eda2cbd..23699dd22bd 100644 Binary files a/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf and b/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex b/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex index 86374249af9..594d1c0e90b 100644 --- a/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex +++ b/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex @@ -15,7 +15,7 @@ \usepackage{url} \title{The \emph{pyluatex} package} \author{Tobias Enderle\\\url{https://github.com/tndrle/PyLuaTeX}} -\date{v0.4.0 (2021/11/05)} +\date{v0.4.1 (2022/02/04)} \begin{document} \maketitle \raggedright @@ -139,8 +139,13 @@ For an example, see the Typesetting Code section. By default, PyLuaTeX aborts the compilation process when Python reports an error. If the \inlcode|ignoreerrors| option is set, the compilation process is not aborted.\\[0.5ex] \textit{Example:} \inlcode|\usepackage[ignoreerrors]{pyluatex}| +\item \inlcode|shutdown|\\[0.5ex] + Specifies when the Python process is shut down. (default: \inlcode|veryveryend|)\\[0.5ex] + \textit{Options:} \inlcode|veryveryend|, \inlcode|veryenddocument|, \inlcode|off|\\[0.5ex] + PyLuaTeX uses the hooks of the package \textit{atveryend} to shut down the Python interpreter when the compilation is done. With the option \inlcode|veryveryend|, Python is shut down in the \inlcode|\AtVeryVeryEnd| hook. With the option \inlcode|veryenddocument|, Python is shut down in the \inlcode|\AtVeryEndDocument| hook. With the option \inlcode|off|, Python is not shut down explicitly. However, the Python process will shut down when the LuaTeX process finishes even if \inlcode|off| is selected. Using \inlcode|off| on Windows might lead to problems with SyncTeX, though.\\[0.5ex] + \textit{Example:} \inlcode|\usepackage[veryenddocument]{pyluatex}| \end{itemize} -Package options (except for \inlcode|executable|) can be changed in the document with the +Package options (except for \inlcode|executable| and \inlcode|shutdown|) can be changed in the document with the \inlcode|\pyoption| command, e.g. \inlcode|\pyoption{verbose}{true}| or \inlcode|\pyoption{ignoreerrors}{false}|. \subsection{Macros} @@ -212,7 +217,7 @@ in your environment definition, e.g. \item Linux, macOS or Windows \end{itemize} Our automated tests currently use TeX Live 2021 and Python 3.7+ on -Ubuntu 20.04, macOS Catalina 10.15 and Windows Server 2019. +Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019. \section{Typesetting Code} Sometimes, in addition to having Python code executed and the output written to your document, you also want to show the code itself in your document. diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py index 0e8b32035fd..4d713e7ab3c 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py @@ -1,7 +1,7 @@ """ MIT License -Copyright (c) 2021 Tobias Enderle +Copyright (c) 2021-2022 Tobias Enderle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -84,10 +84,13 @@ class Handler(socketserver.StreamRequestHandler): interpreters = defaultdict(Interpreter) while True: data = self.rfile.readline().decode('utf-8') - if len(data) == 0: + if len(data) == 0: # socket closed, LuaTeX process finished return data = json.loads(data) + if data == 'shutdown': + return + interpreter = interpreters[data['session']] code = textwrap.dedent(data['code']) if data['repl_mode']: diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua index 6e9c6abb631..f95ab989c08 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua @@ -1,7 +1,7 @@ --[[ MIT License -Copyright (c) 2021 Tobias Enderle +Copyright (c) 2021-2022 Tobias Enderle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -73,6 +73,10 @@ function pyluatex.start(executable) end end +function pyluatex.shutdown() + tcp:send(json.encode("shutdown") .. "\n") +end + local function request(data) tcp:send(json.encode(data) .. "\n") local output = tcp:receive("*l") diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty index ab015d9638d..cf67916d198 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty @@ -1,4 +1,4 @@ -%% Copyright 2021 Tobias Enderle +%% Copyright 2021-2022 Tobias Enderle %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either version 1.3 @@ -9,15 +9,15 @@ %% version 2005/12/01 or later. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{pyluatex}[2021/11/05 v0.4.0 Execute Python code on the fly] +\ProvidesPackage{pyluatex}[2022/02/04 v0.4.1 Execute Python code on the fly] \RequirePackage{expl3} \ExplSyntaxOn \sys_if_engine_luatex:TF{}{% -\PackageError{PyLuaTeX}{LuaTeX~is~required}{}% + \PackageError{PyLuaTeX}{LuaTeX~is~required}{}% } \sys_if_shell_unrestricted:TF{}{% -\PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}% + \PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}% } \ExplSyntaxOff @@ -27,6 +27,7 @@ \DeclareStringOption[python3]{executable} \DeclareBoolOption{ignoreerrors} \DeclareBoolOption{verbose} +\DeclareStringOption[veryveryend]{shutdown} \ProcessKeyvalOptions* \ifpyluatex@ignoreerrors @@ -41,6 +42,25 @@ \fi \directlua{pyluatex.start([==[\pyluatex@executable]==])} +\ExplSyntaxOn +\cs_generate_variant:Nn \tl_if_eq:nnTF { V } +\tl_if_eq:VnTF{\pyluatex@shutdown}{veryveryend}{% + \RequirePackage{atveryend} + \AtVeryVeryEnd{\directlua{pyluatex.shutdown()}} +}{% + \tl_if_eq:VnTF{\pyluatex@shutdown}{veryenddocument}{% + \RequirePackage{atveryend} + \AtVeryEndDocument{\directlua{pyluatex.shutdown()}} + }{% + \tl_if_eq:VnTF{\pyluatex@shutdown}{off}{}{% + \PackageError{PyLuaTeX}{% + Invalid~value~for~package~option~"shutdown":~\pyluatex@shutdown + }{}% + } + } +} +\ExplSyntaxOff + \newcommand*{\PyLTVerbatimEnv}{\directlua{pyluatex.set_parent_env([==[\@currenvir]==])}} \newenvironment{python}{\directlua{pyluatex.record_env("python", false)}}% -- cgit v1.2.3