summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-02-05 21:24:24 +0000
committerKarl Berry <karl@freefriends.org>2022-02-05 21:24:24 +0000
commit0e33ca376dc3608120a8432ca8967d60e3c14407 (patch)
treea40c6e3880481cb291cf075962f1cf32242ccde6 /Master/texmf-dist/tex/lualatex
parentf1e81a3aeba249ef91f772aecea8a2147963cbd2 (diff)
pyluatex (5feb22)
git-svn-id: svn://tug.org/texlive/trunk@61901 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py7
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua6
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty28
3 files changed, 34 insertions, 7 deletions
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)}}%