Skip to content

Commit

Permalink
Merge pull request #3259 from infotroph/treat-roxygen-as-dependency
Browse files Browse the repository at this point in the history
Treat roxygen as a dependency
  • Loading branch information
infotroph authored Feb 15, 2024
2 parents 43d9baf + 1dd96d0 commit 0fd1bb4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
3 changes: 1 addition & 2 deletions docker/depends/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ RUN apt-get update \
COPY pecan.depends.R pecan_package_dependencies.csv pecan_deps_from_github.txt /
RUN --mount=type=secret,id=github_token \
export GITHUB_PAT=`cat /run/secrets/github_token` \
&& Rscript -e "install.packages(c('devtools'))" \
&& Rscript -e "devtools::install_version('roxygen2', '7.2.3', repos = 'cran.r-project.org')" \
&& Rscript -e "install.packages(c('desc', 'remotes'))" \
&& R_LIBS_USER='/usr/local/lib/R/site-library' Rscript /pecan.depends.R \
&& rm -rf /tmp/*

25 changes: 17 additions & 8 deletions docker/depends/pecan.depends.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ condense_version_requirements <- function(specs) {
return("*")
}
specs <- unique(specs[specs != "*"])
if (any(!grepl(">", specs))) {
# we *could* write more to handle this case if needed, but it seems very rare:
# available.packages() shows `<=` or `==` deps in just 4 of 20297 CRAN packages
stop(
"pecan_depends only supports minimum versions (e.g. `>= 2.8.1`), ",
"not exact (`==`) or maximum versions (`<=`).",
"Problem seen in (", paste(dQuote(specs), collapse = ", "), ")")
}
versions <- package_version(
gsub("[^[:digit:].-]+", "", specs))

if ((length(unique(versions)) > 1) && any(!grepl(">", specs))) {
# Can't assume the latest version works for all, so give up.
# We *could* write more to handle this case if needed, but it seems very rare:
# available.packages() shows `<=` or `==` deps in just 4 of 20297 CRAN packages
#
# Since the package name wasn't passed in here, we unhelpfully print *just*
# the offending versions and send the user back to the CSV for details.
stop(
"Found multiple version requirements (",
paste(dQuote(specs), collapse = ", "), ") for the same dependency, ",
"and not all are minimum versions (e.g. `>= x.y.z`). ",
"Exact (`==`) or maximum (`<=`) version reuirements are only allowed ",
"if all PEcAn packages declare the same version. ",
"Sorry, this function doesn't know which dependency caused this. ",
"To find it, search for these version strings in ",
"'pecan_package_dependencies.csv'.")
}
specs[versions == max(versions)]
}

Expand Down
43 changes: 43 additions & 0 deletions docker/depends/pecan_package_dependencies.csv
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,49 @@
"rmarkdown",">= 2.19","modules/assim.batch","Suggests",FALSE
"rmarkdown",">= 2.19","modules/meta.analysis","Suggests",FALSE
"rmarkdown",">= 2.19","modules/photosynthesis","Suggests",FALSE
"roxygen2","== 7.2.3","base/all","Roxygen",FALSE
"roxygen2","== 7.2.3","base/db","Roxygen",FALSE
"roxygen2","== 7.2.3","base/logger","Roxygen",FALSE
"roxygen2","== 7.2.3","base/qaqc","Roxygen",FALSE
"roxygen2","== 7.2.3","base/remote","Roxygen",FALSE
"roxygen2","== 7.2.3","base/settings","Roxygen",FALSE
"roxygen2","== 7.2.3","base/utils","Roxygen",FALSE
"roxygen2","== 7.2.3","base/visualization","Roxygen",FALSE
"roxygen2","== 7.2.3","base/workflow","Roxygen",FALSE
"roxygen2","== 7.2.3","models/basgra","Roxygen",FALSE
"roxygen2","== 7.2.3","models/biocro","Roxygen",FALSE
"roxygen2","== 7.2.3","models/cable","Roxygen",FALSE
"roxygen2","== 7.2.3","models/clm45","Roxygen",FALSE
"roxygen2","== 7.2.3","models/dalec","Roxygen",FALSE
"roxygen2","== 7.2.3","models/dvmdostem","Roxygen",FALSE
"roxygen2","== 7.2.3","models/ed","Roxygen",FALSE
"roxygen2","== 7.2.3","models/fates","Roxygen",FALSE
"roxygen2","== 7.2.3","models/gday","Roxygen",FALSE
"roxygen2","== 7.2.3","models/jules","Roxygen",FALSE
"roxygen2","== 7.2.3","models/ldndc","Roxygen",FALSE
"roxygen2","== 7.2.3","models/linkages","Roxygen",FALSE
"roxygen2","== 7.2.3","models/lpjguess","Roxygen",FALSE
"roxygen2","== 7.2.3","models/maat","Roxygen",FALSE
"roxygen2","== 7.2.3","models/maespa","Roxygen",FALSE
"roxygen2","== 7.2.3","models/preles","Roxygen",FALSE
"roxygen2","== 7.2.3","models/sibcasa","Roxygen",FALSE
"roxygen2","== 7.2.3","models/sipnet","Roxygen",FALSE
"roxygen2","== 7.2.3","models/stics","Roxygen",FALSE
"roxygen2","== 7.2.3","models/template","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/allometry","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/assim.batch","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/assim.sequential","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/benchmark","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/data.atmosphere","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/data.hydrology","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/data.land","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/data.remote","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/emulator","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/meta.analysis","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/photosynthesis","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/priors","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/rtm","Roxygen",FALSE
"roxygen2","== 7.2.3","modules/uncertainty","Roxygen",FALSE
"RPostgres","*","base/db","Suggests",FALSE
"RPostgreSQL","*","base/db","Suggests",FALSE
"RPostgreSQL","*","models/biocro","Suggests",FALSE
Expand Down
2 changes: 1 addition & 1 deletion models/cable/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Copyright: Authors
LazyLoad: yes
LazyData: FALSE
Encoding: UTF-8
RoxygenNote: 6.1.0
RoxygenNote: 7.2.3
3 changes: 1 addition & 2 deletions models/cable/man/write_restart.CABLE.Rd

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

15 changes: 14 additions & 1 deletion scripts/generate_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ parse_desc <- function(path) {
package = d$get_field("Package"),
package_dir = dirname(path)),
remotes = remote_sources,
roxygen_version = d$get_field("RoxygenNote"),
deps = deps)
}

Expand Down Expand Up @@ -83,7 +84,19 @@ deps <- pkgs_parsed |>
# ignore R version requirements (e.g. "Depends: R (>= 3.2.0)")
dplyr::filter(package != "R") |>
dplyr::mutate(is_pecan = grepl("^PEcAn", package)) |>
dplyr::select(package, version, needed_by_dir, tidyselect::everything()) |>
dplyr::select(package, version, needed_by_dir, tidyselect::everything())

# Add Roxygen, used to build all packages but not declared as a dependency
roxy <- pkgs_parsed |>
purrr::map_dfr(
~c(needed_by_dir = .$mapping$package_dir, version = .$roxygen_version)) |>
dplyr::mutate(
package = "roxygen2",
version = paste("==", version),
type = "Roxygen",
is_pecan = FALSE)
deps <- deps |>
rbind(roxy) |>
dplyr::arrange(package, version, needed_by_dir, .locale = "en_US")

# Save these for use at install time
Expand Down

0 comments on commit 0fd1bb4

Please sign in to comment.