Skip to content

Commit

Permalink
import fs and start switching
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmbarrett authored and jimhester committed Mar 26, 2021
1 parent 545131c commit adbe838
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Authors@R:
comment = "Some namespace and vignette code extracted from base R"))
Description: Collection of package development tools.
License: GPL (>= 2)
URL: https://devtools.r-lib.org/,
https://github.com/r-lib/devtools
URL: https://devtools.r-lib.org/, https://github.com/r-lib/devtools
BugReports: https://github.com/r-lib/devtools/issues
Depends:
R (>= 3.0.2),
Expand All @@ -31,6 +30,7 @@ Imports:
covr (>= 3.5.1),
desc (>= 1.2.0),
ellipsis (>= 0.3.1),
fs,
httr (>= 1.4.2),
jsonlite (>= 1.7.2),
memoise (>= 2.0.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export(update_packages)
export(uses_testthat)
export(wd)
export(with_debug)
import(fs)
importFrom(cli,cat_bullet)
importFrom(cli,cat_rule)
importFrom(ellipsis,check_dots_used)
Expand Down
10 changes: 5 additions & 5 deletions R/active.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ find_test_file <- function(path) {

is_test <- type == "test"
path[!is_test] <- paste0("tests/testthat/test-", name_source(path[!is_test]), ".R")
path <- unique(path[file.exists(path)])
path <- unique(path[file_exists(path)])

if (length(path) == 0) {
rlang::abort("No test files found")
Expand All @@ -22,9 +22,9 @@ find_test_file <- function(path) {
}

test_file_type <- function(path) {
dir <- basename(dirname(path))
name <- basename(path)
ext <- tolower(tools::file_ext(path))
dir <- path_file(path_dir(path))
name <- path_file(path)
ext <- tolower(path_ext(path))

src_ext <- c("c", "cc", "cpp", "cxx", "h", "hpp", "hxx")

Expand All @@ -40,5 +40,5 @@ name_test <- function(path) {
gsub("^test[-_]", "", name_source(path))
}
name_source <- function(path) {
tools::file_path_sans_ext(basename(path))
path_ext_remove(path_file(path))
}
2 changes: 1 addition & 1 deletion R/build-manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @export
build_manual <- function(pkg = ".", path = NULL) {
pkg <- as.package(pkg)
path <- path %||% dirname(pkg$path)
path <- path %||% path_dir(pkg$path)
name <- paste0(pkg$package, "_", pkg$version, ".pdf", collapse = " ")
tryCatch(msg <- callr::rcmd("Rd2pdf", cmdargs = c(
"--force",
Expand Down
8 changes: 4 additions & 4 deletions R/build-readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = T
# Ensure rendering github_document() doesn't generate HTML file
output_options$html_preview <- FALSE

paths <- file.path(pkg$path, files)
paths <- path(pkg$path, files)
for (path in paths) {
cli::cli_alert_info("Building {.path {path}}")
callr::r_safe(
Expand All @@ -45,13 +45,13 @@ build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = T
#' @export
build_readme <- function(path = ".", quiet = TRUE, ...) {
pkg <- as.package(path)
inst <- path(pkg$path, "inst")
dirs <- c(pkg$path, if (dir_exists(inst)) inst)

readme_path <- grep(
ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE
))
path_file(dir_ls(dirs))
)
if (length(readme_path) == 0) {
return(invisible())
Expand Down
2 changes: 1 addition & 1 deletion R/build-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build_site <- function(path = ".", quiet = TRUE, ...) {
install(pkg = pkg$path, upgrade = "never", reload = FALSE, quiet = quiet)
if (isTRUE(quiet)) {
withr::with_output_sink(
tempfile(),
file_temp(),
pkgdown::build_site(pkg = pkg$path, ...)
)
} else {
Expand Down
14 changes: 7 additions & 7 deletions R/check-devtools.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ check_vignette_titles <- function(pkg = ".") {
h <- readLines(v, n = n)
any(grepl("Vignette Title", h))
}
v <- stats::setNames(vigns$docs, basename(vigns$docs))
v <- stats::setNames(vigns$docs, path_file(vigns$docs))
has_vt <- vapply(v, has_vignette_title, logical(1), n = 30)

check_status(
Expand All @@ -82,13 +82,13 @@ check_vignette_titles <- function(pkg = ".") {
check_news_md <- function(pkg) {
pkg <- as.package(pkg)

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

ignore_path <- file.path(pkg$path, ".Rbuildignore")
if (!file.exists(ignore_path)) {
ignore_path <- path(pkg$path, ".Rbuildignore")
if (!file_exists(ignore_path)) {
ignore_lines <- character()
} else {
ignore_lines <- readLines(ignore_path)
Expand All @@ -103,9 +103,9 @@ check_news_md <- function(pkg) {
"NEWS.md now supported by CRAN and doesn't need to be ignored."
)

news_rd_path <- file.path(pkg$path, "inst/NEWS.Rd")
news_rd_path <- path(pkg$path, "inst/NEWS.Rd")
check_status(
!file.exists(news_rd_path),
!file_exists(news_rd_path),
"NEWS.Rd does not exist",
"NEWS.md now supported by CRAN, NEWS.Rd can be removed."
)
Expand Down
14 changes: 7 additions & 7 deletions R/check-win.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
pkg <- as.package(pkg)

if (!is.null(email)) {
desc_file <- file.path(pkg$path, "DESCRIPTION")
backup <- tempfile()
file.copy(desc_file, backup)
on.exit(file.rename(backup, desc_file), add = TRUE)
desc_file <- path(pkg$path, "DESCRIPTION")
backup <- file_temp()
file_copy(desc_file, backup)
on.exit(file_move(backup, desc_file), add = TRUE)

change_maintainer_email(desc_file, email)

Expand All @@ -83,11 +83,11 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
args = args,
manual = manual, quiet = quiet, ...
)
on.exit(unlink(built_path), add = TRUE)
on.exit(dir_delete(built_path), add = TRUE)

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

Expand Down Expand Up @@ -128,7 +128,7 @@ change_maintainer_email <- function(desc, email) {
upload_ftp <- function(file, url, verbose = FALSE) {
rlang::check_installed("curl")

stopifnot(file.exists(file))
stopifnot(file_exists(file))
stopifnot(is.character(url))
con <- file(file, open = "rb")
on.exit(close(con), add = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ check <- function(pkg = ".",
vignettes = vignettes,
...
)
on.exit(unlink(built_path), add = TRUE)
on.exit(dir_delete(built_path), add = TRUE)
})

check_built(
Expand Down Expand Up @@ -187,7 +187,7 @@ check_built <- function(path = NULL, cran = TRUE,
}
error_on <- match.arg(error_on)

pkgname <- gsub("_.*?$", "", basename(path))
pkgname <- gsub("_.*?$", "", path_file(path))

if (cran) {
args <- c("--as-cran", args)
Expand Down
13 changes: 6 additions & 7 deletions R/dev-mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ dev_mode <- local({
function(on = NULL, path = getOption("devtools.path")) {
lib_paths <- .libPaths()

path <- normalizePath(path, winslash = "/", mustWork = FALSE)
path <- path_real(path)
if (is.null(on)) {
on <- !(path %in% lib_paths)
}

if (on) {
if (!file.exists(path)) {
dir.create(path, recursive = TRUE, showWarnings = FALSE)
if (!file_exists(path)) {
dir_create(path)
}
if (!file.exists(path)) {
if (!file_exists(path)) {
stop("Failed to create ", path, call. = FALSE)
}

Expand Down Expand Up @@ -63,12 +63,11 @@ dev_mode <- local({

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

# otherwise check that the directories are compiled R directories -
# i.e. that they contain a Meta directory
dirs <- dir(path, full.names = TRUE)
dirs <- dirs[utils::file_test("-d", dirs)]
dirs <- dir_ls(path, type = "folder")

has_pkg_dir <- function(path) length(dir(path, pattern = "Meta")) > 0
help_dirs <- vapply(dirs, has_pkg_dir, logical(1))
Expand Down
4 changes: 2 additions & 2 deletions R/document.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ document <- function(pkg = ".", roclets = NULL, quiet = FALSE) {
}

if (quiet) {
output <- tempfile()
on.exit(unlink(output))
output <- file_temp()
on.exit(file_delete(output))
withr::local_output_sink(output)
}
withr::local_envvar(r_env_vars())
Expand Down
2 changes: 1 addition & 1 deletion R/git.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
uses_git <- function(path = ".") {
dir.exists(file.path(path, ".git"))
dir_exists(path(path, ".git"))
}

git_branch <- function(path = ".") {
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' installed.packages modifyList packageDescription
#' packageVersion remove.packages
#' @importFrom cli cat_rule cat_bullet
#' @import fs
NULL

#' Package development tools for R.
Expand Down

0 comments on commit adbe838

Please sign in to comment.