Skip to content

Commit

Permalink
Merge branch 'develop' into basgra-yasso-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
istfer authored Mar 8, 2024
2 parents 38b8890 + 4564337 commit 7056a5d
Show file tree
Hide file tree
Showing 85 changed files with 827 additions and 684 deletions.
57 changes: 57 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# Add project labels
#

# Add 'Documentation' label to any changes in the documentation

'Documentation':
- book_source/**
- documentation/**
- CONTRIBUTING.md
- DEBUGING.md
- DEV-INTRO.md
- README.md

# Add 'Dockerfile' label to any changes in the docker directory
'Dockerfile':
- docker/**


# Add 'Website' label to any changes in the web directory

'Website':
- web/**

# Add 'Base' label to any changes in the base directory

'Base':
- base/**

# Add 'Models' label to any changes in the models directory

'Models':
- models/**

# Add 'Modules' label to any changes in the modules directory

'Modules':
- modules/**

# Add 'GitHub Actions' label to any changes in the .github/workflows directory

'GitHub Actions':
- .github/workflows/**

# Add 'Scripts' label to any changes in the scripts directory

'Scripts':
- scripts/**

# Add 'Tests' label to any changes in the tests directory

'Tests':
- tests/**
- '**/tests/**'
- '!**/tests/Rcheck_reference.log'


30 changes: 30 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#Define the colour of labels over here

labels:

- name: "Documentation"
color: a2dcf2

- name: "Dockerfile"
color: 0052CC

- name: "Website"
color: 84b6eb

- name: "Base"
color: 1ED626

- name: "Models"
color: C5DEF5

- name: "Modules"
color: FBCA04

- name: "GitHub Actions"
color: 84b6eb

- name: "Scripts"
color: 3B8924

- name: "Tests"
color: ff8c00
22 changes: 22 additions & 0 deletions .github/workflows/prlabeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This workflow is based on github action official label action v4.
# This workflow action is triggered on pull request event(on both fork & inside repo)
# Labels will be applied based on filepath modification in PR.
# This workflow uses a regex based labeling config file(.github/labeler.yml) to take labeling decision.

name: "PR Labeler"
on:
- pull_request_target
jobs:
label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest

