Skip to content

Commit 1787e06

Browse files
committed
Lighten dependencies
To get under the 20 hard dependency limit and avoid a CRAN NOTE
1 parent f0fe379 commit 1787e06

14 files changed

Lines changed: 57 additions & 319 deletions

DESCRIPTION

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
Package: devtools
22
Title: Tools to Make Developing R Packages Easier
33
Version: 2.3.0.9000
4-
Authors@R: c(
5-
person("Hadley", "Wickham", role = "aut"),
6-
person("Jim", "Hester", , "jim.hester@rstudio.com", role = c("aut", "cre")),
7-
person("Winston", "Chang", role = "aut"),
8-
person("RStudio", role = "cph"),
9-
person("R Core team", role = "ctb",
10-
comment = "Some namespace and vignette code extracted from base R")
11-
)
4+
Authors@R:
5+
c(person(given = "Hadley",
6+
family = "Wickham",
7+
role = "aut"),
8+
person(given = "Jim",
9+
family = "Hester",
10+
role = c("aut", "cre"),
11+
email = "jim.hester@rstudio.com"),
12+
person(given = "Winston",
13+
family = "Chang",
14+
role = "aut"),
15+
person(given = "RStudio",
16+
role = "cph"),
17+
person(given = "R Core team",
18+
role = "ctb",
19+
comment = "Some namespace and vignette code extracted from base R"))
1220
Description: Collection of package development tools.
1321
License: GPL (>= 2)
14-
URL: https://devtools.r-lib.org/, https://github.com/r-lib/devtools
22+
URL: https://devtools.r-lib.org/,
23+
https://github.com/r-lib/devtools
1524
BugReports: https://github.com/r-lib/devtools/issues
1625
Depends:
1726
R (>= 3.0.2),
@@ -20,13 +29,9 @@ Imports:
2029
callr (>= 3.4.3),
2130
cli (>= 2.0.2),
2231
covr (>= 3.5.0),
23-
crayon (>= 1.3.4),
2432
desc (>= 1.2.0),
25-
digest (>= 0.6.25),
2633
DT (>= 0.13),
2734
ellipsis (>= 0.3.0),
28-
glue (>= 1.4.0),
29-
git2r (>= 0.26.1),
3035
httr (>= 1.4.1),
3136
jsonlite (>= 1.6.1),
3237
memoise (>= 1.1.0),
@@ -47,19 +52,21 @@ Imports:
4752
Suggests:
4853
BiocManager (>= 1.30.10),
4954
curl (>= 4.3),
55+
digest (>= 0.6.25),
5056
foghorn (>= 1.2.1),
5157
gmailr (>= 1.0.0),
5258
knitr (>= 1.28),
5359
lintr (>= 2.0.1),
60+
MASS,
5461
mockery (>= 0.4.2),
5562
pingr (>= 2.0.0),
56-
MASS,
5763
pkgdown (>= 1.5.1),
5864
rhub (>= 1.1.1),
5965
rmarkdown (>= 2.1),
6066
spelling (>= 2.1)
61-
VignetteBuilder: knitr
67+
VignetteBuilder:
68+
knitr
6269
Encoding: UTF-8
63-
RoxygenNote: 7.1.1
64-
Roxygen: list(markdown = TRUE)
6570
Language: en-US
71+
Roxygen: list(markdown = TRUE)
72+
RoxygenNote: 7.1.1

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
S3method(format,check_results)
44
S3method(print,check_results)
55
S3method(print,dev_sitrep)
6-
S3method(print,doctor)
76
S3method(print,maintainers)
87
export(as.package)
98
export(bash)
@@ -31,8 +30,6 @@ export(dev_packages)
3130
export(dev_sitrep)
3231
export(devtest)
3332
export(document)
34-
export(dr_devtools)
35-
export(dr_github)
3633
export(find_rtools)
3734
export(github_pat)
3835
export(github_pull)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* `run_examples()` arguments `run` and `test` are deprecated in favor of the (hopefully) more clear `run_dontrun` and `run_donttest` (pkgload/#107).
44

5+
* Previously deprecated functions `dr_devtools()` and `dr_github()` have been removed.
6+
57
# devtools 2.3.0
68

79
* `build()` now errors with a more informative error message when passed an

R/check-git.R

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ git_checks <- function(pkg = ".") {
1111

1212
git_report_branch(pkg)
1313
git_check_uncommitted(pkg)
14-
git_check_sync_status(pkg)
1514
cat_rule()
1615
}
1716

@@ -21,16 +20,8 @@ git_report_branch <- function(pkg) {
2120

2221
git_check_uncommitted <- function(pkg) {
2322
check_status(
24-
!git_uncommitted(pkg$path),
23+
!asNamespace("usethis")$git_uncommitted(pkg$path),
2524
"uncommitted files",
2625
"All files should be tracked and committed before release. Please add and commit."
2726
)
2827
}
29-
30-
git_check_sync_status <- function(pkg) {
31-
check_status(
32-
!git_sync_status(pkg$path, check_ahead = FALSE),
33-
"synchronisation with remote branch",
34-
"Local branch should contain all commits of remote branch before release. Please pull."
35-
)
36-
}

R/check-results.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ summarise_check_results <- function(x, colour = FALSE) {
6262

6363
show_count <- function(n, singular, plural, is_error = FALSE) {
6464
out <- paste0(n, " ", ngettext(n, singular, plural))
65-
if (is_error && requireNamespace("crayon", quietly = TRUE)) {
66-
out <- crayon::red(out)
65+
if (is_error && requireNamespace("cli", quietly = TRUE)) {
66+
out <- cli::col_red(out)
6767
}
6868
out
6969
}

R/git.R

Lines changed: 7 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,16 @@
11
uses_git <- function(path = ".") {
2-
!is.null(git2r::discover_repository(path, ceiling = 0))
3-
}
4-
5-
# sha of most recent commit
6-
git_repo_sha1 <- function(r) {
7-
rev <- git2r::repository_head(r)
8-
if (is.null(rev)) {
9-
return(NULL)
10-
}
11-
12-
if (git2r::is_commit(rev)) {
13-
rev$sha
14-
} else {
15-
git2r::branch_target(rev)
16-
}
17-
}
18-
19-
git_sha1 <- function(n = 10, path = ".") {
20-
r <- git2r::repository(path, discover = TRUE)
21-
sha <- git_repo_sha1(r)
22-
substr(sha, 1, n)
23-
}
24-
25-
git_uncommitted <- function(path = ".") {
26-
r <- git2r::repository(path, discover = TRUE)
27-
st <- vapply(git2r::status(r), length, integer(1))
28-
any(st != 0)
29-
}
30-
31-
git_sync_status <- function(path = ".", check_ahead = TRUE, check_behind = TRUE) {
32-
r <- git2r::repository(path, discover = TRUE)
33-
34-
r_head <- git2r::repository_head(r)
35-
if (!inherits(r_head, "git_branch")) {
36-
stop("HEAD is not a branch", call. = FALSE)
37-
}
38-
39-
upstream <- git2r::branch_get_upstream(r_head)
40-
if (is.null(upstream)) {
41-
stop("No upstream branch", call. = FALSE)
42-
}
43-
44-
git2r::fetch(r, git2r::branch_remote_name(upstream))
45-
46-
c1 <- git2r::lookup(r, git2r::branch_target(r_head))
47-
c2 <- git2r::lookup(r, git2r::branch_target(upstream))
48-
ab <- git2r::ahead_behind(c1, c2)
49-
50-
# if (ab[1] > 0)
51-
# message(ab[1], " ahead of remote")
52-
# if (ab[2] > 0)
53-
# message(ab[2], " behind remote")
54-
55-
is_ahead <- ab[[1]] != 0
56-
is_behind <- ab[[2]] != 0
57-
check <- (check_ahead && is_ahead) || (check_behind && is_behind)
58-
check
59-
}
60-
61-
# Retrieve the current running path of the git binary.
62-
# @param git_binary_name The name of the binary depending on the OS.
63-
git_path <- function(git_binary_name = NULL) {
64-
# Use user supplied path
65-
if (!is.null(git_binary_name)) {
66-
if (!file.exists(git_binary_name)) {
67-
stop("Path ", git_binary_name, " does not exist", .call = FALSE)
68-
}
69-
return(git_binary_name)
70-
}
71-
72-
# Look on path
73-
git_path <- Sys.which("git")[[1]]
74-
if (git_path != "") return(git_path)
75-
76-
# On Windows, look in common locations
77-
if (.Platform$OS.type == "windows") {
78-
look_in <- c(
79-
"C:/Program Files/Git/bin/git.exe",
80-
"C:/Program Files (x86)/Git/bin/git.exe"
81-
)
82-
found <- file.exists(look_in)
83-
if (any(found)) return(look_in[found][1])
84-
}
85-
86-
stop("Git does not seem to be installed on your system.", call. = FALSE)
2+
dir.exists(file.path(path, ".git"))
873
}
884

895
git_branch <- function(path = ".") {
90-
r <- git2r::repository(path, discover = TRUE)
91-
92-
if (git2r::is_detached(r)) {
93-
return(NULL)
94-
}
6+
withr::local_dir(path)
957

96-
git2r::repository_head(r)$name
8+
system2("git", c("rev-parse", "--abbrev-ref", "HEAD"), stdout = TRUE)
979
}
9810

99-
# GitHub ------------------------------------------------------------------
100-
101-
uses_github <- function(path = ".") {
102-
if (!uses_git(path)) {
103-
return(FALSE)
104-
}
105-
106-
r <- git2r::repository(path, discover = TRUE)
107-
r_remote_urls <- git2r::remote_url(r)
108-
109-
any(grepl("github", r_remote_urls))
110-
}
111-
112-
github_info <- function(path = ".", remote_name = NULL) {
113-
if (!uses_github(path)) {
114-
return(github_dummy)
115-
}
116-
117-
r <- git2r::repository(path, discover = TRUE)
118-
r_remote_urls <- grep("github", remote_urls(r), value = TRUE)
119-
120-
if (!is.null(remote_name) && !remote_name %in% names(r_remote_urls)) {
121-
stop("no github-related remote named ", remote_name, " found")
122-
}
123-
124-
remote_name <- c(remote_name, "origin", names(r_remote_urls))
125-
x <- r_remote_urls[remote_name]
126-
x <- x[!is.na(x)][1]
127-
128-
github_remote_parse(x)
129-
}
130-
131-
github_dummy <- list(username = "<USERNAME>", repo = "<REPO>", fullname = "<USERNAME>/<REPO>")
132-
133-
remote_urls <- function(r) {
134-
remotes <- git2r::remotes(r)
135-
stats::setNames(git2r::remote_url(r, remotes), remotes)
136-
}
137-
138-
github_remote_parse <- function(x) {
139-
if (length(x) == 0) return(github_dummy)
140-
if (!grepl("github", x)) return(github_dummy)
141-
142-
if (grepl("^(https|git)", x)) {
143-
# https://github.com/r-lib/devtools.git
144-
# https://github.com/r-lib/devtools
145-
# git@github.com:r-lib/devtools.git
146-
re <- "github[^/:]*[/:]([^/]+)/(.*?)(?:\\.git)?$"
147-
} else {
148-
stop("Unknown GitHub repo format", call. = FALSE)
149-
}
150-
151-
m <- regexec(re, x)
152-
match <- regmatches(x, m)[[1]]
153-
list(
154-
username = match[2],
155-
repo = match[3],
156-
fullname = paste0(match[2], "/", match[3])
157-
)
158-
}
159-
160-
# Extract the commit hash from a git archive. Git archives include the SHA1
161-
# hash as the comment field of the zip central directory record
162-
# (see https://www.kernel.org/pub/software/scm/git/docs/git-archive.html)
163-
# Since we know it's 40 characters long we seek that many bytes minus 2
164-
# (to confirm the comment is exactly 40 bytes long)
165-
git_extract_sha1 <- function(bundle) {
166-
167-
# open the bundle for reading
168-
conn <- file(bundle, open = "rb", raw = TRUE)
169-
on.exit(close(conn))
170-
171-
# seek to where the comment length field should be recorded
172-
seek(conn, where = -0x2a, origin = "end")
11+
git_uncommited <- function(path = ".") {
12+
withr::local_dir(path)
17313

174-
# verify the comment is length 0x28
175-
len <- readBin(conn, "raw", n = 2)
176-
if (len[1] == 0x28 && len[2] == 0x00) {
177-
# read and return the SHA1
178-
rawToChar(readBin(conn, "raw", n = 0x28))
179-
} else {
180-
NULL
181-
}
14+
out <- system2("git", c("status", "--porcelain=v1"), stdout = TRUE)
15+
length(out) > 0
18216
}

R/release.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' of additional questions to ask.
1717
#'
1818
#' You also need to read the CRAN repository policy at
19-
#' <https://cran.r-project.org/web/packages/policies.html> and make
19+
#' 'https://cran.r-project.org/web/packages/policies.html' and make
2020
#' sure you're in line with the policies. `release` tries to automate as
2121
#' many of polices as possible, but it's impossible to be completely
2222
#' comprehensive, and they do change in between releases of devtools.
@@ -368,8 +368,9 @@ flag_release <- function(pkg = ".") {
368368
message("Don't forget to tag this release once accepted by CRAN")
369369

370370
date <- Sys.Date()
371-
commit <- git2r::commits(git2r::init(pkg$path), n = 1)[[1]]
372-
sha <- substr(as.data.frame(commit)$sha, 1, 10)
371+
withr::with_dir(pkg$path, {
372+
sha <- system2("git", c("rev-parse", "--short", "HEAD"), stdout = TRUE)
373+
})
373374

374375
msg <- paste0(
375376
"This package was submitted to CRAN on ", date, ".\n",

R/run-source.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#' }
3131
source_url <- function(url, ..., sha1 = NULL) {
3232
stopifnot(is.character(url), length(url) == 1)
33+
if (!requireNamespace("digest", quietly = TRUE)) {
34+
stop("`digest` must be installed to use `source_url()`", call. = FALSE)
35+
}
3336

3437
temp_file <- tempfile()
3538
on.exit(unlink(temp_file))

0 commit comments

Comments
 (0)