Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design function dependencies #185

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Collate:
'dependencies.R'
'dependencies_app.R'
'dependencies_helper.R'
'fnc_deps.R'
'git_tools.R'
'graph_methods.R'
'host.R'
Expand Down
10 changes: 9 additions & 1 deletion R/caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule)
branch_flag = "local"
)
ref <- select_ref_rule(available_refs)
stopifnot(ref %in% available_refs$ref)

# Safenet for missing branch
if (!(ref %in% available_refs$ref)) {
stop("Reference branch ", ref,
" not found between the available ones in repo directory: ",
repo_dir) # nocov
}

if (ref != get_current_branch(repo_dir)) {
# if ref is a branch and you are on the wrong branch throw error
Expand All @@ -146,6 +152,7 @@ copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule)
}
}

# If there is something left unstaged or uncommitted it does it for you (should it?)
if ((length(git2r::status(repo_dir)$staged) > 0) ||
(length(git2r::status(repo_dir)$unstaged) > 0) ||
(length(git2r::status(repo_dir)$untracked) > 0)) {
Expand Down Expand Up @@ -265,6 +272,7 @@ rec_checkout_internal_deps <- function(repos_to_process, ref,
}
)
} else {
# Case some local repos were not specified
repo_info <- checkout_repo(
get_repo_cache_dir(repo_and_host$repo, repo_and_host$host),
get_repo_url(repo_and_host$repo, repo_and_host$host),
Expand Down
20 changes: 15 additions & 5 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# todo: local_repos to data.frame: package name to directory: no, because this means that the package needs to be fetched from the remote first
# todo? unlink(get_packages_cache_dir(), recursive = TRUE); dir.create(get_packages_cache_dir())

# Helper function copied from fs internals
is_windows <- function() {
if (isTRUE(Sys.getenv("FS_IS_WINDOWS", "FALSE") == "TRUE")) {
return(TRUE)
}
tolower(Sys.info()[["sysname"]]) == "windows"
}
Comment on lines +7 to +13
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This in theory could check if on windows to solve #177


#' Create dependency structure of your package collection
#' @param project (`character`) If `project_type` is `local` then
Expand Down Expand Up @@ -72,11 +79,14 @@ dependency_table <- function(project = ".",
renv_profile = NULL,
verbose = 1) {
# validate arguments
stopifnot(is.data.frame(local_repos) || is.null(local_repos))
checkmate::assert_data_frame(local_repos, null.ok = TRUE)
direction <- check_direction_arg_deprecated(direction)
check_direction_arg(direction)
stopifnot(project_type %in% c("local", "repo@host"))
stopifnot(rlang::is_scalar_character(fallback_branch))
checkmate::assert_choice(project_type, c("local", "repo@host"))
checkmate::assert_character(fallback_branch, max.len = 1)

# Ideally here we could catch the error for windows and too long paths
# if (is_windows())

if (verbose != 1) {
checkmate::assert_int(verbose, lower = 0, upper = 2)
Expand Down Expand Up @@ -110,12 +120,12 @@ dependency_table <- function(project = ".",
repo_to_process <- list(parse_remote_project(project))
}


# a dataframe with columns repo, host, ref, sha, cache_dir, accessible (logical)
internal_deps <- rec_checkout_internal_deps(
repo_to_process, ref,
direction = direction,
local_repos = local_repos, fallback_branch = fallback_branch
local_repos = local_repos,
fallback_branch = fallback_branch
)

internal_deps$package_name[internal_deps$accessible] <-
Expand Down
Loading