steps:
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: ".github/labeler.yml"
sync-labels: false
dot: true
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ clean:
+ ./scripts/time.sh "roxygen2 ${1}" Rscript -e ${SETROPTIONS} \
-e "if (!requireNamespace('roxygen2', quietly = TRUE)" \
-e " || packageVersion('roxygen2') != '7.2.3') {" \
-e " devtools::install_github('r-lib/[email protected]')" \
-e " cran <- c(getOption('repos'), 'cloud.r-project.org')" \
-e " remotes::install_version('roxygen2', '7.2.3', repos = cran, upgrade = FALSE)" \
-e "}"
$(eval INSTALLED_ROXYGEN_VERSION := 7.2.3)
echo `date` > $@
Expand Down
2 changes: 1 addition & 1 deletion Makefile.depends
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(call depends,models/template): | .install/base/db .install/base/logger .instal
$(call depends,modules/allometry): | .install/base/db
$(call depends,modules/assim.batch): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils .install/base/workflow .install/modules/benchmark .install/modules/emulator .install/modules/meta.analysis .install/modules/uncertainty
$(call depends,modules/assim.sequential): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils .install/base/visualization .install/base/workflow .install/modules/benchmark .install/modules/data.land .install/modules/data.remote .install/modules/uncertainty
$(call depends,modules/benchmark): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils .install/modules/data.land
$(call depends,modules/benchmark): | .install/base/db .install/base/logger .install/base/settings .install/base/utils .install/modules/data.land
$(call depends,modules/data.atmosphere): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils
$(call depends,modules/data.hydrology): | .install/base/logger .install/base/utils
$(call depends,modules/data.land): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils .install/base/visualization .install/modules/benchmark .install/modules/data.atmosphere
Expand Down
2 changes: 2 additions & 0 deletions base/all/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ Depends:
Imports:
utils
Suggests:
mockery,
PEcAn.ED2,
PEcAn.SIPNET,
PEcAn.BIOCRO,
PEcAn.DALEC,
PEcAn.LINKAGES,
PEcAn.allometry,
PEcAn.photosynthesis,
sessioninfo,
testthat
License: BSD_3_clause + file LICENSE
Copyright: Authors
Expand Down
79 changes: 56 additions & 23 deletions base/all/R/pecan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
#' locations in `.libPaths()`, or if you've loaded a new version into your
#' current session by loading it from its source directory without installing
#' it to the R library.
#' If you see multiple rows unexpectedly, try `find.package(<pkgname>, verbose = TRUE)` to see where each version was found.
#' If you see multiple rows unexpectedly, try
#' `find.package(<pkgname>, verbose = TRUE)` to see where each version was found.
#'
#' @param version PEcAn release number to use for expected package versions
#' @param exact Show only tags that exactly match `version`,
#' or all tags that have it as a substring?
#' @return data frame with columns for package name, expected version(s),
#' and installed version
#' and installed version.
#' If the `sessioninfo` package is installed, a fourth column reports where
#' each package was installed from: local, github, CRAN, etc.
#'
#' @examples
#' pecan_version()
Expand All @@ -35,25 +38,6 @@
#' @export
pecan_version <- function(version = max(PEcAn.all::pecan_releases$version),
exact = FALSE) {
all_pkgs <- as.data.frame(utils::installed.packages())
our_pkgs <- all_pkgs[
grepl("PEcAn", all_pkgs$Package),
c("Package", "Version")
]
colnames(our_pkgs) <- c("package", "installed")
our_pkgs$installed <- package_version(our_pkgs$installed)

# Check in currently loaded packages too,
# add rows for any that differ from installed versions
sess <- utils::sessionInfo()
sess <- c(sess$otherPkgs, sess$loadedOnly)
our_loaded <- sess[grepl("PEcAn", names(sess))]
our_loaded <- data.frame(
package = names(our_loaded),
installed = sapply(our_loaded, `[[`, "Version"))
our_loaded$installed <- package_version(our_loaded$installed)
our_pkgs <- merge(our_pkgs, our_loaded, all = TRUE)

if (!exact) {
version <- sapply(
X = version,
Expand All @@ -62,9 +46,58 @@ pecan_version <- function(version = max(PEcAn.all::pecan_releases$version),
)
version <- unique(unlist(version))
}
cols_to_return <- c("package", version, "installed")


if (requireNamespace("sessioninfo", quietly = TRUE)) {
cols_to_return <- c(cols_to_return, "source")

all_pkgs <- sessioninfo::package_info(pkgs = "installed", dependencies = FALSE)
our_pkgs <- all_pkgs[grepl("PEcAn", all_pkgs$package),]

all_loaded <- sessioninfo::package_info(pkgs = "loaded", dependencies = FALSE)
our_loaded <- all_loaded[grepl("PEcAn", all_loaded$package),]

unloaded <- our_pkgs[!our_pkgs$package %in% our_loaded$package,]
our_pkgs <- rbind(our_loaded, unloaded)
our_pkgs <- our_pkgs[order(our_pkgs$package),]


# TODO: consider using package_info's callouts of packages where loaded and
# installed versions mismatch -- it's a more elegant version of what we
# were trying for with the "multiple rows for packages with multiple
# versions found" behavior.
our_pkgs$installed <- ifelse(
test = is.na(our_pkgs$loadedversion),
yes = our_pkgs$ondiskversion,
no = our_pkgs$loadedversion)
our_pkgs <- our_pkgs[, c("package", "installed", "source")]
our_pkgs$installed <- package_version(our_pkgs$installed)

} else {
all_pkgs <- as.data.frame(utils::installed.packages())
our_pkgs <- all_pkgs[
grepl("PEcAn", all_pkgs$Package),
c("Package", "Version")
]
colnames(our_pkgs) <- c("package", "installed")
our_pkgs$installed <- package_version(our_pkgs$installed)
sess <- utils::sessionInfo()
sess <- c(sess$otherPkgs, sess$loadedOnly)
our_loaded <- sess[grepl("PEcAn", names(sess))]
our_loaded <- data.frame(
package = names(our_loaded),
installed = sapply(our_loaded, `[[`, "Version"))
our_loaded$installed <- package_version(our_loaded$installed)
our_pkgs <- merge(our_pkgs, our_loaded, all = TRUE)
}


res <- merge(our_pkgs, PEcAn.all::pecan_version_history, all = TRUE)
res <- res[, c("package", version, "installed")]
res <- merge(
x = our_pkgs,
y = PEcAn.all::pecan_version_history,
all = TRUE)
res <- res[, cols_to_return]

drop_na_version_rows(res)
}
Expand Down
7 changes: 5 additions & 2 deletions base/all/man/pecan_version.Rd

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

32 changes: 28 additions & 4 deletions base/all/tests/testthat/test-pecan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ test_that("pecan_version", {
# tags substring matched only when exact = FALSE
expect_named(
pecan_version("v1.5"),
c("package", paste0("v1.5.", 0:3), "installed")
c("package", paste0("v1.5.", 0:3), "installed", "source")
)
expect_error(
pecan_version("v1.5", exact = TRUE),
"undefined columns"
)
expect_named(
pecan_version("v1.3", exact = TRUE),
c("package", "v1.3", "installed")
c("package", "v1.3", "installed", "source")
)

# returns current release if no args given
noargs <- pecan_version()
expected_tag <- tail(PEcAn.all::pecan_releases, 1)$tag
expect_length(noargs, 3)
expect_named(noargs, c("package", expected_tag, "installed"))
expect_length(noargs, 4)
expect_named(noargs, c("package", expected_tag, "installed", "source"))

# Why the `any()`s below?
# Because R CMD check runs tests with local test dir added to .libPaths,
Expand All @@ -67,3 +67,27 @@ test_that("pecan_version", {
)
)
})


test_that("pecan_version without sessioninfo", {

with_sessinfo <- pecan_version()

# make pecan_version think the sessioninfo package is unavailable
mockery::stub(pecan_version, 'requireNamespace', FALSE)
without_sessinfo <- pecan_version()

expect_length(with_sessinfo, 4)
expect_length(without_sessinfo, 3)
expect_equal(
with_sessinfo[, colnames(with_sessinfo) != "source"],
without_sessinfo)
})

# TODO: Would be nice to add a check here that will notice if the list of PEcAn
# releases falls out of date, but it's not clear what other source of truth
# to consult to determine that.
#
# The approach that failed just before I wrote this note:
# No, the version of PEcAn.all (1.8.1.9000 today) is not reliably in sync with
# the PEcAn version last tagged as a release (1.7.2 today).
27 changes: 14 additions & 13 deletions base/workflow/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ Description: The Predictive Ecosystem Carbon Analyzer
that can be used to run the major steps of a PEcAn analysis.
License: BSD_3_clause + file LICENSE
Imports:
dplyr,
PEcAn.data.atmosphere,
PEcAn.data.land,
PEcAn.DB,
PEcAn.logger,
PEcAn.remote,
PEcAn.settings,
PEcAn.uncertainty,
PEcAn.utils,
purrr (>= 0.2.3),
XML
dplyr,
PEcAn.data.atmosphere,
PEcAn.data.land,
PEcAn.DB,
PEcAn.logger,
PEcAn.remote,
PEcAn.settings,
PEcAn.uncertainty,
PEcAn.utils,
purrr (>= 0.2.3),
XML
Suggests:
testthat,
mockery
mockery,
testthat,
withr
Copyright: Authors
Encoding: UTF-8
RoxygenNote: 7.2.3
2 changes: 1 addition & 1 deletion base/workflow/R/start_model_runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ start_model_runs <- function(settings, write = TRUE, stop.on.error = TRUE) {

run_file <- file.path(settings$rundir, "runs.txt")
# check if runs need to be done
if (!file.exists(file.path(settings$rundir, "runs.txt"))) {
if (!file.exists(run_file)) {
PEcAn.logger::logger.warn(
"runs.txt not found, assuming no runs need to be done")
return()
Expand Down
20 changes: 20 additions & 0 deletions base/workflow/tests/testthat/test.start_model_runs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("`start_model_runs` throws a warning if runs.txt not provided", {
withr::with_tempdir({
PEcAn.logger::logger.setUseConsole(TRUE, FALSE)
on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE))
settings <- list(rundir = getwd())
expect_output(start_model_runs(settings), "runs.txt not found")
})
})

test_that("`start_model_runs` throws a warning if runs.txt is empty", {
withr::with_tempdir({
PEcAn.logger::logger.setUseConsole(TRUE, FALSE)
on.exit(PEcAn.logger::logger.setUseConsole(TRUE, TRUE))
settings <- list(rundir = getwd())
file_path <- file.path(getwd(), "runs.txt")
file.create(file_path)
expect_output(start_model_runs(settings), "runs.txt found, but is empty")
})
})

Loading

0 comments on commit 7056a5d

Please sign in to comment.