
Run Python scripts, in order, each in an isolated Docker container
Source:R/reproducibility_check_python_docker.R
repro_run_scripts_py_docker.RdThe Docker-backed twin of repro_run_scripts_py(): same return contract,
same per-script semantics (skip on missing inputs / parse failure,
timeout, error classification), but each script runs via docker run --network none --read-only --user <non-root> instead of a processx
subprocess on the host — so the code cannot reach the network (unless net
is given) or touch anything outside the mounted sandbox and library, even
deliberately.
Arguments
- run_tbl
repro_write_scripts()output (file_name,script_path,run_dir) —run_dirmust be the SAME directory as (or a subdirectory of)sandbox_root- order
a vector of
file_names in the order to run- sandbox_root
the materialised layout root on the HOST — mounted read-write at
/sandbox- lib_dir
throwaway
pip install --targetlibrary ON THE HOST (or NULL) — mounted at/pylibwhen supplied, writable, so a package can keep data in its own folder- image
the Docker image to run scripts in (see .repro_docker_default_image_py)
- timeout
per-script timeout in seconds
- skip
character vector of
file_names to record asskipped_missing_inputsinstead of running- parses
named logical (by file_name); a file that will not parse is recorded
not_parsedand not run- failed_deps
character vector of package names
repro_install_deps_py_docker()could not install- deadline
the time (
Sys.time()plus the time for all scripts together) after which no script is started, recorded asskipped_time_limit; a running script is stopped then.NULL(the default) sets no such limit.- net
NULL(the default) runs with the network off; seerepro_run_scripts_docker().
Value
a data frame — identical columns to repro_run_scripts_py()'s
return: file_name, outcome, error, error_type, undefined_var,
stdout, stderr, elapsed, script_lines, captures (always NULL)
Examples
if (FALSE) { # \dontrun{
# needs Docker
root <- file.path(tempdir(), "run_demo_py")
plan <- data.frame(file_name = "analysis.py", target_path = "analysis/analysis.py")
code <- list(analysis.py = "print(sum([1, 2, 3]))")
run_tbl <- repro_write_scripts(code, list(), plan, root, lang = "Python")
repro_run_scripts_py_docker(run_tbl, order = "analysis.py", sandbox_root = root)
} # }