Skip to content

Commit

Permalink
split source file into multople parts
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Feb 1, 2024
1 parent f2fd810 commit 8d45694
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 83 deletions.
83 changes: 0 additions & 83 deletions R/application/check_dependency/check_dependency.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,87 +36,4 @@ const check_dependency = function(app, context = .get_context()) {
));
}
}
}

#' Check of the required environment symbols
#'
#' @details the environment symbols from the analysis context should be
#' set via the ``set_config`` function.
#'
const check_dependency.context_env = function(requires, context) {
const env = context$configs;
const map = {
'any': "any",
'numeric': "num",
'integer': "int",
'character': "chr",
'logical': "logi",
'function': "function"
};
const env_symbols = names(env);
const err = list(
"environment_symbols(all)" = `[${paste(env_symbols, sep = ", ")}]`
);

for(name in names(requires)) {
const mark = requires[[name]];
const missing = !(name in env);

if (missing) {
err[[name]] = "missing";
} else if (mark != "any") {
if (map[[mark]] != typeof(env[[name]])) {
err[[name]] = "mis-matched";
}
}
}

if (length(err) <= 1) {
NULL;
} else {
return(err);
}
}

#' Check for the upstream file dependency
#'
#' @param requires the required temp work files, should be a tuple list
#' object that contains the app reference and the related temp workfile,
#' example data format of this tuple list would be:
#'
#' list(app1 = [file1, file2, ...], app2 = file3, ...)
#'
#' @details the workfile path in the ``requires`` tuple file list should be
#' a relative file path which is relative to the app workdir
#'
const check_dependency.localfiles = function(requires, context) {
const err = list();
const verbose = as.logical(getOption("verbose"));

if (verbose) {
print("checks for the required app dependency modules:");
print(names(requires));

str(requires);
}

for(appName in names(requires)) {
# the required file in the requires list is a relative file
# path which is relative to the app workspace
# the full path will be combine in this for loop and then
# test for work file is exists or not.
const workdir = WorkflowRender::workspace(appName);
const file_rels = requires[[appName]];
const checks = `${workdir}/${file_rels}` |> which(filename -> !file.exists(filename));

if (length(checks) > 0) {
err[[appName]] = checks;
}
}

if (length(err) == 0) {
NULL;
} else {
return(err);
}
}
39 changes: 39 additions & 0 deletions R/application/check_dependency/context_env.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Check of the required environment symbols
#'
#' @details the environment symbols from the analysis context should be
#' set via the ``set_config`` function.
#'
const check_dependency.context_env = function(requires, context) {
const env = context$configs;
const map = {
'any': "any",
'numeric': "num",
'integer': "int",
'character': "chr",
'logical': "logi",
'function': "function"
};
const env_symbols = names(env);
const err = list(
"environment_symbols(all)" = `[${paste(env_symbols, sep = ", ")}]`
);

for(name in names(requires)) {
const mark = requires[[name]];
const missing = !(name in env);

if (missing) {
err[[name]] = "missing";
} else if (mark != "any") {
if (map[[mark]] != typeof(env[[name]])) {
err[[name]] = "mis-matched";
}
}
}

if (length(err) <= 1) {
NULL;
} else {
return(err);
}
}
42 changes: 42 additions & 0 deletions R/application/check_dependency/localfiles.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Check for the upstream file dependency
#'
#' @param requires the required temp work files, should be a tuple list
#' object that contains the app reference and the related temp workfile,
#' example data format of this tuple list would be:
#'
#' list(app1 = [file1, file2, ...], app2 = file3, ...)
#'
#' @details the workfile path in the ``requires`` tuple file list should be
#' a relative file path which is relative to the app workdir
#'
const check_dependency.localfiles = function(requires, context) {
const err = list();
const verbose = as.logical(getOption("verbose"));

if (verbose) {
print("checks for the required app dependency modules:");
print(names(requires));

str(requires);
}

for(appName in names(requires)) {
# the required file in the requires list is a relative file
# path which is relative to the app workspace
# the full path will be combine in this for loop and then
# test for work file is exists or not.
const workdir = WorkflowRender::workspace(appName);
const file_rels = requires[[appName]];
const checks = `${workdir}/${file_rels}` |> which(filename -> !file.exists(filename));

if (length(checks) > 0) {
err[[appName]] = checks;
}
}

if (length(err) == 0) {
NULL;
} else {
return(err);
}
}

0 comments on commit 8d45694

Please sign in to comment.