summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-03-11 22:03:59 +0000
committerKarl Berry <karl@freefriends.org>2022-03-11 22:03:59 +0000
commit594f56d8c6dd122d6841c134070753e69276d5cf (patch)
tree0741b22203b58b0b91e6aa87a4875f3ae7ff2acc /Master/texmf-dist/tex/lualatex
parentcc317986aedbee336d643590445a20b2d256b4f0 (diff)
pyluatex (11mar22) (branch)
git-svn-id: svn://tug.org/texlive/branches/branch2021.final@62639 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py9
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua37
-rw-r--r--Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty24
3 files changed, 51 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py
index 4d713e7ab3c..77d09bbb645 100644
--- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py
+++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex-interpreter.py
@@ -31,6 +31,8 @@ import json
import textwrap
from collections import defaultdict
import re
+import os
+import sys
class Interpreter(InteractiveInterpreter):
def execute_repl(self, code, ignore_errors):
@@ -104,6 +106,13 @@ class Handler(socketserver.StreamRequestHandler):
self.wfile.write((json.dumps(response) + '\n').encode('utf-8'))
if __name__ == '__main__':
+ try:
+ tex_file = sys.argv[1]
+ tex_file_folder = os.path.normpath(os.path.dirname(tex_file))
+ sys.path.insert(0, tex_file_folder)
+ except:
+ pass
+
with socketserver.TCPServer(('localhost', 0), Handler) as server:
print(server.server_address[1], end='\n', flush=True) # publish port
server.handle_request()
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
index f9d8ff68a65..0b785239da9 100644
--- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
+++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
@@ -31,6 +31,8 @@ pyluatex = pyluatex or {
session = "default"
}
+local dir_sep = package.config:sub(1,1)
+
-- status.filename: path to pyluatex.sty
local folder = file.pathpart(file.collapsepath(status.filename, true))
local tcp = nil
@@ -43,6 +45,23 @@ local env_repl_mode = false
local last_code = nil
local last_output = nil
+local function get_tex_file()
+ for k, v in ipairs(arg) do
+ if not v:find("^%-") then
+ local path = lfs.currentdir() .. dir_sep .. v
+ if lfs.attributes(path, "mode") == "file" then
+ return path
+ else
+ path = path .. ".tex"
+ if lfs.attributes(path, "mode") == "file" then
+ return path
+ end
+ end
+ end
+ end
+ return nil
+end
+
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
@@ -51,14 +70,22 @@ local function err_cmd(message)
return "\\PackageError{PyLuaTeX}{" .. message .. "}{}"
end
-function pyluatex.start(executable)
+function pyluatex.start(executable, local_imports)
local script = file.join(folder, "pyluatex-interpreter.py")
- local is_windows = package.config:sub(1,1) ~= "/"
- local cmd
+ local is_windows = dir_sep ~= "/"
+
+ local cmd = ""
+ if local_imports then
+ local tex_file = get_tex_file()
+ if tex_file ~= nil then
+ cmd = " \"" .. tex_file .. "\""
+ end
+ end
+ cmd = executable .. " \"" .. script .. "\"" .. cmd
if is_windows then
- cmd = "start /B " .. executable .. " \"" .. script .. "\""
+ cmd = "start /B " .. cmd
else
- cmd = executable .. " \"" .. script .. "\" &"
+ cmd = cmd .. " &"
end
local f = io.popen(cmd, "r")
local port = f:read("*l")
diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
index 6c247993a91..3413dba4c3e 100644
--- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
+++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
@@ -1,15 +1,15 @@
%% 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
+%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
-%% and version 1.3 or later is part of all distributions of LaTeX
+%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2022/02/13 v0.4.2 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2022/03/10 v0.4.3 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
@@ -27,20 +27,16 @@
\DeclareStringOption[python3]{executable}
\DeclareBoolOption{ignoreerrors}
\DeclareBoolOption{verbose}
+\DeclareBoolOption[true]{localimports}
\DeclareStringOption[veryveryend]{shutdown}
\ProcessKeyvalOptions*
-\ifpyluatex@ignoreerrors
- \directlua{pyluatex.ignore_errors = true}
-\else
- \directlua{pyluatex.ignore_errors = false}
-\fi
-\ifpyluatex@verbose
- \directlua{pyluatex.verbose = true}
-\else
- \directlua{pyluatex.verbose = false}
-\fi
-\directlua{pyluatex.start([==[\pyluatex@executable]==])}
+\directlua{pyluatex.ignore_errors = \ifpyluatex@ignoreerrors true\else false\fi}
+\directlua{pyluatex.verbose = \ifpyluatex@verbose true\else false\fi}
+\directlua{pyluatex.start(
+ [==[\pyluatex@executable]==],
+ \ifpyluatex@localimports true\else false\fi
+)}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_if_eq:nnTF { V }