Skip to content

Commit

Permalink
updated to reorder the remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Jun 20, 2017
1 parent aab1b3b commit 420e2ca
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,12 +1,12 @@
Package: ghtravis
Type: Package
Title: Interfaces with GitHub API and Travis
Version: 0.4.1.1
Version: 0.4.3
Author: John Muschelli
Maintainer: John Muschelli <muschellij2@gmail.com>
Description: Interfaces and compares things on 'GitHub'
'API' and 'Travis' 'CI'.
Imports: utils, devtools, yaml, httr
Imports: utils, devtools, yaml, httr, igraph
License: GPL-2
Encoding: UTF-8
LazyData: true
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Expand Up @@ -26,9 +26,12 @@ export(parse_one_remote)
export(parse_remotes)
export(read_dcf)
export(remote_binaries)
export(remote_order)
export(remote_package_dcf)
export(remote_package_deps)
export(remote_package_names)
export(reorder_remotes)
export(rewrite_remotes)
export(set_update_var)
export(split_remotes)
export(subset_remote)
Expand All @@ -41,6 +44,8 @@ importFrom(httr,GET)
importFrom(httr,authenticate)
importFrom(httr,content)
importFrom(httr,stop_for_status)
importFrom(igraph,degree)
importFrom(igraph,graph_from_adjacency_matrix)
importFrom(utils,compareVersion)
importFrom(utils,download.file)
importFrom(utils,install.packages)
Expand Down
24 changes: 14 additions & 10 deletions R/drop_remotes.R
Expand Up @@ -4,17 +4,22 @@
#'
#' @param path Path to DESCRIPTION file
#' @param drop_remotes Packages for Remotes to Drop
#' @param reorder Should remotes be reordered after running
#' @param ... if \code{reorder = TRUE} then arguments passed to
#' \code{\link{reorder_remotes}}
#'
#' @return Rewrites the DESCRIPTION file without remotes
#' @export
#'
#' @examples
#' path = example_description_file()
#' x = drop_remotes(path)
#' x = drop_remotes(path, reorder = TRUE)
#' readLines(x)
drop_remotes = function(
path = "DESCRIPTION",
drop_remotes = NULL) {
drop_remotes = NULL,
reorder = FALSE,
...) {

# remotes = get_remotes(path )
rres = read_dcf(path)
Expand Down Expand Up @@ -46,15 +51,14 @@ drop_remotes = function(
} else {
remotes = NULL
}
res$Remotes = remotes
nres = names(res)
res = as.data.frame(res,
stringsAsFactors = FALSE)
names(res) = nres

write.dcf(x = res,
file = path)
return(path)
res = rewrite_remotes(
path = path,
remotes = remotes)
if (reorder) {
res = reorder_remotes(path = path, ...)
}
return(res)
}


