Skip to content

Commit

Permalink
Merge branch 'main' into chore-parallel-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Mar 10, 2024
2 parents c276eb2 + 106dfb4 commit 73c2208
Show file tree
Hide file tree
Showing 282 changed files with 6,685 additions and 3,035 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
^\.Rproj\.user$
^\.idea$
^\.dev$
^\.devcontainer$
^\.lintr$
^\.lintr_new$
^wercker\.yml$
Expand Down
54 changes: 54 additions & 0 deletions .dev/lint_metadata_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This script is designed to find linters that lack metadata tests.
# To do so, it forces Lint() to give the wrong information,
# runs the test suite, and finds linters that nevertheless pass all their tests.
library(testthat)

lint_file <- "R/lint.R"

original <- readLines(lint_file)
expected_line <- "line_number = as.integer(line_number)"
if (sum(grepl(expected_line, original, fixed = TRUE)) != 1L) {
stop(sprintf(
"Please update this workflow -- need exactly one hit for line '%s' in file '%s'.",
expected_line, lint_file
))
}
writeLines(
sub(expected_line, "line_number = as.integer(2^31 - 1)", original, fixed = TRUE),
lint_file
)
# Not useful in CI but good when running locally.
withr::defer({
writeLines(original, lint_file)
pkgload::load_all()
})

pkgload::load_all()

report <- test_dir(
"tests/testthat",
filter = "linter$",
stop_on_failure = FALSE,
reporter = SilentReporter$new()
)
names(report) <- gsub("^test-|\\.R$", "", vapply(report, `[[`, "file", FUN.VALUE = character(1L)))

# Hack the nested structure of the testthat report to identify which files have
# any failed test
failed <- report |>
vapply(
\(x) any(vapply(x$results, inherits, "expectation_failure", FUN.VALUE = logical(1L))),
logical(1L)
) |>
which() |>
names() |>
unique()

passed <- setdiff(
available_linters(tags = NULL)$linter,
failed
)

if (length(passed) > 0L) {
stop("Please add tests of lint metadata for the following linters: ", toString(passed))
}
54 changes: 54 additions & 0 deletions .dev/roxygen_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Test to ensure roxygenize() has been run on the current PR
library(tools)
library(roxygen2)

old_dir <- file.path(tempdir(), "man")
if (dir.exists(old_dir)) unlink(old_dir, recursive = TRUE)
file.copy("man", tempdir(), recursive = TRUE)
old_files <- list.files(old_dir, pattern = "\\.Rd$")
new_dir <- "man"
.Last <- function() unlink(old_dir, recursive = TRUE)

# Rd2txt() prints to its out= argument, so we'd have to compare file contents;
# plain parse_Rd() keeps srcref info that encodes the file path, which as.character() strips.
normalize_rd <- function(rd_file) as.character(parse_Rd(rd_file))

rd_equal <- function(f1, f2) isTRUE(all.equal(normalize_rd(f1), normalize_rd(f2)))

check_roxygenize_idempotent <- function(LOCALE) {
Sys.setlocale("LC_COLLATE", LOCALE)
roxygenize()

new_files <- list.files(new_dir, pattern = "\\.Rd$")

old_not_new <- setdiff(old_files, new_files)
if (length(old_not_new) > 0L) {
stop("Found saved .Rd files gone from a fresh run of roxygenize(): ", toString(old_not_new))
}

new_not_old <- setdiff(new_files, old_files)
if (length(new_not_old) > 0L) {
stop("Found new .Rd files from a fresh run of roxygenize(): ", toString(new_not_old))
}

for (file in new_files) {
old_file <- file.path(old_dir, file)
new_file <- file.path(new_dir, file)
if (rd_equal(old_file, new_file)) {
next
}
cat(sprintf("roxygenize() output differs from saved output for %s.\n", file))
cat("Here's the 'diff' comparison of the two files:\n")
cat(" [---]: saved output in man/ directory\n")
cat(" [+++]: roxygenize() output of R/ sources\n")
system2("diff", c("--unified", old_file, new_file))
stop("Failed in LOCALE=", LOCALE, ".", call. = FALSE)
}
}

# Run the check in a few locales to ensure there's no idempotency issues w.r.t. sorting, too
for (LOCALE in c("C", "en_US", "hu_HU", "ja_JP")) {
check_roxygenize_idempotent(LOCALE)
}

unlink(old_dir, recursive = TRUE)
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM rocker/r-base

RUN apt-get -qq update && \
apt-get install -y --no-install-recommends git libxml2-dev

COPY DESCRIPTION .

