Skip to content

Commit

Permalink
updated binary installer to version check
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Jun 15, 2017
1 parent 4b59307 commit 9d61987
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: ghtravis
Type: Package
Title: Interfaces with GitHub API and Travis
Version: 0.2.8.1
Version: 0.2.9
Author: John Muschelli
Maintainer: John Muschelli <muschellij2@gmail.com>
Description: Interfaces and compares things on 'GitHub' 'API' and 'Travis' 'CI'.
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -14,6 +14,7 @@ export(install_remote_binaries)
export(install_remotes_no_dep)
export(latest_release_with_binary)
export(make_full_version)
export(package_comparison_table)
export(package_needs_update)
export(parse_one_remote)
export(parse_remotes)
Expand All @@ -24,6 +25,7 @@ export(set_update_var)
export(split_remotes)
export(subset_remote)
export(sys_ext)
export(update_these_packages)
importFrom(devtools,github_pat)
importFrom(devtools,install_github)
importFrom(httr,GET)
Expand Down
80 changes: 42 additions & 38 deletions R/install_remote_binaries.R
Expand Up @@ -7,7 +7,6 @@
#' @param remotes Remotes to get binaries for - in case not going from DESCRIPTION,
#' passed to \code{\link{remote_binaries}}
#' @param package Specific package to install
#' @param drop_all If TRUE, then will only drop packages that are installed
#' @param verbose Print diagnostic messages
#'
#' @return Invisible NULL
Expand All @@ -19,62 +18,67 @@
#' install_remote_binaries(path = path)
#' }
#' @importFrom utils install.packages installed.packages remove.packages
# @param update_only Should only packages needing update be installed?
# @param drop_all If TRUE, then will only drop packages that are installed
install_remote_binaries = function(
path = "DESCRIPTION",
remotes = NULL,
package = NULL,
drop_all = TRUE,
# update_only = FALSE,
verbose = TRUE
) {

urls = remote_binaries(path = path, remotes = remotes)
if (!is.null(package)) {
if (package != "") {
urls = urls[intersect(package, names(urls))]
}
}

#urls are the only ones with binaries

if (length(urls) > 0) {
packs = names(urls)
urls = unlist(urls)
for (ipack in seq_along(urls)) {
pack = packs[ipack]
url = urls[ipack]
if (verbose) {
message(paste0("Installing ", pack,
" package binaries"))
}
# run_url =
destfile = file.path(tempdir(), basename(url))
## if only update them

# if (update_only) {
# updaters = update_these_packages(path = path)
# packs = intersect(packs, updaters)
# urls = urls[packs]
# }

if (length(urls) > 0) {

# files = mapply(function(url, destfile){
download.file(url, destfile, method = "wget",
quiet = !verbose)
# }, urls, destfiles)
# files = NULL
install.packages(destfile,
repos = NULL,
type = .Platform$pkgType)
for (ipack in seq_along(urls)) {
pack = packs[ipack]
url = urls[ipack]
if (verbose) {
message(paste0("Installing ", pack,
" package binaries"))
}

destfile = file.path(tempdir(), basename(url))

download.file(
url, destfile,
method = "wget",
quiet = !verbose)

install.packages(
destfile,
repos = NULL,
type = .Platform$pkgType)
}
}
if (!drop_all) {
# if (!drop_all) {
# ip = installed.packages()
# need to check versions!
dd = get_dep_table( path = path,
dependencies = c("Depends", "Imports",
"LinkingTo"),
limit_compare = TRUE)
cn = colnames(dd)
cn[ cn == "name"] = "Package"
cn[ cn == "version"] = "required_version"
colnames(dd) = cn
ip = installed.packages()[, c("Package", "Version")]
dd = merge(dd, ip, all.x = TRUE)
keep_packs = update_these_packages(path = path)
# utils::remove.packages(keep_packs)
packs = packs[ !(packs %in% keep_packs)]
# }

dd$comp = apply(dd[, c("required_version", "Version")], 1, function(x) {
x = make_full_version(x)
compareVersion(x[1], x[2])
})
keep_packs = dd[ dd$comp > 0 , "Package"]
utils::remove.packages(keep_packs)
packs = packs[ packs %in% ip & !(packs %in% keep_packs)]
}
if (file.exists(path)) {
drop_remotes(path = path, drop_remotes = packs)
}
Expand Down
5 changes: 3 additions & 2 deletions R/package_needs_update.R
Expand Up @@ -19,8 +19,9 @@ package_needs_update = function(
v = c("version" = version,
"installed" = cur_ver)
v = make_full_version(v)
utils::compareVersion(v["version"],
v["installed"]) > 0
utils::compareVersion(
v["version"],
v["installed"]) > 0
}

#' @rdname package_needs_update
Expand Down
7 changes: 5 additions & 2 deletions R/parse_one_remote.R
Expand Up @@ -28,8 +28,11 @@ parse_one_remote <- function(x) {
error = function(e) stop("Unknown remote type: ",
type, call. = FALSE)
)

fun(repo)
args = list(repo)
if (tolower(type) == "github") {
args$auth_token = devtools::github_pat(quiet = TRUE)
}
do.call(fun, args = args)
}

#' @rdname parse_one_remote
Expand Down
55 changes: 55 additions & 0 deletions R/update_these_packages.R
@@ -0,0 +1,55 @@
#' @title Get Comparison Table from Dependencies
#' @description Gets Remotes and compares to installed packages
#'
#' @param path Path to DESCRIPTION file
#' passed to \code{\link{remote_binaries}}
#' @param dependencies List of dependencies to parse
#' @param ... not used
#'
#' @return Invisible NULL
#' @export
#'
#' @examples
#' path = example_description_file()
#' update_these_packages(path = path)
package_comparison_table = function(
path = "DESCRIPTION",
dependencies = c("Depends", "Imports",
"LinkingTo")
) {

dd = get_dep_table( path = path,
dependencies = dependencies,
limit_compare = FALSE)
cn = colnames(dd)
cn[ cn == "name"] = "Package"
cn[ cn == "version"] = "required_version"
colnames(dd) = cn
ip = installed.packages()[, c("Package", "Version")]
ip = data.frame(ip, stringsAsFactors = FALSE)

dd = merge(dd, ip, all.x = TRUE)
# workaround
dd$required_version[ is.na(dd$required_version)] = "0.0.0.0"
dd$required_version[ is.na(dd$Version) ] = "9999.0.0.0"
dd$Version[ is.na(dd$Version)] = "0.0.0.0"

dd$comp = apply(dd[, c("required_version", "Version")], 1, function(x) {
x = make_full_version(x)
compareVersion(x[1], x[2])
})
return(dd)
}


#' @rdname package_comparison_table
#' @export
update_these_packages = function(
...
) {
dd = package_comparison_table(...)
keep_packs = dd[ dd$comp > 0 |
(dd$compare %in% ">" & dd$comp <= 0) , "Package"]
# removers = keep_packs[ keep_packs %in% ip ]
return(keep_packs)
}
6 changes: 3 additions & 3 deletions inst/extdata/DESCRIPTION
@@ -1,4 +1,4 @@
Package: DESCRIPT
Package: example
Type: Package
Title: Test Package
Version: 0.6
Expand All @@ -9,7 +9,7 @@ Description: Blah
License: GPL-2
LazyLoad: yes
Depends: methods, ANTsRCore (>= 0.2)
Imports: ITKR, ANTsRCore, psych
Remotes: stnava/ITKR, muschellij2/ANTsRCore, cran/psych@084bdd0ae2630cf31c26d97a6e13e59d3f0f66e6
Imports: ITKR, ANTsR (>= 1), psych
Remotes: stnava/ITKR, muschellij2/ANTsRCore, stnava/ANTsR, cran/psych@084bdd0ae2630cf31c26d97a6e13e59d3f0f66e6
VignetteBuilder: knitr
RoxygenNote: 6.0.1
4 changes: 1 addition & 3 deletions man/install_remote_binaries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions man/package_comparison_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d61987

Please sign in to comment.