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

Try to avoid issue with stringi installation #94

Merged
merged 6 commits into from
May 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3-

- name: Install system dependencies
if: runner.os == 'Linux'
if: runner.os == 'Linux (no, try without!)'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Imports:
processx,
rematch2,
sessioninfo,
stringr,
usethis,
withr,
yaml
Expand All @@ -53,4 +52,4 @@ Remotes:
ByteCompile: true
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
RoxygenNote: 7.3.1
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ importFrom(pkgdown,build_site)
importFrom(processx,run)
importFrom(rematch2,re_match)
importFrom(sessioninfo,package_info)
importFrom(stringr,str_detect)
importFrom(stringr,str_remove)
importFrom(stringr,str_replace)
importFrom(stringr,str_split)
importFrom(tools,toTitleCase)
importFrom(usethis,use_description)
importFrom(usethis,use_git_ignore)
importFrom(usethis,use_mit_license)
importFrom(usethis,use_pkgdown)
importFrom(usethis,use_template)
importFrom(utils,tail)
importFrom(utils,getFromNamespace)
importFrom(withr,with_dir)
35 changes: 14 additions & 21 deletions R/.add_authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ add_authors <- function(author_meta, role = "ctb", path = getwd())
#' @export
#' @importFrom purrr transpose
convert_author_metadata_tolist <- function(
author_metadata_df = create_author_metadata_from_orcid()
author_metadata_df = create_author_metadata_from_orcid()
)
{
setNames(
Expand All @@ -94,31 +94,24 @@ convert_author_metadata_tolist <- function(
#' @param orcids named character vector with ORCIDs and names correspondig to
#' to "given_name family name" (defaults: kwb.orcid::get_kwb_orcids())
#' @importFrom kwb.orcid get_kwb_orcids
#' @importFrom stringr str_trim str_split
#' @importFrom magrittr %>%
#' @importFrom kwb.utils extractSubstring setColumns
#' @return data frame with required metadata for R package DESCRIPTION as
#' required by desc::desc_add_author()
#' @export
create_author_metadata_from_orcid <- function(
orcids = kwb.orcid::get_kwb_orcids()
orcids = kwb.orcid::get_kwb_orcids()
)
{
orc_ids <- orcids[order(orcids)]
orc_names <- names(orcids)
orc_ids <- sort(orcids)

orc_names_matrix <- orc_names %>%
stringr::str_trim() %>%
stringr::str_split(pattern = "\\s+", simplify = TRUE, n = 2)

kwb.utils::noFactorDataFrame(
given = orc_names_matrix[,1],
family = orc_names_matrix[,2],
email = sprintf(
"%s.%s@kompetenz-wasser.de",
tolower(orc_names_matrix[, 1]),
tolower(orc_names_matrix[, 2])
),
orcid = orc_ids,
row.names = NULL
)
names(orcids) %>%
kwb.utils::extractSubstring(
pattern = "^\\s*(\\S+)\\s+(\\S+)\\s*$",
index = c(given = 1L, family = 2L)
) %>%
kwb.utils::setColumns(
email = email_kwb(.[["given"]], .[["family"]]),
orcid = orc_ids,
dbg = FALSE
)
}
15 changes: 7 additions & 8 deletions R/create_pkg_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,21 @@ create_pkg_dir <- function(pkg_dir)

#' @noRd
#' @keywords internal
#' @importFrom stringr str_split
#' @importFrom utils tail
check_pkg_dir_nested <- function(pkg_dir)
{
last_folders <- utils::tail(n = 2, as.character(
stringr::str_split(pkg_dir, pattern = "/", simplify = TRUE)
))
leaf_folder <- basename(pkg_dir)
parent_folder <- basename(dirname(pkg_dir))

if (last_folders[1] == last_folders[2]) clean_stop(
sprintf("Package skeleton for '%s' cannot be created, ", last_folders[2]),
if (parent_folder == leaf_folder) clean_stop(
sprintf("Package skeleton for '%s' cannot be created, ", leaf_folder),
sprintf("as it would be nested in subfolder '%s'.\n\n", pkg_dir),
"Workaround: specify a different 'root_dir' in function use_pkg_skeleton()"
)

message(sprintf(
"%s is a valid 'root_dir' for pkg '%s'", pkg_dir, last_folders[2]
"%s is a valid 'root_dir' for pkg '%s'",
pkg_dir,
leaf_folder
))

pkg_dir
Expand Down
4 changes: 2 additions & 2 deletions R/deploy_site_github_with_extra_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ deploy_to_branch_with_extra_files <- function(pkg = ".",

if (clean) {
rule("Cleaning files from old site", line = 1)
pkgdown:::clean_site(pkg)
pkgdown::clean_site(pkg)
}

pkgdown::build_site(pkg, devel = FALSE, preview = FALSE, install = FALSE, ...)
Expand All @@ -271,7 +271,7 @@ deploy_to_branch_with_extra_files <- function(pkg = ".",
)

if (github_pages) {
pkgdown:::build_github_pages(pkg)
getFromNamespace("build_github_pages", "pkgdown")(pkg)
}

github_push(dest_dir, commit_message, remote, branch)
Expand Down
23 changes: 16 additions & 7 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ clean_stop <- function(...)
stop(..., call. = FALSE)
}

# email_kwb --------------------------------------------------------------------
email_kwb <- function(
given,
family,
full_name = paste0(given, family, sep = ".")
)
{
paste0(tolower(full_name), "@kompetenz-wasser.de")
}

# get_from_namespace -----------------------------------------------------------
#' @importFrom utils getFromNamespace
get_from_namespace <- utils::getFromNamespace

# get_pkgname ------------------------------------------------------------------

#' Helper Function: Get Package Name
Expand Down Expand Up @@ -121,7 +135,6 @@ path_to_git <- function()
#' @param dbg print debug messages (default: TRUE)
#' @return sets globally user.name and user.email in Git
#' @export
#' @importFrom stringr str_replace
set_github_user <- function(
git_username = "kwb.pkgbuild::use_autopkgdown()",
git_fullname = "kwb.pkgbuild::use_autopkgdown()",
Expand All @@ -132,13 +145,9 @@ set_github_user <- function(
dbg = TRUE
)
{
# Compose KWB e-mail address
if (is.null(git_email)) {

# Replace space with dot
dot_name <- stringr::str_replace(git_fullname, "\\s+", ".")

# Compose KWB e-mail address
git_email <- paste0(tolower(dot_name), "@kompetenz-wasser.de")
git_email <- email_kwb(full_name = gsub("\\s+", ".", git_fullname))
}

git_exe <- git_check_if_windows(git_exe)
Expand Down
2 changes: 1 addition & 1 deletion R/use_badges.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ use_badge_codecov <- function(repo = NULL, user = "KWB-R", domain = "github")
#' @export
use_badge_lifecycle <- function(stage = "experimental")
{
stages <- usethis:::stages
stages <- getFromNamespace("stages", "usethis")
stage <- match.arg(tolower(stage), names(stages))

kwb.utils::resolve(
Expand Down
4 changes: 2 additions & 2 deletions R/use_codecov.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' @export
use_codecov <- function()
{
usethis:::check_uses_github_actions()
usethis:::use_dependency("covr", "Suggests")
getFromNamespace("check_uses_github_actions", "usethis")()
getFromNamespace("use_dependency", "usethis")("covr", "Suggests")

if (! usethis::use_template("codecov.yml", ignore = TRUE)) {
return(invisible(FALSE))
Expand Down
11 changes: 4 additions & 7 deletions R/use_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' @return writes DESCRIPTION file using usethis::use_description() with KWB
#' style
#' @importFrom usethis use_description
#' @importFrom stringr str_split
#' @importFrom tools toTitleCase
#' @export
use_description <- function(
Expand All @@ -37,13 +36,11 @@ use_description <- function(

pkg$title <- tools::toTitleCase(pkg$title)

full_name <- stringr::str_split(string = author$name,pattern = "\\s+")[[1]]
author_name <- full_name[1]
author_surname <- full_name[2]
full_name <- strsplit(author$name, "\\s+")[[1L]]
author_name <- full_name[1L]
author_surname <- full_name[2L]

author_email <- sprintf(
'%s.%s@kompetenz-wasser.de', tolower(author_name), tolower(author_surname)
)
author_email <- email_kwb(given = author_name, family = author_surname)

author_comment <- if (is.null(author$orcid)) {
"NULL"
Expand Down
7 changes: 2 additions & 5 deletions R/use_gitlab_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ use_gitlab_ci_blogdown <- function(
#' https://github.com/KWB-R/kwb.pkgbuild" sets "KWB-R/kwb.pkgbuild" as
#' "<owner>/<repo>")
#' @return writes .gitlab-ci.yml
#' @importFrom stringr str_remove
#' @importFrom desc desc_get
#' @export

use_gitlab_ci_pkgdown <- function(
dest_dir = getwd(), yml_vector = gitlab_ci_template_pkgdown()
)
{
repo <- stringr::str_remove(desc::desc_get("URL"), "^http(s)?://github.com/")

yml_vector <- stringr::str_replace(yml_vector, "<owner>/<repo>", repo)

owner_repo <- gsub("^http(s)?://github.com/", "", desc::desc_get("URL"))
yml_vector <- gsub("<owner>/<repo>", owner_repo, yml_vector)
write_gitlab_ci(yml_vector, dest_dir = dest_dir, ignore = TRUE)
}

Expand Down
54 changes: 27 additions & 27 deletions R/use_mit_license.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
#' (default: "list(name = kwb.pkgbuild:::kwb_string(), start_year = NULL)")
#' @return creates MIT licence file
#' @importFrom usethis use_mit_license
#' @importFrom stringr str_detect
#' @importFrom fs file_copy
#' @importFrom kwb.utils catAndRun
#' @export
use_mit_license <- function(
copyright_holder = list(name = kwb_string(), start_year = NULL)
copyright_holder = list(name = kwb_string(), start_year = NULL)
)
{
kwb.utils::catAndRun("Creating KWB MIT LICENSE/LICENSE.md files",
expr = {
usethis::use_mit_license(copyright_holder = copyright_holder$name)})
kwb.utils::catAndRun("Creating KWB MIT LICENSE/LICENSE.md files", {
usethis::use_mit_license(copyright_holder = copyright_holder$name)
})

this_year <- format(Sys.Date(), format = "%Y")

copyright_years <- ifelse(!is.null(copyright_holder$start_year),
sprintf("%s-%s", as.character(copyright_holder$start_year),
format(Sys.Date(), format = "%Y")),
format(Sys.Date(), format = "%Y"))
copyright_years <- ifelse(
is.null(copyright_holder$start_year),
this_year,
sprintf("%s-%s", as.character(copyright_holder$start_year), this_year)
)

if (! is.null(copyright_holder$start_year)) {
if (is.null(copyright_holder$start_year)) {
return()
}

kwb.utils::catAndRun("Modifying start year in MIT LICENSE (CRAN version)",
expr = {
writeLines(text = sprintf("YEAR: %s\nCOPYRIGHT HOLDER: %s",
copyright_years,
copyright_holder$name),
con = "LICENSE")
})
kwb.utils::catAndRun("Modifying start year in MIT LICENSE (CRAN version)", {
writeLines(
text = sprintf(
"YEAR: %s\nCOPYRIGHT HOLDER: %s",
copyright_years,
copyright_holder$name
),
con = "LICENSE"
)
})

kwb.utils::catAndRun("Modifying start year in MIT LICENSE.md",
expr = {
kwb.utils::catAndRun("Modifying start year in MIT LICENSE.md", {
lic_txt <- readLines("LICENSE.md")
index <- stringr::str_detect(lic_txt,pattern = "^Copyright\\s+\\(c\\)")

index <- grep("^Copyright\\s+\\(c\\)", lic_txt)
lic_txt[index] <- sprintf(
"Copyright (c) %s %s",
copyright_years,
copyright_holder$name
)

writeLines(lic_txt, "LICENSE.md")})


}

writeLines(lic_txt, "LICENSE.md")
})
}
7 changes: 2 additions & 5 deletions R/use_pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#' "archived", "dormant", "questioning"), (default: "experiment")
#' @return writes DESCRIPTION file using usethis::use_description() with KWB
#' style
#' @importFrom stringr str_detect
#' @importFrom fs dir_create
#' @param auto_build_pkgdown prepare Travis for pkgdown::build_site() (default:
#' FALSE), only possible if GITHUB repo already existing
Expand Down Expand Up @@ -55,10 +54,8 @@ use_pkg <- function(
copyright_holder_name = copyright_holder$name, funder = funder
)

# Create MIT LICENSE file
mit_licence <- stringr::str_detect(string = license, pattern = "MIT")

if (mit_licence) {
# Create MIT LICENSE file if applicable
if (grepl("MIT", license)) {
use_mit_license(copyright_holder)
}

Expand Down
3 changes: 1 addition & 2 deletions R/use_pkg_skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use_pkg_skeleton <- function(pkg_name)

usethis::use_git_ignore(".Rproj.user")

if (usethis:::is_package()) {

if (getFromNamespace("is_package", "usethis")()) {
usethis::use_build_ignore(c(
rproj_file, ".Rhistory", ".RData", ".Rproj.user" , ".here"
))
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#ignore docs
docs
28 changes: 19 additions & 9 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
## Helper for creating temporary R package
create_pkg_temp <- function() {
number <- sample(x = 1:10000000,size = 1)
root_dir <- paste0(stringr::str_replace_all(tempdir(),"\\\\", "/"),
sprintf("%d", number))
pkg_name <- "testpkg"
pkg_dir <- file.path(root_dir, pkg_name)
kwb.pkgbuild::create_pkg_dir(pkg_dir)
withr::with_dir(pkg_dir, {kwb.pkgbuild::use_pkg_skeleton(pkg_name)})
pkg_dir
create_pkg_temp <- function()
{
number <- sample(x = 1:10000000, size = 1L)

root_dir <- paste0(
kwb.utils::rStylePath(tempdir()),
sprintf("%d", number)
)

pkg_name <- "testpkg"
pkg_dir <- file.path(root_dir, pkg_name)

kwb.pkgbuild::create_pkg_dir(pkg_dir)

withr::with_dir(pkg_dir, {
kwb.pkgbuild::use_pkg_skeleton(pkg_name)
})

pkg_dir
}

# create_pkg_temp <- function(root_dir = tempdir()) {
Expand Down
Loading
Loading