Skip to content

Commit

Permalink
initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
kbvernon committed Sep 7, 2024
1 parent 0359070 commit 26988e8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions R/use_msrv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' Add MSRV to DESCRIPTION
#'

Check warning on line 2 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=2,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @param version character scalar, the minimum supported Rust version
#' @param path character scalar, path to folder containing DESCRIPTION file
#'

Check warning on line 5 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=5,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @details
#' It is assumed that MSRV is greater than or equal to `version`. The result is
#' "SystemRequirements: Cargo (Rust's package manager), rustc >= `version`."
#'

Check warning on line 9 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=9,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @return NULL
#' @export
#'

Check warning on line 12 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=12,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @examples
#' \dontrun{
#' use_msrv("1.67.1")
#' }
#'

Check warning on line 17 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=17,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
use_msrv <- function(version = NULL, path = "."){

Check warning on line 18 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=18,col=49,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 18 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=18,col=49,[paren_body_linter] There should be a space between a right parenthesis and a body expression.

if (is.null(version)){

Check warning on line 20 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=20,col=24,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 20 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=20,col=24,[paren_body_linter] There should be a space between a right parenthesis and a body expression.
cli::cli_abort(
"Minimum supported Rust {.arg version} not specified.",
class = "rextendr_error"
)
}

desc_path <- rprojroot::find_package_root_file("DESCRIPTION", path = path)

if (!file.exists(desc_path)) {
cli::cli_abort(
"{.arg path} ({.path {path}}) does not contain a DESCRIPTION",
class = "rextendr_error"
)
}

cur <- paste("Cargo (Rust's package manager), rustc", paste(">=", version))

Check warning on line 36 in R/use_msrv.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_msrv.R,line=36,col=78,[trailing_whitespace_linter] Trailing whitespace is superfluous.

prev <- desc::desc_get("SystemRequirements", file = desc_path)[[1]]
prev <- stringi::stri_trim_both(prev)

if (is.na(prev)) {
update_description("SystemRequirements", cur, desc_path = desc_path)
} else if (!identical(cur, prev)) {
cli::cli_ul(
c(
"The SystemRequirements field in the {.file DESCRIPTION} file is already set.",
"Please update it manually if needed."
)
)
}

invisible(version)

}

0 comments on commit 26988e8

Please sign in to comment.