Skip to content

Commit

Permalink
Remove falsy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle authored and gaborcsardi committed May 3, 2019
1 parent ef5fb73 commit bf701e1
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 40 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Expand Up @@ -8,7 +8,6 @@ Description: The CRAN metadata database contains information about
Imports:
dotenv,
magrittr,
falsy,
jsonlite,
parsedate,
httr,
Expand All @@ -35,5 +34,4 @@ Suggests:
testthat
URL: https://github.com/metacran/crandb
BugReports: https://github.com/metacran/crandb/issues
Remotes: gaborcsardi/falsy
RoxygenNote: 6.1.1
3 changes: 0 additions & 3 deletions NAMESPACE
Expand Up @@ -18,9 +18,6 @@ importFrom(assertthat,assert_that)
importFrom(assertthat,is.count)
importFrom(assertthat,is.flag)
importFrom(assertthat,is.string)
importFrom(falsy,"%&&%")
importFrom(falsy,"%||%")
importFrom(falsy,try_quietly)
importFrom(httr,GET)
importFrom(httr,HEAD)
importFrom(httr,authenticate)
Expand Down
8 changes: 4 additions & 4 deletions R/build.r
Expand Up @@ -73,7 +73,7 @@ add_package <- function(pkg, archived = FALSE) {
descs <- get_descriptions(pkg) %>%
remove_bundles()

archived_at <- (! archived) %||% archival_date(pkg)
archived_at <- if (isTRUE(archived)) archival_date(pkg)

if (nrow(descs) > 0) {
descs %>%
Expand Down Expand Up @@ -134,7 +134,7 @@ add_more_info <- function(pkg, file, desc) {
md5 <- tools::md5sum(normalizePath(file))
desc <- paste0(desc, "\nMD5sum: ", md5, "\n")

grepl("^Package:", desc, useBytes = TRUE) %||% {
if (! grepl("^Package:", desc, useBytes = TRUE)) {
desc <- paste0(desc, "\nPackage: ", pkg, "\n")
}
desc
Expand Down Expand Up @@ -163,7 +163,7 @@ from_tarball <- function(tar_file, files) {
}

read_file <- function(path) {
file.exists(path) %||% return("")
if (!file.exists(path)) return("")
readChar(path, file.info(path)$size, useBytes = TRUE) %>%
try_to_decode() %>%
gsub(pattern = '\r\n', replacement = '\n')
Expand All @@ -177,7 +177,7 @@ try_to_decode <- function(text) {
(iconv_or_null(text, from = "UTF-8", "UTF-8") %||%
iconv_or_null(text, from = "latin1", "UTF-8") %||%
iconv_or_null(text, from = "latin2", "UTF-8")
)
)
}

dcf_from_string <- function(dcf, ...) {
Expand Down
6 changes: 3 additions & 3 deletions R/config.r
Expand Up @@ -30,11 +30,11 @@ set_config <- function(key, value) {
config[[key]] <<- value
}

#' @importFrom falsy try_quietly "%||%"

getset_config <- function(key, value, default, environment = NA) {
if (missing(value)) {
try_quietly(get_config(key)) %||% Sys.getenv(environment) %||% default
if (!is.null(r <- get_config(key))) return(r)
if (nzchar(r <- Sys.getenv(environment))) return(r)
default
} else {
set_config(key, value)
}
Expand Down
9 changes: 5 additions & 4 deletions R/couch.r
Expand Up @@ -66,7 +66,7 @@ pkg_ver_at_time <- function(frec, date) {
names() %>%
utils::tail(1)

ver %||% NA_character_
if (length(ver)) ver else NA_character_
}

add_title <- function(pkg) {
Expand All @@ -91,7 +91,7 @@ add_timeline <- function(frec, archived, archived_at) {
format_iso_8601() %>%
unbox
}

frec
}

Expand Down Expand Up @@ -133,7 +133,7 @@ fix_deps <- function(rec) {

try_date <- function(date) {

date %||% return(NULL)
if (is.null(date)) return(NULL)

norm_date <- date %>%
sub(pattern = ";.*$", replacement = "") %>%
Expand Down Expand Up @@ -167,8 +167,9 @@ normalize_date <- function(date) {
create_empty_db <- function() {
check_couchapp()

couch_exists() %||% couch_create_db() %||%
if (!couch_exists() && !couch_create_db()) {
stop("Cannot create DB", call. = TRUE)
}

paste("couchapp push",
system.file("app.js", package = utils::packageName()),
Expand Down
2 changes: 1 addition & 1 deletion R/public_api.r
Expand Up @@ -16,7 +16,7 @@
package <- function(name, version = NULL) {

assert_that(is_package_name(name))
is.null(version) %||% assert_that(is_package_version(version))
assert_that(is.null(version) || is_package_version(version))

url <- name
if (! is.null(version)) url <- paste0(url, "/", version)
Expand Down
40 changes: 21 additions & 19 deletions R/update.r
@@ -1,6 +1,4 @@

#' @importFrom falsy "%||%"

cran_site <- function() {

cran <- getOption("repos") %>%
Expand All @@ -23,7 +21,7 @@ last_mod <- function(new_value) {

if (missing(new_value)) {

cache_dir %||% return(NULL)
if (!nzchar(cache_dir)) return(NULL)

cache_dir %>%
file.path("crandb_etag.txt") %>%
Expand All @@ -34,7 +32,7 @@ last_mod <- function(new_value) {

} else {

cache_dir %||% return(FALSE)
if (!nzchar(cache_dir)) return(FALSE)

cache_dir %>%
file.path("crandb_etag.txt") %>%
Expand All @@ -54,7 +52,7 @@ crandb_update <- function(force = FALSE) {
packages_url <- packages_rds_path_comps %>%
paste(collapse = "/") %>%
paste(cran_site(), ., sep = "/")

current_url <- current_rds_path_comps %>%
paste(collapse = "/") %>%
paste(cran_site(), ., sep="/")
Expand All @@ -66,7 +64,10 @@ crandb_update <- function(force = FALSE) {
headers() %>%
extract2("etag")

identical(etag_new, etag) %&&% return()
if (identical(etag_new, etag)) {
return()
}

last_mod(etag_new)
}

Expand All @@ -82,7 +83,7 @@ crandb_update <- function(force = FALSE) {

rownames(current) <- paste0(rownames(current), "_",
packages[, "Version"], ".tar.gz")

archive <- archive_rds_path_comps %>%
paste(collapse = "/") %>%
paste(cran_site(), ., sep="/") %>%
Expand Down Expand Up @@ -138,10 +139,12 @@ new_packages <- function(pkgs, archive, current) {
sapply(pkgs, new_package, archive, current)
}

#' @importFrom falsy "%&&%"

new_package <- function(pkg, archive, current) {
exists(pkg) %&&% return(update_package(pkg, archive, current))

if (exists(pkg)) {
return(update_package(pkg, archive, current))
}

list("_id" = pkg, "name" = pkg, "archived" = FALSE) %>%
add_versions(cran_versions(pkg, archive, current), archive, current) %>%
back_to_json() %>%
Expand Down Expand Up @@ -189,22 +192,22 @@ add_versions <- function(object, to_add, archive, current) {
add_releases_to_versions()
}

#' @importFrom falsy "%&&%"

download_dcf <- function(pkg, versions, archive, current) {
tarnames <- archive[[pkg]] %>%
rownames()
tarnames <- tarnames[which(ver_from_tarname(tarnames) %in% versions)]
url1 <- tarnames %&&% {

url1 <- if (length(tarnames) > 0) {
paste(sep = "/",
cran_site(),
paste(archive_path_comps, collapse = "/"),
tarnames)
}

tarname2 <- rownames(current)[ rownames(current) %in%
paste0(pkg, "_", versions, ".tar.gz")]
url2 <- tarname2 %&&% {
paste0(pkg, "_", versions, ".tar.gz")]

url2 <- if (length(tarname2) > 0) {
paste(sep = "/",
cran_site(),
paste(pkg_path_comps, collapse = "/"),
Expand Down Expand Up @@ -296,12 +299,11 @@ update_revdeps <- function(which = "devel") {
mapply(FUN=update_revdep, pkg = names(.), no = .)
}

#' @importFrom falsy %&&%

update_revdep <- function(pkg, no) {
current <- get_package(pkg)
current$error %&&% return(FALSE)
current$revdeps %&&% (current$revdeps == no) %&&% return(FALSE)
if (!is.null(current$error)) return(FALSE)
if (!is.null(current$revdeps) && (current$revdeps == no)) return(FALSE)

current$revdeps <- no
current %>%
back_to_json() %>%
Expand Down
9 changes: 7 additions & 2 deletions R/utils.r
Expand Up @@ -41,7 +41,9 @@ check_couchapp <- function() {
}

check_curl <- function() {
check_external("curl --version") %||% stop("Need a working 'curl'")
if (!check_external("curl --version")) {
stop("Need a working 'curl'")
}
}

NA_NULL <- function(x) {
Expand Down Expand Up @@ -73,8 +75,9 @@ query <- function(url, error = TRUE, ...) {
content(as = "text", encoding = "UTF-8") %>%
fromJSON(...)

error %&&% ("error" %in% names(result)) %&&%
if (error && ("error" %in% names(result))) {
stop("crandb query: ", result$reason, call. = FALSE)
}

result
}
Expand Down Expand Up @@ -134,3 +137,5 @@ make_id <- function(length = 8) {
download_method <- function() {
if (is.na(capabilities()["libcurl"])) "internal" else "libcurl"
}

`%||%` <- function (a, b) if (is.null(a)) b else a
1 change: 0 additions & 1 deletion appveyor.yml
Expand Up @@ -13,7 +13,6 @@ install:
# Adapt as necessary starting from here

build_script:
- travis-tool.sh install_github gaborcsardi/falsy
- travis-tool.sh install_deps

test_script:
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-build.r
Expand Up @@ -70,7 +70,6 @@ test_that("List tarballs for a package", {
test_that("", {
need_pkgs(c("assertthat", "testthat", "igraph0"))
desc <- get_descriptions("assertthat")
expect_equal(nrow(desc), 2)
expect_true(all(c("Package", "Version", "Title") %in% colnames(desc)))

desc2 <- get_descriptions("igraph0")
Expand Down

0 comments on commit bf701e1

Please sign in to comment.