Skip to content

Commit

Permalink
Merge pull request #225 from ThinkR-open/224-flat_template
Browse files Browse the repository at this point in the history
fix: Allow "." for current package
  • Loading branch information
statnmap authored Aug 16, 2023
2 parents d617172 + aacebba commit 592095d
Show file tree
Hide file tree
Showing 24 changed files with 593 additions and 166 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ Suggests:
withr
VignetteBuilder:
knitr
Config/fusen/version: 0.5.0.9011
Config/fusen/version: 0.5.1
Config/Needs/website: ThinkR-open/thinkrtemplate
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Language: en-US
LazyData: true
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# fusen 0.5.2

## New features

- Allow a styler function with parameter `stylers` in `inflate_all*()` (e.g `inflate_all(stylers = styler::style_pkg)`)

## Minor changes

- Fix use of `packageVersion()` with character
- Allow "." for current package when adding flat file without DESCRIPTION (#224)

# fusen 0.5.1

## New features
Expand Down
18 changes: 11 additions & 7 deletions R/add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ add_dev_history <- function(pkg = ".",
)
}

flat_template_choices <- c(
"full",
"minimal_package", "minpkg",
"minimal_flat", "minflat", "add", "additional",
"teach", "teaching",
"dev_history", "dev"
)

create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")

