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

Fixes #1851 Executed styler against package source #1862

Merged
merged 1 commit into from
Sep 11, 2018
Merged
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
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# devtools 1.13.3.9000
# devtools 1.13.6.9000

* Executed `styler::style_pkg()` to update code style (#1851, @amundsenjunior).

* All `install_*()` functions are now re-exported from remotes rather than being defined in devtools.

Expand Down
18 changes: 12 additions & 6 deletions R/build-readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {

pkg <- as.package(path)

readme_path <- grep(ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE)))
if (length(readme_path) == 0) { return(invisible()) }
readme_path <- grep(
ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE
))
)
if (length(readme_path) == 0) {
return(invisible())
}

readme_path <- file.path(pkg$path, readme_path[[1]])

Expand All @@ -33,7 +38,8 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {

output <- callr::r(build,
args = list(pkg_path = pkg$path, readme_path = readme_path, ... = ..., quiet = quiet),
show = TRUE, spinner = FALSE)
show = TRUE, spinner = FALSE
)

invisible(TRUE)
}
3 changes: 2 additions & 1 deletion R/build-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ build_site <- function(path = ".", quiet = TRUE, ...) {
withr::with_temp_libpaths(action = "prefix", code = {
install(pkg = pkg$path, upgrade_dependencies = FALSE, reload = FALSE, quiet = quiet)
if (isTRUE(quiet)) {
withr::with_output_sink(tempfile(),
withr::with_output_sink(
tempfile(),
pkgdown::build_site(pkg = pkg$path, ...)
)
} else {
Expand Down
14 changes: 9 additions & 5 deletions R/check-devtools.r
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ check_version <- function(pkg = ".") {
pkg <- as.package(pkg)
ver <- unlist(numeric_version(pkg$version))

check_status(length(ver) == 3,
check_status(
length(ver) == 3,
"version number has three components",
paste0("version (", pkg$version, ") should have exactly three components")
)
Expand Down Expand Up @@ -83,8 +84,9 @@ check_news_md <- function(pkg) {
pkg <- as.package(pkg)

news_path <- file.path(pkg$path, "NEWS.md")
if (!file.exists(news_path))
if (!file.exists(news_path)) {
return()
}

ignore_path <- file.path(pkg$path, ".Rbuildignore")
if (!file.exists(ignore_path)) {
Expand All @@ -94,9 +96,10 @@ check_news_md <- function(pkg) {
}

has_news <- grepl("NEWS\\.md", ignore_lines, fixed = TRUE) |
grepl("NEWS.md", ignore_lines, fixed = TRUE)
grepl("NEWS.md", ignore_lines, fixed = TRUE)

check_status(!any(has_news),
check_status(
!any(has_news),
"NEWS.md is not ignored",
"NEWS.md now supported by CRAN and doesn't need to be ignored."
)
Expand All @@ -110,7 +113,8 @@ check_news_md <- function(pkg) {
}

check_remotes <- function(pkg) {
check_status(!has_dev_remotes(pkg),
check_status(
!has_dev_remotes(pkg),
"DESCRIPTION doesn't have Remotes field",
"Remotes field should be removed before CRAN submission."
)
Expand Down
13 changes: 7 additions & 6 deletions R/check-results.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ parse_check_results <- function(path) {

structure(
list(
errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)],
errors = pieces[grepl("... ERROR", pieces, fixed = TRUE)],
warnings = pieces[grepl("... WARN", pieces, fixed = TRUE)],
notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)]
notes = pieces[grepl("... NOTE", pieces, fixed = TRUE)]
),
path = path,
class = "check_results"
Expand All @@ -23,10 +23,10 @@ signal_check_results <- function(x, on = c("none", "error", "warning", "note"))

on <- match.arg(on)
has_problem <- switch(on,
none = FALSE,
error = has$errors,
none = FALSE,
error = has$errors,
warning = has$errors | has$warnings,
note = has$errors | has$warnings | has$notes
note = has$errors | has$warnings | has$notes
)

if (has_problem) {
Expand Down Expand Up @@ -90,8 +90,9 @@ trunc_middle <- function(x, n_max = 25, n_top = 10, n_bottom = 10) {
lines <- strsplit(x, "\n", fixed = TRUE)[[1]]
nlines <- length(lines)

if (nlines <= n_max)
if (nlines <= n_max) {
return(x)
}

paste(c(
lines[1:n_top],
Expand Down
25 changes: 15 additions & 10 deletions R/check-win.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ check_win_oldrelease <- function(pkg = ".", args = NULL, quiet = FALSE, ...) {

check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"),
args = NULL, quiet = FALSE, ...) {

pkg <- as.package(pkg)
version <- match.arg(version, several.ok = TRUE)

if (!quiet) {
message("Building windows version of ", pkg$package, " (", pkg$version, ")",
" for ", paste(version, collapse = ", "),
" with win-builder.r-project.org.\n")
message(
"Building windows version of ", pkg$package, " (", pkg$version, ")",
" for ", paste(version, collapse = ", "),
" with win-builder.r-project.org.\n"
)
if (interactive() && yesno("Email results to ", maintainer(pkg)$email, "?")) {
return(invisible())
}
Expand All @@ -59,15 +60,19 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
built_path <- pkgbuild::build(pkg$path, tempdir(), args = args, quiet = quiet, ...)
on.exit(unlink(built_path))

url <- paste0("ftp://win-builder.r-project.org/", version, "/",
basename(built_path))
url <- paste0(
"ftp://win-builder.r-project.org/", version, "/",
basename(built_path)
)
lapply(url, upload_ftp, file = built_path)

if (!quiet) {
message("[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ",
"Check ", maintainer(pkg)$email, " for a link to the built package",
if (length(version) > 1) "s" else "",
" in 15-30 mins.")
message(
"[", strftime(Sys.time(), "%I:%M %p (%Y-%m-%d)"), "] ",
"Check ", maintainer(pkg)$email, " for a link to the built package",
if (length(version) > 1) "s" else "",
" in 15-30 mins."
)
}

invisible()
Expand Down
4 changes: 1 addition & 3 deletions R/check.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ check <- function(pkg = ".",
check_dir = tempdir(),
cleanup = TRUE,
error_on = c("never", "error", "warning", "note")) {

pkg <- as.package(pkg)
withr::local_options(list(warn = 1))

Expand Down Expand Up @@ -154,9 +153,8 @@ check <- function(pkg = ".",
check_built <- function(path = NULL, cran = TRUE,
remote = FALSE, incoming = remote, force_suggests = FALSE,
run_dont_test = FALSE, manual = FALSE, args = "--timings",
env_vars = NULL, check_dir = tempdir(), quiet = FALSE,
env_vars = NULL, check_dir = tempdir(), quiet = FALSE,
error_on = c("never", "error", "warning", "note")) {

if (missing(error_on) && !interactive()) {
error_on <- "warning"
}
Expand Down
1 change: 0 additions & 1 deletion R/cran.r
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package_url <- function(package, repos,
# @param package The name of the package.
# @param available A matrix of information about packages.
cran_pkg_version <- function(package, available = available.packages()) {

idx <- available[, "Package"] == package
if (any(idx)) {
as.package_version(available[package, "Version"])
Expand Down
20 changes: 12 additions & 8 deletions R/create.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ create <- function(path, description = getOption("devtools.desc"),
if (!file.exists(path)) {
if (!dir.create(path)) {
stop("Failed to create package directory '", basename(path), "'",
call. = FALSE)
call. = FALSE
)
}
}

# if the directory exists but is not empty, bail
files <- list.files(path)
if (length(files)) {

valid <- length(files) == 1 && tools::file_ext(files) == "Rproj"
if (!valid)
if (!valid) {
stop("Directory exists and is not empty", call. = FALSE)
}
}

path <- normalizePath(path, winslash = "/", mustWork = TRUE)
setup(path = path, description = description, rstudio = rstudio,
check = check, quiet = quiet)
setup(
path = path, description = description, rstudio = rstudio,
check = check, quiet = quiet
)

invisible(TRUE)
}
Expand Down Expand Up @@ -71,7 +74,8 @@ create_description <- function(path = ".", extra = getOption("devtools.desc"),
subdir <- file.path(path, c("R", "src", "data"))
if (!any(file.exists(subdir))) {
stop("'", path, "' does not look like a package: no R/, src/ or data directories",
call. = FALSE)
call. = FALSE
)
}

desc <- build_description(extract_package_name(path), extra)
Expand All @@ -95,7 +99,7 @@ build_description <- function(name, extra = list()) {
Version = "0.0.0.9000",
"Authors@R" = getOption("devtools.desc.author"),
Description = "What the package does (one paragraph).",
Depends = paste0("R (>= ", as.character(getRversion()) ,")"),
Depends = paste0("R (>= ", as.character(getRversion()), ")"),
License = getOption("devtools.desc.license"),
Suggests = getOption("devtools.desc.suggests"),
Encoding = "UTF-8",
Expand Down Expand Up @@ -137,7 +141,7 @@ create_namespace <- function(path) {
if (file.exists(ns_path)) return()

cat(
'# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n',
"# Generated by roxygen2: fake comment so roxygen2 overwrites silently.\n",
'exportPattern("^[^\\\\.]")\n',
sep = "",
file = ns_path
Expand Down
12 changes: 5 additions & 7 deletions R/decompress.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ source_pkg <- function(path, subdir = NULL, before_install = NULL) {
}

# Call before_install for bundles (if provided)
if (!is.null(info$bundle) && !is.null(before_install))
if (!is.null(info$bundle) && !is.null(before_install)) {
before_install(info$bundle, info$pkg_path)
}

info$pkg_path
}
Expand All @@ -50,23 +51,20 @@ decompress <- function(src, target) {
if (grepl("\\.zip$", src)) {
my_unzip(src, target)
outdir <- getrootdir(as.vector(utils::unzip(src, list = TRUE)$Name))

} else if (grepl("\\.tar$", src)) {
utils::untar(src, exdir = target)
outdir <- getrootdir(utils::untar(src, list = TRUE))

} else if (grepl("\\.(tar\\.gz|tgz)$", src)) {
utils::untar(src, exdir = target, compressed = "gzip")
outdir <- getrootdir(utils::untar(src, compressed = "gzip", list = TRUE))

} else if (grepl("\\.(tar\\.bz2|tbz)$", src)) {
utils::untar(src, exdir = target, compressed = "bzip2")
outdir <- getrootdir(utils::untar(src, compressed = "bzip2", list = TRUE))

} else {
ext <- gsub("^[^.]*\\.", "", src)
stop("Don't know how to decompress files with extension ", ext,
call. = FALSE)
call. = FALSE
)
}

file.path(target, outdir)
Expand All @@ -76,7 +74,7 @@ decompress <- function(src, target) {
# Returns everything before the last slash in a filename
# getdir("path/to/file") returns "path/to"
# getdir("path/to/dir/") returns "path/to/dir"
getdir <- function(path) sub("/[^/]*$", "", path)
getdir <- function(path) sub("/[^/]*$", "", path)

# Given a list of files, returns the root (the topmost folder)
# getrootdir(c("path/to/file", "path/to/other/thing")) returns "path/to"
Expand Down
7 changes: 4 additions & 3 deletions R/dev-mode.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ dev_mode <- local({

if (!is_library(path)) {
warning(path, " does not appear to be a library. ",
"Are sure you specified the correct directory?", call. = FALSE)
"Are sure you specified the correct directory?",
call. = FALSE
)
}

message("Dev mode: ON")
Expand All @@ -48,7 +50,6 @@ dev_mode <- local({

.libPaths(c(path, lib_paths))
} else {

message("Dev mode: OFF")
options(dev_path = NULL)

Expand All @@ -62,7 +63,7 @@ dev_mode <- local({

is_library <- function(path) {
# empty directories can be libraries
if (length(dir(path)) == 0) return (TRUE)
if (length(dir(path)) == 0) return(TRUE)

# otherwise check that the directories are compiled R directories -
# i.e. that they contain a Meta directory
Expand Down
29 changes: 18 additions & 11 deletions R/doctor.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,27 @@ dr_github <- function(path = ".") {
config <- git2r::config(r)
config_names <- names(modifyList(config$global, config$local))

if (!uses_github(path))
if (!uses_github(path)) {
msg[["github"]] <- " * cannot detect that this repo is connected to GitHub"
if (!("user.name" %in% config_names))
}
if (!("user.name" %in% config_names)) {
msg[["name"]] <- "* user.name config option not set"
if (!("user.email" %in% config_names))
}
if (!("user.email" %in% config_names)) {
msg[["user"]] <- "* user.email config option not set"
}

if (!file.exists("~/.ssh/id_rsa"))
if (!file.exists("~/.ssh/id_rsa")) {
msg[["ssh"]] <- "* SSH private key not found"
}

if (identical(Sys.getenv("GITHUB_PAT"), ""))
msg[["PAT"]] <- paste("* GITHUB_PAT environment variable not set",
if (identical(Sys.getenv("GITHUB_PAT"), "")) {
msg[["PAT"]] <- paste(
"* GITHUB_PAT environment variable not set",
"(this is not necessary unless you want to install private repos",
"or connect local repos to GitHub)")
"or connect local repos to GitHub)"
)
}

desc_path <- file.path(path, "DESCRIPTION")
desc <- read_dcf(desc_path)
Expand All @@ -111,16 +118,16 @@ dr_github <- function(path = ".") {

re <- "https://github.com/(.*?)/(.*)"
if (field_empty(desc, "URL")) {
msg[["URL_empty"]] <-"* empty URL field in DESCRIPTION"
msg[["URL_empty"]] <- "* empty URL field in DESCRIPTION"
} else if (field_no_re(desc, "URL", re)) {
msg[["URL"]] <-"* no GitHub repo link in URL field in DESCRIPTION"
msg[["URL"]] <- "* no GitHub repo link in URL field in DESCRIPTION"
}

re <- paste0(re, "/issues")
if (field_empty(desc, "BugReports")) {
msg[["BugReports_empty"]] <-"* empty BugReports field in DESCRIPTION"
msg[["BugReports_empty"]] <- "* empty BugReports field in DESCRIPTION"
} else if (field_no_re(desc, "BugReports", re)) {
msg[["BugReports"]] <-"* no GitHub Issues link in URL field in DESCRIPTION"
msg[["BugReports"]] <- "* no GitHub Issues link in URL field in DESCRIPTION"
}

doctor("github", msg)
Expand Down
Loading