The Python binding (kpy/): klammertext.Machine from a script

Assembled from klammertext-dev ed13dfaa5b7a.  kpy/klammertext.cpp is a
CPython extension module giving a Python script an instance of the
Machine class -- ktext in-process, set up through the same functions the
command uses.  Errors map one-to-one to Python exceptions under the C++
names; an @eval's Python exception is chained as __cause__.  Built by
make -C mac, found through PYTHONPATH (env/runtime.env sets it), tested
by tst/kpy_test.sh.  Three engine changes came with it: Error::message(),
set_command_state(), and the @eval error report carrying its traceback.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uv7KWxafinDPraswEf4GsC
This commit is contained in:
ackandClaude Fable 5.1 committed 2026-09-08 16:54:21 +02:00
1 parent e4f1307aa9
commit 760fda5470
17 files changed
+1241 -78

No files matched your search

+15
View File
@@ -20,3 +20,18 @@ parse_args(
std::string output_basename, bool display_only);
void load_klammersets(Machine& machine, const strings_t& symbols);
// The state a command gives a Machine before anything is read: the frame
// named for the command and the K_* variables that describe the run --
// target, output directory and basename, whether output is displayed rather
// than written, the input filenames, the verbosity, and the input directory
// (the first input file's, or the cwd when there is none). This was the top
// of ktext's main(), and it is policy, not mechanism: a klammer set reads
// these names (@document reads K_stdout_only and K_output_dir), so a second
// consumer of the Machine -- the Python binding in kpy/ -- must set exactly
// the same ones or a document that renders under ktext fails under it. One
// function, two callers, nothing restated.
void set_command_state(
Machine& machine, const std::string& frame_name, const std::string& target,
const std::vector<std::string>& input_filenames, const std::string& output_dir,
const std::string& output_basename, bool display_only);