Skip to content

Commit

Permalink
reduce lint preparing for #16
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Feb 18, 2021
1 parent 99e11f8 commit 98360b9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
5 changes: 3 additions & 2 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ gh_pkgs_image_url <- function(image_name = gh_pkgs_image_name(target = "runtime"
)
}

#' @describeIn gh_pkgs_image_url Get the docker image name conventionally used in muggle projects
#' @describeIn gh_pkgs_image_url
#' Get the docker image name conventionally used in muggle projects
#'
#' @param target Build target for multistage muggle builds.
#' By convention, for a package `foo`, {muggle} would build a `foo-buildtime` and `foo-runtime` for the `buildtime` and `runtime` docker multistage build targets, respectively.
Expand Down Expand Up @@ -64,7 +65,7 @@ gh_pkgs_image_version <- function() {
gh_repo_spec <- function() {
# something like this already exists in usethis, but seems unexported
# muggle image *has* git, and on gh actions should also have a repo
# but this will not work in a local docker container, which has git, but no repo
# but this will not work in a local docker cont, which has git, but no repo
do.call(paste, c(gh::gh_tree_remote(), sep = "/"))
}

Expand Down
28 changes: 17 additions & 11 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Browse to URL
#'
#' @details This function is copied from an unexported function in [usethis](https://github.com/r-lib/usethis/blob/23dd62c5e7713ed8ecceae82e6338f795d30ba92/R/helpers.R).
#' @details
#' This function is copied from an unexported function in [usethis](https://github.com/r-lib/usethis/blob/23dd62c5e7713ed8ecceae82e6338f795d30ba92/R/helpers.R).
#'
#' @param ... Elements of the URL
#' @param open `[logical(1)]` giving whether the URL should be opened
Expand All @@ -24,34 +25,35 @@ remove_dep <- function(x) {
desc::desc_del_dep(x)
usethis::ui_done(
x = glue::glue(
"Removing {dep} from DESCRIPTION again, because it is already included in the muggle image.",
"Removing {dep} from DESCRIPTION again, ",
"because it is already included in the muggle image.",
dep = x
)
)
}

#' Muggle files
#'
#' @param muggle_file
#'
#' @param muggle_file
#' File to copy, relative path from built package root.
#'
#'
#' @keywords internal
#' @export
get_muggle_file <- function(muggle_file) {
system.file(muggle_file, package = "muggle")
}

#' Temporarily get muggle files
#'
#'
#' Copies muggle files ([get_muggle_file()]) to the working directory.
#' Files are deleted when `.local_envir` expires.
#' If file already exists, only a warning is thrown.
#' Useful to avoid pasting boilerplate files in muggle packages.
#'
#'
#' @inheritParams get_muggle_file
#'
#'
#' @inheritParams withr::local_file
#'
#'
#' @keywords internal
#' @export
local_muggle_file <- function(muggle_file, .local_envir = parent.frame()) {
Expand All @@ -62,14 +64,18 @@ local_muggle_file <- function(muggle_file, .local_envir = parent.frame()) {
"To use muggle defaults, remove the file."
))
} else {
target <- withr::local_file(.file = muggle_file, .local_envir = .local_envir)
target <- withr::local_file(
.file = muggle_file,
.local_envir = .local_envir
)
fs::file_copy(path = get_muggle_file(muggle_file), new_path = target)
}
}

#' Determine if code is running inside GitHub Actions
#'
#' Looks for the `GITHUB_ACTIONS` environment variable, as [documented](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)
#' Looks for the `GITHUB_ACTIONS` environment variable,
#' as [documented](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)
#'
#' @keywords internal
is_github_actions <- function() {
Expand Down
30 changes: 15 additions & 15 deletions R/pkgdown.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#' Replacement versions of [pkgdown::build_site()] etc. with muggle defaults
#'
#'
#' Sets some muggle defaults for pkgdown to minimize code duplication across muggle projects.
#' This includes overrides of `_pkgdown.yml` and `_site.yml`.
#'
#'
#' @section Additions to pkgdown:
#' These replacement versions of pkgdown functions make the following changes to pkgdown, as applicable:
#' - If there are `vignettes/`, declaring a default vignette rendering function ([local_siteyaml()])
#' - Overriding some values in `_pkgdown.yml` by appending [override_pkgdownyaml()]) to `override`.
#' Be careful not to provide conflicting overrides.
#' - Sets `run_dont_run = TRUE`, so that examples inside `\dontrun{}` are still run inside of pkgdown.
#' Examples often need to be skipped on CRAN and other checks, though not when building pkgdown.
#'
#'
#' @inheritSection pkgdown::build_site YAML config - navbar
#' @inheritParams pkgdown::build_site
#' @inheritDotParams pkgdown::build_site
Expand Down Expand Up @@ -40,12 +40,12 @@ build_article2 <- function(...) {
}

#' List of overrides for `_pkgdown.yml` with muggle defaults.
#'
#'
#' @examples
#' \dontrun{
#' override_pkgdownyaml()
#' }
#'
#'
#' @family pkgdown functions
#' @export
override_pkgdownyaml <- function() {
Expand All @@ -56,30 +56,30 @@ override_pkgdownyaml <- function() {


#' Temporarily create muggle default `vignettes/_site.yml` file
#'
#'
#' Upgrades vignettes to muggle default.
#' Wraps [local_muggle_file()] to delete file upon use.
#'
#'
#' @details
#' This `vignettes/_site.yml` declares the default vignette rendering function for muggle vignettes.
#' To enable it, you also must declare in the yaml frontmatter *for each of the vignettes*:
#'
#'
#' ```yaml
#' pkgdown:
#' as_is: true
#' ```
#'
#'
#' For an example of such a vignette with all its features, see `vignette("vignette-muggle")`
#'
#'
#' @section Features:
#' ## Backported Bookdown Features
#' By default, pkgdown builds vignettes (or rather, articles) using a special format based on [rmarkdown::html_document()].
#' This format does not include the automatic numbering and crossreferencing of figures, tables, equations, and (for cross-references) sections supported by [bookdown](http://bookdown.org).
#' The [`bookdown::html_document2()`](https://bookdown.org/yihui/bookdown/a-single-document.html) render function backports these features for uses outside of bookdown.
#'
#'
#' ## Raw HTML
#' Pandoc extensions are set to allow correctly indented raw HTML inside vignettes.
#'
#'
#' @inheritParams local_muggle_file
#' @family pkgdown functions
#' @export
Expand All @@ -88,17 +88,17 @@ local_siteyaml <- function(.local_envir = parent.frame()) {
}

#' Retrieve the public URL from the `DESCRIPTION`
#'
#'
#' Chooses whichever URL in the `DESCRIPTION` is *not* on github.com.
#' That's assumed to be the public-facing website, such as a pkgdown website on GitHub pages.
#'
#'
#' @keywords internal
get_url_from_desc <- function() {
all_urls <- desc::desc_get_urls()
gh_urls <- sapply(all_urls, is_gh_url)
public_urls <- all_urls[!gh_urls]
public_urls[1]
}
}

is_gh_url <- function(url) {
httr::parse_url(url)$hostname == "github.com"
Expand Down
13 changes: 8 additions & 5 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#'
#' @inheritParams usethis::create_package
#' @param license one of the license functions in [usethis]
#' @param license_holder giving the license holder, used as `cph` and `fnd` role in `DESCRIPTION`
#' @param license_holder
#' giving the license holder, used as `cph` and `fnd` role in `DESCRIPTION`
#' @inheritParams usethis::use_github
#' @family setup functions
#' @export
Expand Down Expand Up @@ -63,7 +64,8 @@ create_muggle_package <- function(path,
usethis::use_git()
# imperfect check for whether github remote is set
if (nrow(gert::git_remote_list()) == 0) {
# if there was already a git remote as will be the case for existing projects, the whole function would error out here
# if there was already a git remote as will be the case for existing projects,
# the whole function would error out here
usethis::use_github(
organisation = organisation,
private = private,
Expand Down Expand Up @@ -98,9 +100,10 @@ create_muggle_package <- function(path,
text = c("See `help('muggle::lib_cache_path')`"),
path = fs::path(lib_cache_path, "README.md")
)
usethis::ui_done(
"Created {usethis::ui_code(lib_cache_path)} to add cached dependencies to docker build context on GitHub actions."
)
usethis::ui_done(c(
"Created {usethis::ui_code(lib_cache_path)} to add cached dependencies ",
"to docker build context on GitHub actions."
))

# compute environment ====
# TODO add docker generation
Expand Down
6 changes: 3 additions & 3 deletions R/test-helpers.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local_create_package <- function(dir = fs::file_temp(), env = parent.frame()) {
old_wd <- getwd()

usethis::create_package(dir, open = FALSE)
withr::defer(fs::dir_delete(dir), envir = env)

setwd(dir)
withr::defer(setwd(old_wd), envir = env)

dir
}
10 changes: 6 additions & 4 deletions R/testing.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#' Set up codecov
#' @param reposlug `[character(1)]` giving the `username/repo` URL slug of the project.
#' @param reposlug `[character(1)]`
#' giving the `username/repo` URL slug of the project.
#' @family testing functions
#' @export
use_codecov2 <- function(reposlug) {
usethis::use_coverage(type = "codecov")
usethis::ui_todo(
"Add the {usethis::ui_value('Repository Upload Token')} from codecov as a secret called {usethis::ui_value('CODECOV_TOKEN')} on GitHub."
)
usethis::ui_todo(c(
"Add the {usethis::ui_value('Repository Upload Token')} from codecov ",
"as a secret called {usethis::ui_value('CODECOV_TOKEN')} on GitHub."
))
view_url("https://codecov.io/gh", reposlug, "settings")
view_url("https://github.com", reposlug, "settings", "secrets")
}
3 changes: 2 additions & 1 deletion man/is_github_actions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/use_codecov2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98360b9

Please sign in to comment.