Juliacon 2024

CodeEvaluation.jl: emulating Julia code evaluations
07-12, 10:10–10:20 (Europe/Amsterdam), REPL (2, main stage)

CodeEvaluation.jl and its companion IOCapture.jl are two small Julia packages that offer simple interfaces for emulating(*) Julia code execution (e.g. when evaluating code examples in documents). The talk will give a brief overview of the packages' interfaces, and discusses the challenges of trying to emulate Julia code execution.


CodeEvaluation.jl is a higher-level package that offers an interface for executing Julia code snippets, and then capturing the outputs. You provide a code snippet as a string, and the package then tries to run it as if you pasted it into a clean REPL or started it as a script from the command line. The captured outputs aim to be a faithful representation of what you would see in the terminal.

One non-trivial piece of the puzzle is the output capture. IOCapture.jl is a lightweight package that offers a simple interface to capture outputs (in particular, the standard output and error streams, and also the output from the logging macros) from arbitrary code execution, hiding away the complexity from you.

Their main users for these packages is tooling that evaluates user-written code snippets, such as documentation and report generators. The code in these packages has been battle tested in the Documenter.jl code base for a long time, and is now factored out in the hopes is that it will be useful people writing similar tools.

Acknowledgments: much of the hard implementation work was done by other contributors, and my main contribution here is factoring this into a separate package.

(*) Just for clarity, the CodeEvaluation is not a Julia emulator, but evaluates the code snippets in the running Julia process. However, does tricks to make it look as if the code is running in a clean Main module.

See also:

Morten is a physicist & software engineer from Estonia, but based in Auckland, New Zealand. He's one of the maintainers Documenter.jl and the JuliaDocs package ecosystem, and works as a software engineer at JuliaHub.

GitHub: @mortenpi

This speaker also appears in: