Skip to content

Commit

Permalink
Merge pull request #114 from b-rodrigues/fix_89
Browse files Browse the repository at this point in the history
Fix 89
  • Loading branch information
b-rodrigues authored Jan 27, 2024
2 parents 16a5d25 + f938e62 commit 047e238
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 12 deletions.
15 changes: 11 additions & 4 deletions R/find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ')
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down
55 changes: 48 additions & 7 deletions dev/flat_build_envs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ')
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -726,7 +733,6 @@ testthat::test_that("Snapshot test of rix()", {
rix(r_ver = "4.3.1",
r_pkgs = c("dplyr", "janitor", "[email protected]", "quarto"),
system_pkgs = c("quarto"),
tex_pkgs = c("amsmath"),
git_pkgs = list(
list(package_name = "housing",
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
})
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/_snaps/find_rev/no_quarto_default.nix
Original file line number Diff line number Diff line change
@@ -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";
}
22 changes: 22 additions & 0 deletions tests/testthat/_snaps/find_rev/yes_quarto_default.nix
Original file line number Diff line number Diff line change
@@ -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";
}
34 changes: 33 additions & 1 deletion tests/testthat/test-find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ testthat::test_that("Snapshot test of rix()", {

rix(r_ver = "4.3.1",
r_pkgs = c("dplyr", "janitor", "[email protected]", "quarto"),
system_pkgs = c("quarto"),
tex_pkgs = c("amsmath"),
git_pkgs = list(
list(package_name = "housing",
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 047e238

Please sign in to comment.