diff --git a/src/julia/options.py b/src/julia/options.py index 00ba9801..82dc0494 100644 --- a/src/julia/options.py +++ b/src/julia/options.py @@ -145,6 +145,9 @@ def yes_no_etc(*etc): threads: {int, 'auto'} How many threads to use. + +trace_compile: str + Trace precompile statements during execution to the given file. """ @@ -174,6 +177,7 @@ class JuliaOptions(object): inline = Choices("inline", yes_no_etc()) check_bounds = Choices("check_bounds", yes_no_etc()) threads = IntEtc("threads", etc={"auto"}) + trace_compile = String("trace_compile") def __init__(self, **kwargs): unsupported = [] diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py new file mode 100644 index 00000000..0789330e --- /dev/null +++ b/src/julia/tests/test_trace_compile.py @@ -0,0 +1,31 @@ +import re +from pathlib import Path + +from .test_compatible_exe import runcode +from .utils import skip_in_windows + + +@skip_in_windows +def test_trace_file_created(tmpdir): + trace_compile_path = Path(tmpdir) / "trace_compile.jl" + runcode( + f""" + from julia.api import Julia + jl = Julia(trace_compile="{trace_compile_path}") + + from julia import Main + Main.sin(2.0) + """.format( + str(trace_compile_path) + ) + ) + assert (trace_compile_path).exists() + assert len(trace_compile_path.read_text().strip()) > 0 + + # check whether the sin precompilation directive is included in the file + trace_compile_content = Path(trace_compile_path).read_text().strip() + lines = [x for x in trace_compile_content.split("\n") if len(x) > 0] + expected_precompile_line = ( + r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)" + ) + assert any([re.match(expected_precompile_line, x) is not None for x in lines])