5 changes: 5 additions & 0 deletions R/install_remotes_no_dep.R
Expand Up @@ -3,6 +3,7 @@
#'
#' @param path Path to DESCRIPTION file
#' @param package Package to subset. If NULL, then all will be installed
#' @param reorder should remotes be reordered before running
#' @param drop Remotes should be dropped after installing
#' @param ... arguments to pass to install_github
#' @return Character vector of remotes
Expand All @@ -17,13 +18,17 @@
install_remotes_no_dep = function(
path = "DESCRIPTION",
package = NULL,
reorder = TRUE,
drop = TRUE,
...) {
if (!is.null(package)) {
if (all(package == "")) {
package = NULL
}
}
if (reorder) {
reorder_remotes(path = path)
}
remotes = subset_remote(path = path, package = package)
if (length(remotes) == 0) {
return(NULL)
Expand Down
78 changes: 78 additions & 0 deletions R/remote_order.R
@@ -0,0 +1,78 @@

#' Order of the Remotes for Installation
#'
#' @param path Path to DESCRIPTION file
#' @param ... arguments passed to \code{\link{remote_package_deps}}
#' @param max_iter Number of iterations - shouldn't have to change,
#' stops from infinite loop
#'
#' @return Order of remotes
#' @export
#' @importFrom igraph graph_from_adjacency_matrix degree
#' @examples
#' path = example_description_file()
#' x = remote_order(path = path)
#' x
remote_order = function(
path = "DESCRIPTION",
...,
max_iter = 200){

repo = get_remotes(path = path)
if (length(repo) == 0) {
return(NULL)
}
parsed = parse_remotes(repo)
all_packs = sapply(parsed, `[[`, "repo")

L = remote_package_deps(
repo = repo,
dependencies = c("Depends", "Imports"),
...)
packs = names(L)
stopifnot(all(all_packs %in% packs))
names(repo) = packs
dep_mat = sapply(L, function(x) {
packs %in% x$name
})
rownames(dep_mat) = packs

install_order = list()
i = 1
while(length(packs) > 0) {
graph = igraph::graph_from_adjacency_matrix(
dep_mat,
mode = "directed")

outs = igraph::degree(graph, mode = "in")
installer = names(outs)[outs == 0]
install_order = c(install_order,
list(installer))
# no_dep = names(deg)[deg == 0]

keep = !(packs %in% installer)
dep_mat = dep_mat[keep, keep, drop = FALSE]
packs = packs[keep]
i = i + 1
if (i > max_iter) {
stop("something is wrong")
}
}
install_order = unlist(install_order)
remotes = repo[ install_order]
return(remotes)
}

#' @export
#' @rdname remote_order
reorder_remotes = function(
path = "DESCRIPTION",
...){
remotes = remote_order(path = path, ...)
res = rewrite_remotes(path = path, remotes = remotes)
return(res)
}




17 changes: 9 additions & 8 deletions R/remote_package_deps.R
Expand Up @@ -25,11 +25,13 @@ all_remote_package_deps = function(
"LinkingTo", "Suggests"),
exclude_remotes = TRUE) {
repo = get_remotes(path = path)
res = remote_package_deps(repo = repo,
L = remote_package_deps(repo = repo,
dependencies = dependencies,
...)
packs = res$packages
deps = res$dependencies
packs = names(L)
deps = do.call("rbind", L)
rownames(deps) = NULL
deps = unique(deps)
if (exclude_remotes) {
deps = deps[ !(deps$name %in% packs), , drop = FALSE]
}
Expand All @@ -45,7 +47,7 @@ remote_package_deps = function(
"LinkingTo", "Suggests")) {
tmp_dcf = get_remote_package_dcf(...)
L = vector(mode = "list", length = length(tmp_dcf))
packs = rep(NA, length = length(tmp_dcf))
# packs = rep(NA, length = length(tmp_dcf))
for (iL in seq_along(tmp_dcf)) {
tmp = tmp_dcf[[iL]]
if (is.na(tmp)) {
Expand All @@ -54,12 +56,11 @@ remote_package_deps = function(
} else {
L[[iL]] = get_dep_table(path = tmp,
dependencies = dependencies)
packs[iL] = read_dcf(tmp)$dcf$Package
names(L)[iL] = read_dcf(tmp)$dcf$Package
# packs[iL] = read_dcf(tmp)$dcf$Package
}
}
L = do.call("rbind", L)
L = unique(L)
L = list(dependencies = L, packages = packs)
# names(L) = packs
return(L)
}

Expand Down
21 changes: 21 additions & 0 deletions R/rewrite_remotes.R
@@ -0,0 +1,21 @@

#' Rewrite DESCRIPTION file overwriting Remotes
#'
#' @param path Path to DESCRIPTION file
#' @param remotes Packages for remotes field
#'
#' @return Name of path
#' @export
rewrite_remotes = function(path, remotes = NULL) {
rres = read_dcf(path = path)
res = rres$dcf
res$Remotes = remotes
nres = names(res)
res = as.data.frame(res,
stringsAsFactors = FALSE)
names(res) = nres

write.dcf(x = res,
file = path)
return(path)
}
10 changes: 8 additions & 2 deletions man/drop_remotes.Rd

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

6 changes: 4 additions & 2 deletions man/install_remotes_no_dep.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/remote_order.Rd

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

19 changes: 19 additions & 0 deletions man/rewrite_remotes.Rd

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

0 comments on commit 420e2ca

Please sign in to comment.