RUN Rscript -e ' \
install.packages("remotes"); \
remotes::install_deps(dependencies = c( \
"Imports", \
"Config/needs/development" \
)) \
'
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"build": { "dockerfile": "Dockerfile", "context": ".."}
}
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', locale: 'en_US'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', locale: 'zh_CN'}
- {os: ubuntu-latest, r: 'release', http-user-agent: 'release', locale: 'zh_CN'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/check-link-rot.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.3
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/repo-meta-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Various repo-level tests for code quality
on:
push:
branches: [main]
pull_request:
branches: [main]

name: repo-meta-tests

jobs:
repo-meta-tests:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: "release"
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::roxygen2
- name: Ensure lint metadata is tested
run: |
options(crayon.enabled = TRUE)
callr::rscript(".dev/lint_metadata_test.R")
shell: Rscript {0}

- name: Ensure roxygen content matches man directory
run: |
callr::rscript(".dev/roxygen_test.R")
shell: Rscript {0}
10 changes: 9 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ linters: all_linters(
backport_linter("3.6.0", except = c("R_user_dir", "deparse1", "...names")),
line_length_linter(120L),
object_overwrite_linter(allow_names = c("line", "lines", "pipe", "symbols")),
todo_comment_linter(
except_regex = rex::rex(
"TODO(",
# GitHub issue number #1234, possibly from another repo org/repo#5678
maybe(one_or_more(character_class("a-zA-Z0-9-")), "/", one_or_more(character_class("a-zA-Z0-9._-"))),
"#", one_or_more(digit),
")"
)
),
undesirable_function_linter(modify_defaults(
defaults = default_undesirable_functions,
library = NULL,
Expand All @@ -14,7 +23,6 @@ linters: all_linters(
)),
unnecessary_concatenation_linter(allow_single_expression = FALSE),
absolute_path_linter = NULL,
extraction_operator_linter = NULL,
library_call_linter = NULL,
nonportable_path_linter = NULL,
todo_comment_linter = NULL,
Expand Down
18 changes: 8 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ Imports:
Suggests:
bookdown,
cli,
httr (>= 1.2.1),
jsonlite,
mockery,
patrick,
patrick (>= 0.2.0),
rlang,
rmarkdown,
rstudioapi (>= 0.2),
testthat (>= 3.1.5),
testthat (>= 3.2.1),
tibble,
tufte,
withr (>= 2.5.0)
Expand All @@ -53,11 +51,12 @@ Enhances:
VignetteBuilder:
knitr
Config/Needs/website: tidyverse/tidytemplate
Config/Needs/development: pkgload, cli, testthat, patrick
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Collate:
'make_linter_from_xpath.R'
'xp_utils.R'
Expand All @@ -76,8 +75,7 @@ Collate:
'cache.R'
'class_equals_linter.R'
'commas_linter.R'
'comment_linters.R'
'comments.R'
'commented_code_linter.R'
'comparison_negation_linter.R'
'condition_call_linter.R'
'condition_message_linter.R'
Expand All @@ -103,7 +101,6 @@ Collate:
'expect_true_false_linter.R'
'expect_type_linter.R'
'extract.R'
'extraction_operator_linter.R'
'fixed_regex_linter.R'
'for_loop_index_linter.R'
'function_argument_linter.R'
Expand Down Expand Up @@ -144,6 +141,7 @@ Collate:
'nested_ifelse_linter.R'
'nested_pipe_linter.R'
'nonportable_path_linter.R'
'shared_constants.R'
'nrow_subset_linter.R'
'numeric_leading_zero_linter.R'
'nzchar_linter.R'
Expand Down Expand Up @@ -176,8 +174,8 @@ Collate:
'seq_linter.R'
'settings.R'
'settings_utils.R'
'shared_constants.R'
'sort_linter.R'
'source_utils.R'
'spaces_inside_linter.R'
'spaces_left_parentheses_linter.R'
'sprintf_linter.R'
Expand All @@ -186,14 +184,14 @@ Collate:
'strings_as_factors_linter.R'
'system_file_linter.R'
'terminal_close_linter.R'
'todo_comment_linter.R'
'trailing_blank_lines_linter.R'
'trailing_whitespace_linter.R'
'tree_utils.R'
'undesirable_function_linter.R'
'undesirable_operator_linter.R'
'unnecessary_concatenation_linter.R'
'unnecessary_lambda_linter.R'
'unnecessary_nested_if_linter.R'
'unnecessary_nesting_linter.R'
'unnecessary_placeholder_linter.R'
'unreachable_code_linter.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export(linters_with_defaults)
export(linters_with_tags)
export(list_comparison_linter)
export(literal_coercion_linter)
export(make_linter_from_function_xpath)
export(make_linter_from_xpath)
export(matrix_apply_linter)
export(missing_argument_linter)
Expand Down Expand Up @@ -190,6 +191,7 @@ importFrom(utils,tail)
importFrom(utils,txtProgressBar)
importFrom(xml2,as_list)
importFrom(xml2,xml_attr)
importFrom(xml2,xml_children)
importFrom(xml2,xml_find_all)
importFrom(xml2,xml_find_chr)
importFrom(xml2,xml_find_first)
Expand Down
Loading

0 comments on commit 73c2208

Please sign in to comment.