Skip to content

feat: add use_extendr_badge() #417

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 34 additions & 0 deletions R/badge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' 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
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 19 in R/badge.R

View check run for this annotation

Codecov / codecov/patch

R/badge.R#L19

Added line #L19 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 24 in R/badge.R

View check run for this annotation

Codecov / codecov/patch

R/badge.R#L24

Added line #L24 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 @@ -206,6 +206,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 @@ -225,6 +228,9 @@ use_extendr <- function(path = ".",
usethis::use_build_ignore("src/Makevars.win")
usethis::use_git_ignore("src/Makevars.win")


use_extendr_badge()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use it by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, as a point of encouragement. It does quite literally nothing other than print a message to the console. The hope is that users can add it to their package for a bit of flair and provide and indication that they're R package is rust powered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like it defeats the purpose, a user still have to run use_extendr() once. What's the point of a separate function? Perhaps it is better to show here an invite to run rextendr::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 README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ knitr::opts_chunk$set(
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R build status](https://github.com/extendr/rextendr/workflows/R-CMD-check/badge.svg)](https://github.com/extendr/rextendr/actions)
[![Codecov test coverage](https://codecov.io/gh/extendr/rextendr/graph/badge.svg)](https://app.codecov.io/gh/extendr/rextendr)
[![extendr](https://img.shields.io/badge/extendr-^0.7.1-276DC2)](https://extendr.github.io/extendr/extendr_api/)
<!-- badges: end -->

## Installation
Expand Down
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 @@ -410,6 +410,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 @@ -430,6 +437,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