diff --git a/R/find_rev.R b/R/find_rev.R index 3f3c5156..8a06e1ca 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -461,7 +461,14 @@ tex_pkgs) } # system packages - get_system_pkgs <- function(system_pkgs){ + get_system_pkgs <- function(system_pkgs, r_pkgs){ + + system_pkgs <- if(any(grepl("quarto", r_pkgs))){ + unique(c(system_pkgs, "quarto")) + } else { + system_pkgs + } + paste(system_pkgs, collapse = ' ') } @@ -485,12 +492,12 @@ tex_pkgs) # `R` needs to be added. If we were using the rWrapper # this wouldn't be needed, but we're not so we need # to add it. - generate_system_pkgs <- function(system_pkgs){ + generate_system_pkgs <- function(system_pkgs, r_pkgs){ sprintf('system_packages = builtins.attrValues { inherit (pkgs) R glibcLocales %s; }; ', -get_system_pkgs(system_pkgs)) +get_system_pkgs(system_pkgs, r_pkgs)) } generate_locale_variables <- function() { @@ -571,7 +578,7 @@ flag_rpkgs generate_rpkgs(cran_pkgs$rPackages), generate_git_archived_packages(git_pkgs, cran_pkgs$archive_pkgs), generate_tex_pkgs(tex_pkgs), - generate_system_pkgs(system_pkgs), + generate_system_pkgs(system_pkgs, r_pkgs), generate_rstudio_pkgs(ide, flag_git_archive, flag_rpkgs), generate_shell(flag_git_archive, flag_rpkgs), collapse = "\n" diff --git a/dev/flat_build_envs.Rmd b/dev/flat_build_envs.Rmd index d529fab9..61905251 100644 --- a/dev/flat_build_envs.Rmd +++ b/dev/flat_build_envs.Rmd @@ -584,7 +584,14 @@ tex_pkgs) } # system packages - get_system_pkgs <- function(system_pkgs){ + get_system_pkgs <- function(system_pkgs, r_pkgs){ + + system_pkgs <- if(any(grepl("quarto", r_pkgs))){ + unique(c(system_pkgs, "quarto")) + } else { + system_pkgs + } + paste(system_pkgs, collapse = ' ') } @@ -608,12 +615,12 @@ tex_pkgs) # `R` needs to be added. If we were using the rWrapper # this wouldn't be needed, but we're not so we need # to add it. - generate_system_pkgs <- function(system_pkgs){ + generate_system_pkgs <- function(system_pkgs, r_pkgs){ sprintf('system_packages = builtins.attrValues { inherit (pkgs) R glibcLocales %s; }; ', -get_system_pkgs(system_pkgs)) +get_system_pkgs(system_pkgs, r_pkgs)) } generate_locale_variables <- function() { @@ -694,7 +701,7 @@ flag_rpkgs generate_rpkgs(cran_pkgs$rPackages), generate_git_archived_packages(git_pkgs, cran_pkgs$archive_pkgs), generate_tex_pkgs(tex_pkgs), - generate_system_pkgs(system_pkgs), + generate_system_pkgs(system_pkgs, r_pkgs), generate_rstudio_pkgs(ide, flag_git_archive, flag_rpkgs), generate_shell(flag_git_archive, flag_rpkgs), collapse = "\n" @@ -717,7 +724,7 @@ flag_rpkgs } ``` -```{r tests-rix} +```{r, tests-rix} testthat::test_that("Snapshot test of rix()", { save_default_nix_test <- function(ide) { @@ -726,7 +733,6 @@ testthat::test_that("Snapshot test of rix()", { rix(r_ver = "4.3.1", r_pkgs = c("dplyr", "janitor", "AER@1.2-8", "quarto"), - system_pkgs = c("quarto"), tex_pkgs = c("amsmath"), git_pkgs = list( list(package_name = "housing", @@ -771,6 +777,40 @@ testthat::test_that("Snapshot test of rix()", { ``` +```{r, tests-add_quarto_to_sys_pkgs} +testthat::test_that("Quarto gets added to sys packages", { + + save_default_nix_test <- function(pkgs) { + + path_default_nix <- tempdir() + + rix(r_ver = "4.3.1", + r_pkgs = pkgs, + ide = "other", + project_path = path_default_nix, + overwrite = TRUE) + + paste0(path_default_nix, "/default.nix") + + } + + testthat::announce_snapshot_file("find_rev/no_quarto_default.nix") + + testthat::expect_snapshot_file( + path = save_default_nix_test(pkgs = "dplyr"), + name = "no_quarto_default.nix", + ) + + testthat::announce_snapshot_file("find_rev/yes_quarto_default.nix") + + testthat::expect_snapshot_file( + path = save_default_nix_test(pkgs = c("dplyr", "quarto")), + name = "yes_quarto_default.nix" + ) + +}) + +``` This is a helper to create `./inst/extadata/default.nix`. @@ -2121,6 +2161,8 @@ testthat::test_that("Testing with_nix() if Nix is installed", { path_subshell <- file.path(".", "_env_R_3_5_3") + on.exit(unlink(path_subshell, recursive = TRUE, force = TRUE)) + rix_init( project_path = path_subshell, rprofile_action = "overwrite", @@ -2153,7 +2195,6 @@ testthat::test_that("Testing with_nix() if Nix is installed", { all(c(2, 6, 5, 8, 9) == out_subshell) ) - on.exit(unlink(path_subshell, recursive = TRUE, force = TRUE)) }) diff --git a/tests/testthat/_snaps/find_rev/no_quarto_default.nix b/tests/testthat/_snaps/find_rev/no_quarto_default.nix new file mode 100644 index 00000000..3e1552fb --- /dev/null +++ b/tests/testthat/_snaps/find_rev/no_quarto_default.nix @@ -0,0 +1,22 @@ + +let + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; + rpkgs = builtins.attrValues { + inherit (pkgs.rPackages) dplyr; +}; + system_packages = builtins.attrValues { + inherit (pkgs) R glibcLocales ; +}; + in + pkgs.mkShell { + LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else ""; + LANG = "en_US.UTF-8"; + LC_ALL = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + + buildInputs = [ rpkgs system_packages ]; + shellHook = "R --vanilla"; + } diff --git a/tests/testthat/_snaps/find_rev/yes_quarto_default.nix b/tests/testthat/_snaps/find_rev/yes_quarto_default.nix new file mode 100644 index 00000000..17acbd36 --- /dev/null +++ b/tests/testthat/_snaps/find_rev/yes_quarto_default.nix @@ -0,0 +1,22 @@ + +let + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; + rpkgs = builtins.attrValues { + inherit (pkgs.rPackages) dplyr quarto; +}; + system_packages = builtins.attrValues { + inherit (pkgs) R glibcLocales quarto; +}; + in + pkgs.mkShell { + LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else ""; + LANG = "en_US.UTF-8"; + LC_ALL = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + + buildInputs = [ rpkgs system_packages ]; + shellHook = "R --vanilla"; + } diff --git a/tests/testthat/test-find_rev.R b/tests/testthat/test-find_rev.R index cc22fbaf..cdcdf43b 100644 --- a/tests/testthat/test-find_rev.R +++ b/tests/testthat/test-find_rev.R @@ -64,7 +64,6 @@ testthat::test_that("Snapshot test of rix()", { rix(r_ver = "4.3.1", r_pkgs = c("dplyr", "janitor", "AER@1.2-8", "quarto"), - system_pkgs = c("quarto"), tex_pkgs = c("amsmath"), git_pkgs = list( list(package_name = "housing", @@ -108,6 +107,39 @@ testthat::test_that("Snapshot test of rix()", { }) +testthat::test_that("Quarto gets added to sys packages", { + + save_default_nix_test <- function(pkgs) { + + path_default_nix <- tempdir() + + rix(r_ver = "4.3.1", + r_pkgs = pkgs, + ide = "other", + project_path = path_default_nix, + overwrite = TRUE) + + paste0(path_default_nix, "/default.nix") + + } + + testthat::announce_snapshot_file("find_rev/no_quarto_default.nix") + + testthat::expect_snapshot_file( + path = save_default_nix_test(pkgs = "dplyr"), + name = "no_quarto_default.nix", + ) + + testthat::announce_snapshot_file("find_rev/yes_quarto_default.nix") + + testthat::expect_snapshot_file( + path = save_default_nix_test(pkgs = c("dplyr", "quarto")), + name = "yes_quarto_default.nix" + ) + +}) + + testthat::test_that("Snapshot test of rix_init()", { skip_on_covr()