Skip to content

msmu.pv.to_script

Generate editable Python calls with source/output hash checks.

If filename is supplied, write UTF-8 Python source (overwriting an existing file) and return None. Otherwise return the source text.

Accepts the same file-backed histories and options as replay(). The generated script requires msmu, checks the recorded environment at execution, and leaves its final MuData in mdata. Scripts enable hashing even when verification is disabled. Generation neither reads inputs nor executes calls.

Parameters:

Name Type Description Default
history MuData | dict

MuData or decoded history from get_log; supported workflows are described by replay.

required
filename str | Path | None

Optional output path; an existing file is overwritten.

None
sources dict | None

Mapping from recorded file paths/URLs to replacements, as in replay.

None
verify bool

Include input/output hash verification. Requires recorded hashes when True and checks the current MuData against the last recorded output before export.

True

Returns:

Type Description
str | None

Python source string when filename is omitted; otherwise None after writing the file.

Notes

Export does not execute the workflow or modify the supplied history. Decoded histories have no current MuData to compare. A failed validation leaves the destination file unchanged.

Examples:

import msmu as mm
script = mm.pv.to_script(mdata)