Skip to content

Commit

Permalink
feat(app): #77 move param parsing to script instead of function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAxthelm committed Aug 6, 2024
1 parent 66a4c15 commit 5470dc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
41 changes: 1 addition & 40 deletions R/run_pacta.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run_pacta <- function(
raw_params = commandArgs(trailingOnly = TRUE),
params,
pacta_data_dir = Sys.getenv("PACTA_DATA_DIR"),
output_dir = Sys.getenv("ANALYSIS_OUTPUT_DIR"),
portfolio_dir = Sys.getenv("PORTFOLIO_DIR")
Expand All @@ -20,45 +20,6 @@ run_pacta <- function(
}
log_info("Running PACTA")

# Read Params
log_trace("Processing input parameters.")
if (length(raw_params) == 0L || all(raw_params == "")) {
log_error("No parameters specified.")
}

log_trace("Validating raw input parameters.")
raw_input_validation_results <- jsonvalidate::json_validate(
json = raw_params,
schema = system.file(
"extdata", "schema", "rawParameters.json",
package = "workflow.pacta"
),
verbose = TRUE,
greedy = FALSE,
engine = "ajv"
)
if (raw_input_validation_results) {
log_trace("Raw input parameters are valid.")
} else {
log_error(
"Invalid raw input parameters. ",
"Must include \"inherit\" key, or match full schema."
)
stop("Invalid raw input parameters.")
}

params <- pacta.workflow.utils:::parse_params(
json = raw_params,
inheritence_search_paths = system.file(
"extdata", "parameters",
package = "workflow.pacta"
),
schema_file = system.file(
"extdata", "schema", "portfolioParameters.json",
package = "workflow.pacta"
)
)

run_audit(
portfolio_files = params[["portfolio"]][["files"]],
pacta_data_dir = pacta_data_dir,
Expand Down
15 changes: 15 additions & 0 deletions inst/extdata/scripts/run_pacta.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
logger::log_threshold(Sys.getenv("LOG_LEVEL", "INFO"))
params <- pacta.workflow.utils::parse_raw_params(
json = commandArgs(trailingOnly = TRUE),
inheritence_search_paths = system.file(
"extdata", "parameters",
package = "workflow.pacta"
),
schema_file = system.file(
"extdata", "schema", "portfolioParameters.json",
package = "workflow.pacta"
),
raw_schema_file = system.file(
"extdata", "schema", "rawParameters.json",
package = "workflow.pacta"
)
)
workflow.pacta:::run_pacta(commandArgs(trailingOnly = TRUE))

0 comments on commit 5470dc3

Please sign in to comment.