Skip to content

Commit

Permalink
feat: Add compute_codecov() utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ymansiaux committed Jun 17, 2024
1 parent 164569a commit 4a9be86
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Imports:
lightparser,
magrittr,
methods,
pkgload,
roxygen2,
stats,
stringi,
Expand All @@ -40,7 +41,6 @@ Imports:
Suggests:
gert,
knitr,
pkgload,
rcmdcheck,
rmarkdown,
rstudioapi,
Expand All @@ -49,7 +49,7 @@ Suggests:
withr
VignetteBuilder:
knitr
Config/fusen/version: 0.6.0.9001
Config/fusen/version: 0.6.0.9002
Config/testthat/edition: 3
Config/testthat/parallel: false
Encoding: UTF-8
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ importFrom(devtools,check)
importFrom(glue,glue)
importFrom(magrittr,"%>%")
importFrom(methods,formalArgs)
importFrom(pkgload,unload)
importFrom(stats,na.omit)
importFrom(stats,setNames)
importFrom(stringi,stri_trans_general)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tools,file_path_sans_ext)
importFrom(utils,getFromNamespace)
importFrom(utils,osVersion)
importFrom(utils,read.csv)
importFrom(utils,write.csv)
importFrom(yaml,read_yaml)
Expand Down
62 changes: 43 additions & 19 deletions R/inflate-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ parse_fun <- function(x) { # x <- rmd_fun[3,]
# If chunk all empty
code <- character(0)
} else if (!is.na(first_function_start) &&
!any(grepl("@export|@noRd", code[1:first_function_start]))) {
!any(grepl("@export|@noRd", code[1:first_function_start]))) {
if (!is.na(last_hastags_above_first_fun)) {
code <- c(
code[1:last_hastags_above_first_fun],
Expand Down Expand Up @@ -142,7 +142,7 @@ parse_fun <- function(x) { # x <- rmd_fun[3,]
add_names_to_parsed <- function(parsed_tbl, fun_code) {
# Which parts were functions
which_parsed_fun <- which(!is.na(parsed_tbl$label) &
grepl(regex_functions, parsed_tbl$label))
grepl(regex_functions, parsed_tbl$label))

# From fun_code, we retrieve fun_name & rox_filename
parsed_tbl[["fun_name"]] <- NA_character_
Expand Down Expand Up @@ -175,7 +175,7 @@ add_names_to_parsed <- function(parsed_tbl, fun_code) {
sec_title_name[["sec_title"]] == x, "sec_fun_name"
]
parsed_tbl[group, "sec_fun_name"] <- ifelse(length(sec_fun_name) == 0,
NA_character_, as.character(sec_fun_name)
NA_character_, as.character(sec_fun_name)
)
parsed_tbl[group, ] <- tidyr::fill(
parsed_tbl[group, ],
Expand Down Expand Up @@ -204,7 +204,7 @@ add_names_to_parsed <- function(parsed_tbl, fun_code) {
pkg_filled[["file_name"]] <- NA_character_
# chunk_filename
pkg_filled[["file_name"]] <- ifelse(!is.na(pkg_filled[["chunk_filename"]]),
pkg_filled[["chunk_filename"]], NA_character_
pkg_filled[["chunk_filename"]], NA_character_
)
# rox_filename
pkg_filled[["file_name"]] <- ifelse(
Expand Down Expand Up @@ -280,7 +280,7 @@ parse_test <- function(x, pkg, relative_flat_file) { # x <- rmd_test[1,]
add_fun_code_examples <- function(parsed_tbl, fun_code) {
# Example in separate chunk
which_parsed_ex <- which(!is.na(parsed_tbl$label) &
grepl(regex_example, parsed_tbl$label))
grepl(regex_example, parsed_tbl$label))
rmd_ex <- parsed_tbl[which_parsed_ex, ]

# Get file_name variable
Expand All @@ -292,8 +292,8 @@ add_fun_code_examples <- function(parsed_tbl, fun_code) {
fun_code <- fun_code[order(fun_code[["order"]]), ]
# Get file_name for not functions. Only last place where possible
fun_code[["file_name"]] <- ifelse(is.na(fun_code[["file_name"]]),
fun_code[["sec_title"]],
fun_code[["file_name"]]
fun_code[["sec_title"]],
fun_code[["file_name"]]
)

# Example already in skeleton
Expand Down Expand Up @@ -378,8 +378,8 @@ add_fun_code_examples <- function(parsed_tbl, fun_code) {
}

end_skeleton <- ifelse(is.na(fun_code_x[["example_pos_start"]]),
fun_code_x[["example_pos_end"]],
fun_code_x[["example_pos_start"]] - 1
fun_code_x[["example_pos_end"]],
fun_code_x[["example_pos_start"]] - 1
)

all_fun_code <- stats::na.omit(c(
Expand All @@ -392,7 +392,7 @@ add_fun_code_examples <- function(parsed_tbl, fun_code) {
# end
unlist(fun_code_x[["code"]])[
(fun_code_x[["example_pos_end"]] + 1):
length(unlist(fun_code_x[["code"]]))
length(unlist(fun_code_x[["code"]]))
]
))
return(all_fun_code)
Expand Down Expand Up @@ -476,14 +476,14 @@ create_vignette_head <- function(pkg, vignette_name, yaml_options = NULL) {
title: ".{vignette_title}."
output: rmarkdown::html_vignette',
ifelse(length(yaml_options) != 0,
glue::glue_collapse(
c(
"",
glue("{names(yaml_options)}: \"{yaml_options}\""), ""
),
sep = "\n"
),
"\n"
glue::glue_collapse(
c(
"",
glue("{names(yaml_options)}: \"{yaml_options}\""), ""
),
sep = "\n"
),
"\n"
),
'vignette: >
%\\VignetteIndexEntry{.{vignette_name}.}
Expand All @@ -502,7 +502,7 @@ knitr::opts_chunk$set(
library(.{pkgname}.)
```
',
.open = ".{", .close = "}."
.open = ".{", .close = "}."
)
)
}
Expand Down Expand Up @@ -623,3 +623,27 @@ document_and_check_pkg <- function(pkg = ".", document = TRUE, check = TRUE, ...
print(res)
}
}

#' Document and check current package
#' @param pkg Path to package
#' @importFrom pkgload unload
#' @importFrom covr package_coverage
#' @importFrom utils osVersion
#' @noRd
compute_codecov <- function(pkg = ".") {
on_windows <- grepl("windows", tolower(osVersion))
if (on_windows) {
# On windows, package_coverage() will fail
# if called right alfer a pkgload::load_all()
pkgload::unload(
basename(
normalizePath(
pkg
)
)
)
}
print(
covr::package_coverage()
)
}

0 comments on commit 4a9be86

Please sign in to comment.