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

feat: add use_extendr_badge() #417

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(rust_source)
export(to_toml)
export(use_crate)
export(use_extendr)
export(use_extendr_badge)
export(use_msrv)
export(vendor_pkgs)
export(write_license_note)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rextendr (development version)

* `use_extendr_badge()` has been added to add an extendr-specific badge to a `README.Rmd` via `usethis::use_badge()` <https://github.com/extendr/rextendr/pull/417>
* Removes `Makevars.ucrt` as R versions < 4.1 are not supported by extendr <https://github.com/extendr/rextendr/pull/414>
* `purrr` has been replaced with [`R/standalone-purrr.R`](https://github.com/r-lib/rlang/blob/main/R/standalone-purrr.R) removing `purrr` from `Imports` <https://github.com/extendr/rextendr/pull/408>
* `document()` will no longer try to save all open files using rstudioapi <https://github.com/extendr/rextendr/issues/404> <https://github.com/extendr/rextendr/issues/407>
Expand Down
35 changes: 35 additions & 0 deletions R/badge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' extendr README badge
#'
#' Add the version of extendr being used by an R package to its README.
#'
#' Requires `usethis` to be available.
#'
#' @examples
#' \dontrun{
#' use_extendr_badge()
#' }
#'
#' @inheritParams use_extendr
#' @export
use_extendr_badge <- function(path = ".") {
rlang::check_installed("usethis")
meta <- read_cargo_metadata(path)
deps <- meta[[c("packages", "dependencies")]][[1]]

if (rlang::is_null(deps)) {
cli::cli_abort("Unable to determine version of `extendr-api`")

Check warning on line 20 in R/badge.R

View check run for this annotation

Codecov / codecov/patch

R/badge.R#L20

Added line #L20 was not covered by tests
}

is_extendr <- which(deps$name == "extendr-api")
if (!rlang::is_bare_numeric(is_extendr, 1)) {
cli::cli_abort("Unable to determine version of `extendr-api`")

Check warning on line 25 in R/badge.R

View check run for this annotation

Codecov / codecov/patch

R/badge.R#L25

Added line #L25 was not covered by tests
}

extendr_version <- deps$req[is_extendr]

usethis::use_badge(
"extendr",
"https://extendr.github.io/extendr/extendr_api/",
sprintf("https://img.shields.io/badge/extendr-%s-276DC2", extendr_version)
)
}
6 changes: 6 additions & 0 deletions R/use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ use_extendr <- function(path = ".",
Sys.chmod("configure", "0755")
}

# Set the minimum version of R to 4.2 as now required by libR-sys 0.7
usethis::use_package("R", "Depends", "4.2")

# the temporary cargo directory must be ignored
usethis::use_build_ignore("src/.cargo")

Expand All @@ -217,6 +220,9 @@ use_extendr <- function(path = ".",
usethis::use_build_ignore("src/Makevars.win")
usethis::use_git_ignore("src/Makevars.win")


use_extendr_badge()

if (!isTRUE(quiet)) {
cli::cli_alert_success("Finished configuring {.pkg extendr} for package {.pkg {pkg_name}}.")
cli::cli_ul(
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ reference:
- make_module_macro
- rust_sitrep
- read_cargo_metadata
- use_extendr_badge
23 changes: 23 additions & 0 deletions man/use_extendr_badge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@
> File 'tools/msrv.R' already exists. Skip writing the file.
> File 'configure' already exists. Skip writing the file.
> File 'configure.win' already exists. Skip writing the file.
! Can't find a README for the current project.
i See `usethis::use_readme_rmd()` for help creating this file.
i Badge link will only be printed to screen.
[ ] Copy and paste the following lines into 'README':
<!-- badges: start -->
[![extendr](https://img.shields.io/badge/extendr-*-276DC2)](https://extendr.github.io/extendr/extendr_api/)
<!-- badges: end -->
v Finished configuring extendr for package testpkg.wrap.
* Please run `rextendr::document()` for changes to take effect.

Expand All @@ -416,6 +423,13 @@
v Writing 'tools/msrv.R'
v Writing 'configure'
v Writing 'configure.win'
! Can't find a README for the current project.
i See `usethis::use_readme_rmd()` for help creating this file.
i Badge link will only be printed to screen.
[ ] Copy and paste the following lines into 'README':
<!-- badges: start -->
[![extendr](https://img.shields.io/badge/extendr-*-276DC2)](https://extendr.github.io/extendr/extendr_api/)
<!-- badges: end -->
v Finished configuring extendr for package testpkg.
* Please run `rextendr::document()` for changes to take effect.

Expand Down
Loading