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

Better messaging handling #187

Merged
merged 16 commits into from
Aug 22, 2023
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: staged.dependencies
Type: Package
Title: Install R packages from Particular Git Branches
Version: 0.3.1
Version: 0.3.1.9001
Authors@R: c(
person("Adrian", "Waddell", email = "[email protected]", role = c("aut", "cre")),
person("Maximilian", "Mordig", email = "[email protected]", role = "aut"),
person("Nikolas", "Burkoff", email = "[email protected]", role = "aut")
)
Imports:
checkmate,
desc,
devtools,
digest,
Expand Down Expand Up @@ -47,6 +48,7 @@ Suggests:
visNetwork
VignetteBuilder: knitr
Collate:
'argument_convention.R'
'caching.R'
'dependencies.R'
'dependencies_app.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export(install_deps)
export(install_deps_app)
export(install_deps_job)
export(update_with_direct_deps)
export(verbose_sd_get)
export(verbose_sd_rm)
export(verbose_sd_set)
importFrom(dplyr,"%>%")
importFrom(rlang,.data)
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# staged.dependecies 0.3.1.9001

### Enhancements
* Added functions to set and remove general level of messaging as option variable `verbose_level_staged.deps`.
* Added `argument_convention.R` with default parameter definitions.

### Miscellaneous
* Replaced internal function that checks directory existence with assertion from `checkmate` when there is no prefix.

# staged.dependecies 0.3.1

* Enhanced support of subdirectories for gitlab.
Expand Down
12 changes: 12 additions & 0 deletions R/argument_convention.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Default Arguments
#'
#' The documentation to this function lists all the arguments in `staged.dependencies`
#' that are used repeatedly.
#'
#' @param verbose (`numeric`) \cr verbosity level, incremental;
#' (0: None, 1: packages that get installed + high-level git operations,
#' 2: includes git checkout infos)
#'
#' @keywords internal
#' @name argument_convention
NULL
47 changes: 21 additions & 26 deletions R/caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ clear_cache <- function(pattern = "*") {
if (!identical(pattern, "*")) {
direcs <- dir(get_packages_cache_dir())
if (length(direcs) == 0) {
message("Cache empty")
message_if_verbose("Cache empty")
} else {
message("Directories remaining in cache:\n", paste(direcs, collapse = "\n"))
message_if_verbose("Directories remaining in cache:\n", paste(direcs, collapse = "\n"))
}
}
}

# copies example config file to package settings directory
# fails if copy did not work
copy_config_to_storage_dir <- function() {

path <- file.path(get_storage_dir(), "config.yaml")

if (!file.exists(path)) {
Expand Down Expand Up @@ -79,9 +78,7 @@ get_active_branch_in_cache <- function(repo, host, local = FALSE) {
# copies a local directory to the cache dir and commits the current state in
# that cache dir, so the SHA can be added to the DESCRIPTION file
# note: files in .gitignore are also available to the package locally
copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule, verbose = 0) {
check_verbose_arg(verbose)

copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule) {
local_dir <- fs::path_dir(git2r::discover_repository(local_dir))

check_dir_exists(local_dir, prefix = "Local directory: ")
Expand All @@ -91,9 +88,11 @@ copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule,
fs::dir_delete(repo_dir)
}

if (verbose >= 1) {
message(paste("Copying local dir", local_dir, "to cache dir", repo_dir))
}
message_if_verbose("Copying local dir ", local_dir, " to cache dir ", repo_dir, required_verbose = 2)
message_if_verbose("Copying local dir ", local_dir, " to cache dir...",
required_verbose = 1, is_equal = TRUE
)

# file.copy copies a directory inside an existing directory
# we ignore the renv sub directories as it is large (so slow), has long
# path names (so causes problems on Windows) and is not needed
Expand Down Expand Up @@ -151,12 +150,11 @@ copy_local_repo_to_cachedir <- function(local_dir, repo, host, select_ref_rule,
(length(git2r::status(repo_dir)$unstaged) > 0) ||
(length(git2r::status(repo_dir)$untracked) > 0)) {
# add all files, including untracked (all argument of git2r::commit does not do this)
if (verbose >= 2) {
message(
"Adding all of the following files: \n",
paste(utils::capture.output(git2r::status(repo_dir)), collapse = "\n")
)
}
static_msg <- paste0(
"Adding all of the following files: \n",
paste(utils::capture.output(git2r::status(repo_dir)), collapse = "\n")
)
message_if_verbose(static_msg, required_verbose = 2)
git2r::add(repo_dir, ".")
git2r::commit(
repo_dir,
Expand Down Expand Up @@ -215,7 +213,6 @@ get_hashed_repo_to_dir_mapping <- function(local_repos) {
#' The packages listed there are internal packages. All other dependencies
#' listed in the `DESCRIPTION` file are external dependencies.
#'
#' @md
#' @param repos_to_process `list` of `list(repo, host)` repos to start from
#' @param ref (`character`) tag/branch to build
#' @param direction (`character`) direction in which to discover packages
Expand All @@ -225,23 +222,20 @@ get_hashed_repo_to_dir_mapping <- function(local_repos) {
#' local rather than cloned; columns are `repo, host, directory`
#' @param fallback_branch (`character`) the default branch to try to use if
#' no other matches found
#' @param verbose (`numeric`) verbosity level, incremental;
#' (0: None, 1: packages that get installed + high-level git operations,
#' 2: includes git checkout infos)
#'
#' @return A data frame, one row per checked out repository with columns
#' repo, host and cache_dir
#'
#' @keywords internal
rec_checkout_internal_deps <- function(repos_to_process, ref,
direction = "upstream",
local_repos = get_local_pkgs_from_config(),
fallback_branch = "main",
verbose = 0) {
fallback_branch = "main") {
stopifnot(
is.list(repos_to_process)
)
direction <- check_direction_arg_deprecated(direction)
check_direction_arg(direction)
check_verbose_arg(verbose)

local_repo_to_dir <- get_hashed_repo_to_dir_mapping(local_repos)
rm(local_repos)
Expand All @@ -268,8 +262,7 @@ rec_checkout_internal_deps <- function(repos_to_process, ref,
local_repo_to_dir[[hashed_repo_and_host]], repo_and_host$repo, repo_and_host$host,
select_ref_rule = function(available_refs) {
determine_ref(ref, available_refs, fallback_branch = fallback_branch)
},
verbose = verbose
}
)
} else {
repo_info <- checkout_repo(
Expand All @@ -279,8 +272,7 @@ rec_checkout_internal_deps <- function(repos_to_process, ref,
select_ref_rule = function(available_refs) {
determine_ref(ref, available_refs, fallback_branch = fallback_branch)
},
must_work = (length(hashed_processed_repos) == 0), # first repo must be accessible
verbose = verbose
must_work = (length(hashed_processed_repos) == 0) # first repo must be accessible
)
}

Expand Down Expand Up @@ -312,5 +304,8 @@ rec_checkout_internal_deps <- function(repos_to_process, ref,
df$accessible <- unlist(unname(hashed_repos_accessible))
df$ref <- unlist(unname(hashed_repos_refs))
df$sha <- unlist(unname(hashed_repos_shas))

message_if_verbose("Current cache directory: ", fs::path_norm(get_packages_cache_dir()))

return(df)
}
Loading