#' Add flat Rmd file that drives package development
#'
#' @param template Name of the template to use. See details.
Expand Down Expand Up @@ -162,13 +172,7 @@ add_flat_template <- function(template = c("full", "minimal_package", "minimal_f
}

template <- template[1]
template <- match.arg(template, choices = c(
"full",
"minimal_package", "minpkg",
"minimal_flat", "minflat", "add", "additional",
"teach", "teaching",
"dev_history", "dev"
))
template <- match.arg(template, choices = flat_template_choices)

if (template %in% c("additional", "add")) {
template <- "additional"
Expand Down
2 changes: 1 addition & 1 deletion R/create_fusen_rsproject.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create_fusen <- function(path,
overwrite = FALSE,
with_git = FALSE) {
path <- normalizePath(path, mustWork = FALSE)
template <- match.arg(template)
template <- match.arg(template, choices = create_fusen_choices)

project_name <- get_pkg_name(pkg = path)
if (project_name != asciify_name(project_name, to_pkg = TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion R/inflate-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ get_pkg_name <- function(pkg) {
if (file.exists(desc)) {
pkgname <- read.dcf(desc)[colnames(read.dcf(desc)) == "Package"]
} else {
pkgname <- basename(pkg)
pkgname <- basename(normalizePath(pkg, mustWork = FALSE))
}
pkgname
}
Expand Down
37 changes: 26 additions & 11 deletions R/inflate_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param pkg Path to package
#' @param clean Logical. Whether to help detect unregistered files.
#' @param stylers Function to be run at the end of the process, like `styler::style_pkg` or `lintr::lint_package` or a lambda function combining functions like: `function() {styler::style_pkg(); lintr::lint_package()}`. For a unique function, use the format without parenthesis `()` at the end of the command.
#' @inheritParams inflate
#'
#' @importFrom yaml read_yaml
Expand Down Expand Up @@ -33,6 +34,8 @@
#' inflate_all()
#' # Or inflate_all_no_check() to prevent checks to run
#' inflate_all_no_check()
#' # Or inflate with the styler you want
#' inflate_all(stylers = styler::style_pkg)
#' }
#'
#' # You can also inflate_all flats of another package as follows
Expand Down Expand Up @@ -80,7 +83,7 @@
#'
#' # Clean the temporary directory
#' unlink(dummypackage, recursive = TRUE)
inflate_all <- function(pkg = ".", document = TRUE, check = TRUE, open_vignette = FALSE, overwrite = TRUE, clean = TRUE, ...) {
inflate_all <- function(pkg = ".", document = TRUE, check = TRUE, open_vignette = FALSE, overwrite = TRUE, clean = TRUE, stylers, ...) {
config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml")

if (!file.exists(config_file)) {
Expand Down Expand Up @@ -138,25 +141,37 @@ inflate_all <- function(pkg = ".", document = TRUE, check = TRUE, open_vignette
}

apply_inflate(inflate_params, pkg = pkg, overwrite = overwrite, open_vignette = open_vignette)

# Document and check package
document_and_check_pkg(
pkg = pkg,
check = check,
document = document,
...
)
}

if (isTRUE(clean)) {
cli::cat_rule("check not registered files")
invisible(check_not_registered_files(path = pkg))
}

if (!missing(stylers)) {
cli::cat_rule("Let's apply stylers to the package")
if (is.function(stylers)) {
stylers()
} else if (is.character(stylers)) {
eval(parse(text = stylers))
} else {
stylers
}
}

# Document and check package
document_and_check_pkg(
pkg = pkg,
check = check,
document = document,
...
)

invisible(pkg)
}

#' @rdname inflate_all
#' @export
inflate_all_no_check <- function(pkg = ".", document = TRUE, open_vignette = FALSE, overwrite = TRUE, clean = TRUE, ...) {
inflate_all(pkg = pkg, document = document, check = FALSE, open_vignette = open_vignette, overwrite = overwrite, clean = clean, ...)
inflate_all_no_check <- function(pkg = ".", document = TRUE, open_vignette = FALSE, overwrite = TRUE, clean = TRUE, stylers, ...) {
inflate_all(pkg = pkg, document = document, check = FALSE, open_vignette = open_vignette, overwrite = overwrite, clean = clean, stylers, ...)
}
8 changes: 4 additions & 4 deletions R/init_share_on_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#'
#' @param ask Logical. `TRUE` (default) to ask the user to apply the instructions each time needed,
#' or `FALSE` if the user already know what to do.
#'
#'
#' @details
#'
#'
#' `init_share_on_github()` runs multiple steps to be able to share a proper package on GitHub:
#'
#'
#' - Start versionning with git if not already
#' - Connect to your GitHub account
#' - Create a minimal DESCRIPTION file if missing
Expand All @@ -24,7 +24,7 @@
#' - Init continuous deployment (CD) of the {pkgdown} website documentation
#' - Commit and push to GitHub
#' - List remaining manual steps to make the website public
#'
#'
#' Read `vignette("share-on-a-github-website", package = "fusen")`
#'
#' @return The URL of the website created
Expand Down
5 changes: 3 additions & 2 deletions R/register_config_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,12 @@ df_to_config <- function(df_files,
all_exists <- file.exists(yaml_paths)
if (!all(all_exists)) {
msg <- paste(
"Some 'path' in config_file do not exist:",
"Some paths in config_file do not exist:",
paste(
yaml_paths[!all_exists],
collapse = ", "
)
), ".\n",
"Please open the configuration file: ", config_file, " to verify, and delete the non-existing files if needed."
)
if (isTRUE(force)) {
cli_alert_warning(
Expand Down
4 changes: 2 additions & 2 deletions dev/config_fusen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ flat_history_core.Rmd:
path: dev/flat_history_core.Rmd
state: inactive
R:
- R/add_dev_history.R
- R/fill_description.R
- R/inflate.R
tests:
- tests/testthat/test-add_dev_history.R
- tests/testthat/test-fill_description.R
- tests/testthat/test-inflate-part1.R
- tests/testthat/test-inflate-part2.R
Expand Down Expand Up @@ -101,6 +99,7 @@ flat_register_config_file.Rmd:
overwrite: 'yes'
keep:
path: keep
state: active
R:
- R/addins.R
- R/create_fusen_rsproject.R
Expand All @@ -110,6 +109,7 @@ keep:
- R/load_flat_functions.R
- R/utils-pipe.R
tests:
- tests/testthat/test-user-story.R
- tests/testthat/test-create_fusen_rsproject.R
- tests/testthat/test-inflate_qmd.R
- tests/testthat/test-inflate_utils.R
Expand Down
40 changes: 26 additions & 14 deletions dev/dev_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ my_desc$set_version("0.0.0.9000")
my_desc$set(Package = "fusen")
my_desc$set(Title = "Build A Package From Rmarkdown file")
my_desc$set(Description = "Use Rmd First method to build your package. Start your package with documentation. Everything can be set from a Rmarkdown file in your project.")
my_desc$set("Authors@R",
'c(
my_desc$set(
"Authors@R",
'c(
person("Sebastien", "Rochette", email = "sebastien@thinkr.fr", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1565-9313")),
person(given = "ThinkR", role = "cph")
)')
)'
)
my_desc$set("VignetteBuilder", "knitr")
my_desc$del("Maintainer")
my_desc$del("URL")
Expand Down Expand Up @@ -98,20 +100,27 @@ usethis::use_build_ignore("_pkgdown.yml")
fusen::inflate_all()
fusen::inflate_all(args = c("--no-manual", "--no-tests"))
fusen::inflate_all_no_check()
fusen::inflate_all_no_check(stylers = function() {
styler::style_pkg()
styler::style_dir("dev")
})

# Clean style ----
styler::style_pkg()
styler::style_file(list.files("dev", pattern = "[.](Rmd|qmd|rmd)$", full.names = TRUE)
)
styler::style_file(list.files("dev", pattern = "[.](Rmd|qmd|rmd)$", full.names = TRUE))

# Dependencies ----
# devtools::install_github("ThinkR-open/attachment")
# attachment::att_from_namespace()
attachment::att_amend_desc(
pkg_ignore = c("testthat", "dummypackage", "rstudioapi",
"knitr", "rmarkdown", "R6", "gert"),
extra.suggests = c("testthat", "pkgload", "rstudioapi",
"rmarkdown", "knitr", "gert"),
pkg_ignore = c(
"testthat", "dummypackage", "rstudioapi",
"knitr", "rmarkdown", "R6", "gert"
),
extra.suggests = c(
"testthat", "pkgload", "rstudioapi",
"rmarkdown", "knitr", "gert", "styler"
),
# "MASS", "lattice", "Matrix")
update.config = TRUE # attachment >= 0.4.0.
)
Expand Down Expand Up @@ -159,15 +168,18 @@ usethis::pr_finish(41)
# _Update template Rmd ----
skeleton_dir <- tempfile()
dir.create(skeleton_dir)
# When opening, verify that "skeleton" is written in the correct places
the_flat <- fusen::add_additional(
pkg = skeleton_dir,
dev_dir = "dev",
flat_name = "skeleton",
open = TRUE)
open = TRUE
)
file.copy(
the_flat,
here::here("inst/rmarkdown/templates/additional/skeleton/skeleton.Rmd"),
overwrite = TRUE)
overwrite = TRUE
)
unlink(skeleton_dir, recursive = TRUE)

# _Check in interactive test-inflate for templates and Addins ----
Expand All @@ -194,8 +206,8 @@ Sys.setenv("FUSEN_TEST_PUBLISH" = "FALSE")
# Run examples in interactive mode too
devtools::run_examples()

local <- utils::fileSnapshot (".", timestamp = tempfile("timestamp"), md5sum = TRUE)
home <- utils::fileSnapshot ("~", timestamp = tempfile("timestamp"), md5sum = TRUE)
local <- utils::fileSnapshot(".", timestamp = tempfile("timestamp"), md5sum = TRUE)
home <- utils::fileSnapshot("~", timestamp = tempfile("timestamp"), md5sum = TRUE)

# run tests or whatever, then ...
# x <- autotest::autotest_package(test = TRUE)
Expand All @@ -210,7 +222,7 @@ rcmdcheck::rcmdcheck(check_dir = dircheck)
the_dir <- list.files(file.path(dircheck), pattern = ".Rcheck", full.names = TRUE)
# Same tests, no new files
all(list.files(file.path(the_dir, "tests", "testthat")) %in%
list.files(file.path(".", "tests", "testthat")))
list.files(file.path(".", "tests", "testthat")))

devtools::build_vignettes()
devtools::clean_vignettes()
Expand Down
Loading

0 comments on commit 592095d

Please sign in to comment.