Skip to content

Commit

Permalink
Update R tester to allow renv.lock file upload (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
soheegoo authored Jan 16, 2025
1 parent 5e276a5 commit de4c719
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented here.

## [unreleased]
- Update python, pyta and jupyter testers to allow a requirements file (#580)
- Update R tester to allow a renv.lock file (#581)

## [v2.6.0]
- Update python versions in docker file (#568)
Expand Down
18 changes: 18 additions & 0 deletions server/autotest_server/testers/r/lib/r_renv_setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Script to install dependencies for R tester environment using a renv.lock file.

# Install renv if not already installed
if (!("renv" %in% rownames(installed.packages()))) {
install.packages("renv")
}
library(renv)

# Set the path for the renv.lock file and the env_dir directory
lockfile <- commandArgs(trailingOnly = TRUE)[1]
env_dir <- commandArgs(trailingOnly = TRUE)[2]

if (!file.exists(lockfile)) {
stop("renv.lock file not found: ", lockfile)
}

# Initialize the renv environment and restore dependencies from the lockfile
renv::restore(lockfile = lockfile, library = env_dir)
5 changes: 5 additions & 0 deletions server/autotest_server/testers/r/settings_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"title": "R environment",
"type": "object",
"properties": {
"renv.lock": {
"title": "Use renv to set up environment",
"type": "boolean",
"default": false
},
"requirements": {
"title": "Package requirements",
"type": "string"
Expand Down
14 changes: 13 additions & 1 deletion server/autotest_server/testers/r/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

def create_environment(settings_, env_dir, default_env_dir):
env_data = settings_.get("env_data", {})
req_string = env_data.get("requirements", "")
lockfile_submitted = env_data.get("renv.lock", False)
os.makedirs(env_dir, exist_ok=True)
env = {"R_LIBS_SITE": env_dir, "R_LIBS_USER": env_dir}

req_string = env_data.get("requirements", "")
r_tester_setup = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib", "r_tester_setup.R")
subprocess.run(
["Rscript", r_tester_setup, req_string],
Expand All @@ -18,6 +19,17 @@ def create_environment(settings_, env_dir, default_env_dir):
capture_output=True,
)

if lockfile_submitted:
renv_lock_path = os.path.join(env_dir, "../", "files", "renv.lock")
r_renv_setup = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib", "r_renv_setup.R")
if os.path.exists(renv_lock_path):
subprocess.run(
["Rscript", r_renv_setup, renv_lock_path, env_dir],
env={**os.environ, **env},
check=True,
text=True,
capture_output=True,
)
return {**env, "PYTHON": os.path.join(default_env_dir, "bin", "python3")}


Expand Down

0 comments on commit de4c719

Please sign in to comment.