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

use_msrv() #384

Merged
merged 18 commits into from
Sep 7, 2024
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
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
#'

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.
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
#' @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
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
#' "SystemRequirements: Cargo (Rust's package manager), rustc >= `version`."
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
#'

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.
kbvernon marked this conversation as resolved.
Show resolved Hide resolved
#' @return `version`
#' @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.
kbvernon marked this conversation as resolved.
Show resolved Hide resolved

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"

Check warning on line 23 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L20-L23

Added lines #L20 - L23 were not covered by tests
)
}
kbvernon marked this conversation as resolved.
Show resolved Hide resolved

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

Check warning on line 27 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L27

Added line #L27 was not covered by tests

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

Check warning on line 32 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L29-L32

Added lines #L29 - L32 were not covered by tests
)
}

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.

Check warning on line 36 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L36

Added line #L36 was not covered by tests

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

Check warning on line 39 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L38-L39

Added lines #L38 - L39 were not covered by tests

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."

Check warning on line 47 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L41-L47

Added lines #L41 - L47 were not covered by tests
)
)
}
kbvernon marked this conversation as resolved.
Show resolved Hide resolved

invisible(version)

Check warning on line 52 in R/use_msrv.R

View check run for this annotation

Codecov / codecov/patch

R/use_msrv.R#L52

Added line #L52 was not covered by tests

}
Loading