From ce05505588cfd37f6f447ddc2cde626ca0191e59 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Sat, 3 Aug 2024 01:10:19 -0700 Subject: [PATCH 01/13] add record of Git commit at package build time --- Makefile | 7 ++++++- base/all/R/version.R | 3 +++ base/db/R/version.R | 3 +++ base/logger/R/version.R | 3 +++ base/qaqc/R/version.R | 3 +++ base/remote/R/version.R | 3 +++ base/settings/R/version.R | 3 +++ base/utils/R/version.R | 3 +++ base/visualization/R/version.R | 3 +++ base/workflow/R/version.R | 3 +++ models/basgra/R/version.R | 3 +++ models/biocro/R/version.R | 3 +++ models/clm45/R/version.R | 3 +++ models/dalec/R/version.R | 3 +++ models/dvmdostem/R/version.R | 3 +++ models/ed/R/version.R | 3 +++ models/fates/R/version.R | 3 +++ models/gday/R/version.R | 3 +++ models/jules/R/version.R | 3 +++ models/ldndc/R/version.R | 3 +++ models/linkages/R/version.R | 3 +++ models/lpjguess/R/version.R | 3 +++ models/maat/R/version.R | 3 +++ models/maespa/R/version.R | 3 +++ models/preles/R/version.R | 3 +++ models/sibcasa/R/version.R | 3 +++ models/sipnet/R/version.R | 3 +++ models/stics/R/version.R | 3 +++ models/template/R/version.R | 3 +++ modules/allometry/R/version.R | 3 +++ modules/assim.batch/R/version.R | 3 +++ modules/assim.sequential/R/version.R | 3 +++ modules/benchmark/R/version.R | 3 +++ modules/data.atmosphere/R/version.R | 3 +++ modules/data.land/R/version.R | 3 +++ modules/data.remote/R/version.R | 3 +++ modules/emulator/R/version.R | 3 +++ modules/meta.analysis/R/version.R | 3 +++ modules/photosynthesis/DESCRIPTION | 4 ---- modules/photosynthesis/R/version.R | 3 +++ modules/priors/R/version.R | 3 +++ modules/rtm/R/version.R | 3 +++ modules/uncertainty/R/version.R | 3 +++ 43 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 base/all/R/version.R create mode 100644 base/db/R/version.R create mode 100644 base/logger/R/version.R create mode 100644 base/qaqc/R/version.R create mode 100644 base/remote/R/version.R create mode 100644 base/settings/R/version.R create mode 100644 base/utils/R/version.R create mode 100644 base/visualization/R/version.R create mode 100644 base/workflow/R/version.R create mode 100644 models/basgra/R/version.R create mode 100644 models/biocro/R/version.R create mode 100644 models/clm45/R/version.R create mode 100644 models/dalec/R/version.R create mode 100644 models/dvmdostem/R/version.R create mode 100644 models/ed/R/version.R create mode 100644 models/fates/R/version.R create mode 100644 models/gday/R/version.R create mode 100644 models/jules/R/version.R create mode 100644 models/ldndc/R/version.R create mode 100644 models/linkages/R/version.R create mode 100644 models/lpjguess/R/version.R create mode 100644 models/maat/R/version.R create mode 100644 models/maespa/R/version.R create mode 100644 models/preles/R/version.R create mode 100644 models/sibcasa/R/version.R create mode 100644 models/sipnet/R/version.R create mode 100644 models/stics/R/version.R create mode 100644 models/template/R/version.R create mode 100644 modules/allometry/R/version.R create mode 100644 modules/assim.batch/R/version.R create mode 100644 modules/assim.sequential/R/version.R create mode 100644 modules/benchmark/R/version.R create mode 100644 modules/data.atmosphere/R/version.R create mode 100644 modules/data.land/R/version.R create mode 100644 modules/data.remote/R/version.R create mode 100644 modules/emulator/R/version.R create mode 100644 modules/meta.analysis/R/version.R create mode 100644 modules/photosynthesis/R/version.R create mode 100644 modules/priors/R/version.R create mode 100644 modules/rtm/R/version.R create mode 100644 modules/uncertainty/R/version.R diff --git a/Makefile b/Makefile index 4160b751007..3f16a4af5b8 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,17 @@ drop_parents = $(filter-out $(patsubst %/,%,$(dir $1)), $1) # Generates a list of regular files at any depth inside its argument files_in_dir = $(call drop_parents, $(call recurse_dir, $1)) +# Git hash + clean status for this directory +git_rev = $(shell \ + CLEAN=$$(if [[ -n $$(git status -s $1) ]]; then echo "modified from "; fi); \ + echo "$$CLEAN"$$(git rev-parse --short=10 HEAD)) + # HACK: NA vs TRUE switch on dependencies argument is an ugly workaround for # a circular dependency between benchmark and data.land. # When this is fixed, can go back to simple `dependencies = TRUE` depends_R_pkg = ./scripts/time.sh "depends ${1}" ./scripts/confirm_deps.R ${1} \ $(if $(findstring modules/benchmark,$(1)),NA,TRUE) -install_R_pkg = ./scripts/time.sh "install ${1}" Rscript \ +install_R_pkg = PECAN_GIT_REV="$(call git_rev,$1)" ./scripts/time.sh "install ${1}" Rscript \ -e ${SETROPTIONS} \ -e "remotes::install_local('$(strip $(1))', force=TRUE, dependencies=FALSE, upgrade=FALSE)" check_R_pkg = ./scripts/time.sh "check ${1}" Rscript scripts/check_with_errors.R $(strip $(1)) diff --git a/base/all/R/version.R b/base/all/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/all/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/db/R/version.R b/base/db/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/db/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/logger/R/version.R b/base/logger/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/logger/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/qaqc/R/version.R b/base/qaqc/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/qaqc/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/remote/R/version.R b/base/remote/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/remote/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/settings/R/version.R b/base/settings/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/settings/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/utils/R/version.R b/base/utils/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/utils/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/visualization/R/version.R b/base/visualization/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/visualization/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/workflow/R/version.R b/base/workflow/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/base/workflow/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/basgra/R/version.R b/models/basgra/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/basgra/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/biocro/R/version.R b/models/biocro/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/biocro/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/clm45/R/version.R b/models/clm45/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/clm45/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/dalec/R/version.R b/models/dalec/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/dalec/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/dvmdostem/R/version.R b/models/dvmdostem/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/dvmdostem/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/ed/R/version.R b/models/ed/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/ed/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/fates/R/version.R b/models/fates/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/fates/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/gday/R/version.R b/models/gday/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/gday/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/jules/R/version.R b/models/jules/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/jules/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/ldndc/R/version.R b/models/ldndc/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/ldndc/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/linkages/R/version.R b/models/linkages/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/linkages/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/lpjguess/R/version.R b/models/lpjguess/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/lpjguess/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/maat/R/version.R b/models/maat/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/maat/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/maespa/R/version.R b/models/maespa/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/maespa/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/preles/R/version.R b/models/preles/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/preles/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/sibcasa/R/version.R b/models/sibcasa/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/sibcasa/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/sipnet/R/version.R b/models/sipnet/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/sipnet/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/stics/R/version.R b/models/stics/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/stics/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/template/R/version.R b/models/template/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/models/template/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/allometry/R/version.R b/modules/allometry/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/allometry/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/assim.batch/R/version.R b/modules/assim.batch/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/assim.batch/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/assim.sequential/R/version.R b/modules/assim.sequential/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/assim.sequential/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/benchmark/R/version.R b/modules/benchmark/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/benchmark/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.atmosphere/R/version.R b/modules/data.atmosphere/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/data.atmosphere/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.land/R/version.R b/modules/data.land/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/data.land/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.remote/R/version.R b/modules/data.remote/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/data.remote/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/emulator/R/version.R b/modules/emulator/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/emulator/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/meta.analysis/R/version.R b/modules/meta.analysis/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/meta.analysis/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/photosynthesis/DESCRIPTION b/modules/photosynthesis/DESCRIPTION index 2605358e806..e872f23b10f 100644 --- a/modules/photosynthesis/DESCRIPTION +++ b/modules/photosynthesis/DESCRIPTION @@ -34,10 +34,6 @@ License: BSD_3_clause + file LICENSE Copyright: Authors LazyLoad: yes LazyData: FALSE -Collate: - fitA.R - Licor.QC.R - plots.R Encoding: UTF-8 RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/modules/photosynthesis/R/version.R b/modules/photosynthesis/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/photosynthesis/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/priors/R/version.R b/modules/priors/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/priors/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/rtm/R/version.R b/modules/rtm/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/rtm/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/uncertainty/R/version.R b/modules/uncertainty/R/version.R new file mode 100644 index 00000000000..660621ff760 --- /dev/null +++ b/modules/uncertainty/R/version.R @@ -0,0 +1,3 @@ +# Set at package build time, used by pecan.all::pecan_version() +# to identify development versions of packages +.build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") From 8fb20616536e7395f5eb9d8d5d78fc0df2e375ae Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Aug 2024 14:06:18 -0700 Subject: [PATCH 02/13] more compact indicator of modified tree --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3f16a4af5b8..aa80046ae6f 100644 --- a/Makefile +++ b/Makefile @@ -69,8 +69,8 @@ files_in_dir = $(call drop_parents, $(call recurse_dir, $1)) # Git hash + clean status for this directory git_rev = $(shell \ - CLEAN=$$(if [[ -n $$(git status -s $1) ]]; then echo "modified from "; fi); \ - echo "$$CLEAN"$$(git rev-parse --short=10 HEAD)) + CLEAN=$$([[ -n $$(git status -s $1) ]] && echo "+mods"); \ + echo $$(git rev-parse --short=10 HEAD)"$$CLEAN") # HACK: NA vs TRUE switch on dependencies argument is an ugly workaround for # a circular dependency between benchmark and data.land. From 6e771f99a72a503dba20c77afb3f3f23be872454 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Aug 2024 14:09:02 -0700 Subject: [PATCH 03/13] include hash in version report (including nicer print nethod) --- base/all/NAMESPACE | 1 + base/all/R/pecan_version.R | 40 +++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/base/all/NAMESPACE b/base/all/NAMESPACE index a7e08575d38..150394015c9 100644 --- a/base/all/NAMESPACE +++ b/base/all/NAMESPACE @@ -1,3 +1,4 @@ # Generated by roxygen2: do not edit by hand +S3method(print,pecan_version_report) export(pecan_version) diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 4563a4cfdfd..123dab2042b 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -46,7 +46,7 @@ pecan_version <- function(version = max(PEcAn.all::pecan_releases$version), ) version <- unique(unlist(version)) } - cols_to_return <- c("package", version, "installed") + cols_to_return <- c("package", version, "installed", "build_hash") if (requireNamespace("sessioninfo", quietly = TRUE)) { @@ -94,14 +94,16 @@ pecan_version <- function(version = max(PEcAn.all::pecan_releases$version), our_pkgs <- our_pkgs[!duplicated(our_pkgs),] } + our_pkgs$build_hash <- sapply(our_pkgs$package, get_buildhash) res <- merge( x = our_pkgs, y = PEcAn.all::pecan_version_history, all = TRUE) - res <- res[, cols_to_return] + res <- drop_na_version_rows(res[, cols_to_return]) + class(res) <- c("pecan_version_report", class(res)) - drop_na_version_rows(res) + res } # Remove rows where all versions are missing @@ -110,3 +112,35 @@ drop_na_version_rows <- function(df) { stopifnot(colnames(df)[[1]] == "package") df[rowSums(is.na(df[, -1])) < ncol(df[, -1]), ] } + + +# Look up git revision, if recorded, from an installed PEcAn package +get_buildhash <- function(pkg) { + if (!length(find.package(pkg))) { + return(NA_character_) + } + # Set if installed from r-universe or via install_github() + desc_sha <- packageDescription(pkg)$RemoteSha + if (!is.null(desc_sha)) { + return(substr(desc_sha, 1, 10)) + } + # Set if PECAN_GIT_REV was set during install (includes `make install`) + get0(".build_hash", envir = asNamespace(pkg), ifnotfound = NA_character_) +} + + +# print method for version +# (Just to help it display more compactly) +#' @export +print.pecan_version_report <- function(x, ...) { + xx <- as.data.frame(x) + xx$build_hash[is.na(xx$build_hash)] <- "" + xx$installed <- paste0( + xx$installed, + sub("(.+)", " (\\1)", xx$build_hash)) + xx$build_hash <- NULL + if (!is.null(xx$source)) { + xx$source <- paste0(substr(xx$source, 1, 17), "...") + } + print(xx) +} From 1d202ce36cfc52d36655ad751ae4a885a3e372c9 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Aug 2024 15:58:07 -0700 Subject: [PATCH 04/13] update tests for new column --- base/all/tests/testthat/test-pecan_version.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/all/tests/testthat/test-pecan_version.R b/base/all/tests/testthat/test-pecan_version.R index c1e45b0c267..fc1d147c575 100644 --- a/base/all/tests/testthat/test-pecan_version.R +++ b/base/all/tests/testthat/test-pecan_version.R @@ -26,7 +26,7 @@ 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", "source") + c("package", paste0("v1.5.", 0:3), "installed", "build_hash", "source") ) expect_error( pecan_version("v1.5", exact = TRUE), @@ -34,14 +34,14 @@ test_that("pecan_version", { ) expect_named( pecan_version("v1.3", exact = TRUE), - c("package", "v1.3", "installed", "source") + c("package", "v1.3", "installed", "build_hash", "source") ) # returns current release if no args given noargs <- pecan_version() expected_tag <- tail(PEcAn.all::pecan_releases, 1)$tag - expect_length(noargs, 4) - expect_named(noargs, c("package", expected_tag, "installed", "source")) + expect_length(noargs, 5) + expect_named(noargs, c("package", expected_tag, "installed", "build_hash", "source")) # Why the `any()`s below? # Because R CMD check runs tests with local test dir added to .libPaths, @@ -77,8 +77,8 @@ test_that("pecan_version without sessioninfo", { mockery::stub(pecan_version, 'requireNamespace', FALSE) without_sessinfo <- pecan_version() - expect_length(with_sessinfo, 4) - expect_length(without_sessinfo, 3) + expect_length(with_sessinfo, 5) + expect_length(without_sessinfo, 4) expect_equal( with_sessinfo[, colnames(with_sessinfo) != "source"], without_sessinfo) From fb7ec70b7e9a29c4d98412be12a80ea688202fcf Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Aug 2024 16:34:02 -0700 Subject: [PATCH 05/13] avoid unintended data --- base/all/data/pecan_version_history.R | 52 ++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/base/all/data/pecan_version_history.R b/base/all/data/pecan_version_history.R index 5e30bcb3460..efff2cdf1ac 100644 --- a/base/all/data/pecan_version_history.R +++ b/base/all/data/pecan_version_history.R @@ -1,30 +1,34 @@ +# Read and format a list of pecan versions -pecan_version_history <- utils::read.csv( - "pecan_version_history.csv", - colClasses = "character", - check.names = FALSE) +# The local() wrapper is to avoid adding objects to the package data: +# Any extra vars defined at the top level of this file would be loaded +# into the global environment by `data("pecan_version_history")` -# We'd like to parse strictly to catch invalid versions (probably typos). -# But we _need_ to allow NAs... and in R < 4.4, package_version did not -# accept NAs unless strict=FALSE. -strict <- TRUE -na_version <- try( - package_version(NA_character_, strict = strict), - silent = TRUE) -if (inherits(na_version, "try-error")) { - strict <- FALSE -} +pecan_version_history <- local({ + pvh <- utils::read.csv( + "pecan_version_history.csv", + colClasses = "character", + check.names = FALSE) -for (col in colnames(pecan_version_history)) { - if (col != "package") { - pecan_version_history[[col]] <- package_version( - pecan_version_history[[col]], - strict = strict) + # We'd like to parse strictly to catch invalid versions (probably typos). + # But we _need_ to allow NAs... and in R < 4.4, package_version did not + # accept NAs unless strict=FALSE. + strict <- TRUE + na_version <- try( + package_version(NA_character_, strict = strict), + silent = TRUE) + if (inherits(na_version, "try-error")) { + strict <- FALSE } -} -# Now remove local vars -# Yes, this really is needed: _all_ objects left defined at end of script -# will be added to the package data list! -rm(strict, na_version, col) + for (col in colnames(pvh)) { + if (col != "package") { + pvh[[col]] <- package_version( + pvh[[col]], + strict = strict) + } + } + + pvh +}) From 824846134600f01179b8c81c3ae3451025b6127c Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Aug 2024 17:20:36 -0700 Subject: [PATCH 06/13] speedups On my machine this drops from ~3-4 sec for first call and ~2 after, to ~2 sec for first call and ~1 after. No longer feels "too slow" to me. --- base/all/R/pecan_version.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 123dab2042b..6c0be5e522c 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -94,7 +94,10 @@ pecan_version <- function(version = max(PEcAn.all::pecan_releases$version), our_pkgs <- our_pkgs[!duplicated(our_pkgs),] } - our_pkgs$build_hash <- sapply(our_pkgs$package, get_buildhash) + want_hash <- !is.na(our_pkgs$installed) + our_pkgs$build_hash[want_hash] <- sapply( + our_pkgs$package[want_hash], + get_buildhash) res <- merge( x = our_pkgs, @@ -116,12 +119,9 @@ drop_na_version_rows <- function(df) { # Look up git revision, if recorded, from an installed PEcAn package get_buildhash <- function(pkg) { - if (!length(find.package(pkg))) { - return(NA_character_) - } # Set if installed from r-universe or via install_github() - desc_sha <- packageDescription(pkg)$RemoteSha - if (!is.null(desc_sha)) { + desc_sha <- utils::packageDescription(pkg, fields = "RemoteSha") + if (!is.na(desc_sha)) { return(substr(desc_sha, 1, 10)) } # Set if PECAN_GIT_REV was set during install (includes `make install`) From 059a93d5781bdc54ad693fd9f7551979ea7dd68e Mon Sep 17 00:00:00 2001 From: Chris Black Date: Wed, 2 Oct 2024 14:01:19 -0700 Subject: [PATCH 07/13] set env inside R call Probably not a big difference, but felt to me like it make the Make output a little easier to interpret --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aa80046ae6f..a7827141bb9 100644 --- a/Makefile +++ b/Makefile @@ -77,8 +77,9 @@ git_rev = $(shell \ # When this is fixed, can go back to simple `dependencies = TRUE` depends_R_pkg = ./scripts/time.sh "depends ${1}" ./scripts/confirm_deps.R ${1} \ $(if $(findstring modules/benchmark,$(1)),NA,TRUE) -install_R_pkg = PECAN_GIT_REV="$(call git_rev,$1)" ./scripts/time.sh "install ${1}" Rscript \ +install_R_pkg = ./scripts/time.sh "install ${1}" Rscript \ -e ${SETROPTIONS} \ + -e "Sys.setenv(PECAN_GIT_REV='$(call git_rev,$1)')" \ -e "remotes::install_local('$(strip $(1))', force=TRUE, dependencies=FALSE, upgrade=FALSE)" check_R_pkg = ./scripts/time.sh "check ${1}" Rscript scripts/check_with_errors.R $(strip $(1)) test_R_pkg = ./scripts/time.sh "test ${1}" Rscript \ From f78fd1faa29d48f8bdd491a83fbfff8f9ee7795a Mon Sep 17 00:00:00 2001 From: Chris Black Date: Wed, 2 Oct 2024 15:52:54 -0700 Subject: [PATCH 08/13] more printing tweaks - use args provided at print time - default to no rownames and left alignment - truncate more --- base/all/R/pecan_version.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 6c0be5e522c..92327b8b75b 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -133,14 +133,23 @@ get_buildhash <- function(pkg) { # (Just to help it display more compactly) #' @export print.pecan_version_report <- function(x, ...) { + + dots <- list(...) + if (is.null(dots$row.names)) { dots$row.names <- FALSE } + if (is.null(dots$right)) { dots$right <- FALSE } + xx <- as.data.frame(x) xx$build_hash[is.na(xx$build_hash)] <- "" + xx$build_hash <- sub(".{5}\\+mods$", "+mods", xx$build_hash) xx$installed <- paste0( xx$installed, sub("(.+)", " (\\1)", xx$build_hash)) xx$build_hash <- NULL if (!is.null(xx$source)) { - xx$source <- paste0(substr(xx$source, 1, 17), "...") + xx$source <- paste0( + strtrim(xx$source, 17), + ifelse(nchar(xx$source, type="width") <= 17, "", "...")) } - print(xx) + dots$x <- xx + do.call("print", dots) } From 26515c9c4e393f80597a79b2e024ced8d30a6885 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Wed, 2 Oct 2024 22:41:22 -0700 Subject: [PATCH 09/13] one less letter --- Makefile | 2 +- base/all/R/pecan_version.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a7827141bb9..db701ada644 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ files_in_dir = $(call drop_parents, $(call recurse_dir, $1)) # Git hash + clean status for this directory git_rev = $(shell \ - CLEAN=$$([[ -n $$(git status -s $1) ]] && echo "+mods"); \ + CLEAN=$$([[ -n $$(git status -s $1) ]] && echo "+mod"); \ echo $$(git rev-parse --short=10 HEAD)"$$CLEAN") # HACK: NA vs TRUE switch on dependencies argument is an ugly workaround for diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 92327b8b75b..bb99b9790e1 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -140,7 +140,7 @@ print.pecan_version_report <- function(x, ...) { xx <- as.data.frame(x) xx$build_hash[is.na(xx$build_hash)] <- "" - xx$build_hash <- sub(".{5}\\+mods$", "+mods", xx$build_hash) + xx$build_hash <- sub(".{4}\\+mod$", "+mod", xx$build_hash) xx$installed <- paste0( xx$installed, sub("(.+)", " (\\1)", xx$build_hash)) From 769e9e39a55f3ea42e8488a578b95c130c893ad3 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 3 Oct 2024 01:14:19 -0700 Subject: [PATCH 10/13] tests --- base/all/R/pecan_version.R | 2 ++ base/all/tests/testthat/test-pecan_version.R | 34 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index bb99b9790e1..3617d37b02c 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -152,4 +152,6 @@ print.pecan_version_report <- function(x, ...) { } dots$x <- xx do.call("print", dots) + + invisible(x) } diff --git a/base/all/tests/testthat/test-pecan_version.R b/base/all/tests/testthat/test-pecan_version.R index fc1d147c575..b66172709a2 100644 --- a/base/all/tests/testthat/test-pecan_version.R +++ b/base/all/tests/testthat/test-pecan_version.R @@ -91,3 +91,37 @@ test_that("pecan_version without sessioninfo", { # 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). + + +test_that("printing", { + ver <- structure( + data.frame( + package = "PEcAnFake", + v0.0 = package_version("1.2.3"), + installed = package_version("1.2.3.9000"), + build_hash = "01234567ab", + source = "13 characters"), + class = c("pecan_version_report", "data.frame") + ) + + long_ver <- ver + long_ver$build_hash = "01234567ab+mod" + long_ver$source = "twenty-two characters" + + # hash truncated to fit "+mod" if present + expect_output(print(ver), "01234567ab", fixed = TRUE) + expect_output(print(long_ver), "012345+mod", fixed = TRUE) + + # source truncated to total of 20 chars + expect_output(print(ver), "13 characters$") + expect_output(print(long_ver), "twenty-two charac...", fixed = TRUE) + + # source truncation works on width not glyph count + long_ver$source <- gsub("tw", "\U{1F197}\U{1F192}", long_ver$source) + expect_output(print(long_ver), "\U{1F192}o ch...", fixed = TRUE) + + # dots passed on + expect_output(print(ver), "\n PEcAnFake") + expect_output(print(ver, row.names = TRUE), "\n1 PEcAnFake", fixed = TRUE) + expect_output(print(ver, quote = TRUE), "\n \"PEcAnFake\"", fixed = TRUE) +}) From 5984931829deed473740f61beb2759e13d99a096 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 3 Oct 2024 02:22:16 -0700 Subject: [PATCH 11/13] changelog --- CHANGELOG.md | 1 + base/all/NEWS.md | 4 ++++ base/all/R/pecan_version.R | 6 +++--- base/all/man/pecan_version.Rd | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a17817da4b..0cbd0976ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha * Model packages `PEcAn.BASGRA`, `PEcAn.CLM45`, `PEcAn.DALEC`, `PEcAn.dvmdostem`, `PEcAn.FATES`, `PEcAn.GDAY`, `PEcAn.JULES`, `PEcAn.LDNDC`, `PEcAn.LINKAGES`, `PEcAn.LPJGUESS`, `PEcAn.MAAT`, `PEcAn.MAESPA`, `PEcAn.PRELES`, `PEcAn.SIBCASA`, `PEcAn.SIPNET`, `PEcAn.STICS`, and the new model package template. * Modules `PEcAn.allometry`, `PEcAn.assim.batch`, `PEcAn.data.mining`, `PEcAn.emulator`, `PEcAn.MA`, `PEcAn.photosynthesis`, `PEcAn.priors`, and `PEcAn.RTM`. - Renamed master branch to main +- `PEcAn.all::pecan_version()` now reports commit hashes as well as version numbers for each installed package. ### Removed diff --git a/base/all/NEWS.md b/base/all/NEWS.md index 22b477b0daa..1c4ff017520 100644 --- a/base/all/NEWS.md +++ b/base/all/NEWS.md @@ -3,6 +3,10 @@ ## License change * PEcAn.all is now distributed under the BSD three-clause license instead of the NCSA Open Source license. +## Changed +* `pecan_version()` now reports the Git revision (if known) for each package, + and prints its results more compactly for easier reading. + # PEcAn.all 1.8.0 ## Added diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 3617d37b02c..76d7fe0a1e3 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -23,9 +23,9 @@ #' @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. -#' If the `sessioninfo` package is installed, a fourth column reports where -#' each package was installed from: local, github, CRAN, etc. +#' installed version, and Git hash (if known). +#' If the `sessioninfo` package is installed, an additional column reports +#' where each package was installed from: local, github, CRAN, etc. #' #' @examples #' pecan_version() diff --git a/base/all/man/pecan_version.Rd b/base/all/man/pecan_version.Rd index a0275089a9a..1f3c9578b59 100644 --- a/base/all/man/pecan_version.Rd +++ b/base/all/man/pecan_version.Rd @@ -14,9 +14,9 @@ or all tags that have it as a substring?} } \value{ data frame with columns for package name, expected version(s), -and installed version. -If the \code{sessioninfo} package is installed, a fourth column reports where -each package was installed from: local, github, CRAN, etc. +installed version, and Git hash (if known). +If the \code{sessioninfo} package is installed, an additional column reports +where each package was installed from: local, github, CRAN, etc. } \description{ Reports the currently installed or loaded version(s) of each PEcAn package, From 5a3faca5527c99f284e3a0b6367575f7adf081a9 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 10 Oct 2024 16:11:21 -0700 Subject: [PATCH 12/13] document that version is read from env at install not build It would be conceptually better to record it at build time, but R code is not parsed at that stage. If we really want build-time recording, could consider saving it as data (data/*.R are run at build time) --- base/all/R/version.R | 2 +- base/db/R/version.R | 2 +- base/logger/R/version.R | 2 +- base/qaqc/R/version.R | 2 +- base/remote/R/version.R | 2 +- base/settings/R/version.R | 2 +- base/utils/R/version.R | 2 +- base/visualization/R/version.R | 2 +- base/workflow/R/version.R | 2 +- models/basgra/R/version.R | 2 +- models/biocro/R/version.R | 2 +- models/clm45/R/version.R | 2 +- models/dalec/R/version.R | 2 +- models/dvmdostem/R/version.R | 2 +- models/ed/R/version.R | 2 +- models/fates/R/version.R | 2 +- models/gday/R/version.R | 2 +- models/jules/R/version.R | 2 +- models/ldndc/R/version.R | 2 +- models/linkages/R/version.R | 2 +- models/lpjguess/R/version.R | 2 +- models/maat/R/version.R | 2 +- models/maespa/R/version.R | 2 +- models/preles/R/version.R | 2 +- models/sibcasa/R/version.R | 2 +- models/sipnet/R/version.R | 2 +- models/stics/R/version.R | 2 +- models/template/R/version.R | 2 +- modules/allometry/R/version.R | 2 +- modules/assim.batch/R/version.R | 2 +- modules/assim.sequential/R/version.R | 2 +- modules/benchmark/R/version.R | 2 +- modules/data.atmosphere/R/version.R | 2 +- modules/data.land/R/version.R | 2 +- modules/data.remote/R/version.R | 2 +- modules/emulator/R/version.R | 2 +- modules/meta.analysis/R/version.R | 2 +- modules/photosynthesis/R/version.R | 2 +- modules/priors/R/version.R | 2 +- modules/rtm/R/version.R | 2 +- modules/uncertainty/R/version.R | 2 +- 41 files changed, 41 insertions(+), 41 deletions(-) diff --git a/base/all/R/version.R b/base/all/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/all/R/version.R +++ b/base/all/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/db/R/version.R b/base/db/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/db/R/version.R +++ b/base/db/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/logger/R/version.R b/base/logger/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/logger/R/version.R +++ b/base/logger/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/qaqc/R/version.R b/base/qaqc/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/qaqc/R/version.R +++ b/base/qaqc/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/remote/R/version.R b/base/remote/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/remote/R/version.R +++ b/base/remote/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/settings/R/version.R b/base/settings/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/settings/R/version.R +++ b/base/settings/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/utils/R/version.R b/base/utils/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/utils/R/version.R +++ b/base/utils/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/visualization/R/version.R b/base/visualization/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/visualization/R/version.R +++ b/base/visualization/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/base/workflow/R/version.R b/base/workflow/R/version.R index 660621ff760..0e58d885272 100644 --- a/base/workflow/R/version.R +++ b/base/workflow/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/basgra/R/version.R b/models/basgra/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/basgra/R/version.R +++ b/models/basgra/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/biocro/R/version.R b/models/biocro/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/biocro/R/version.R +++ b/models/biocro/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/clm45/R/version.R b/models/clm45/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/clm45/R/version.R +++ b/models/clm45/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/dalec/R/version.R b/models/dalec/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/dalec/R/version.R +++ b/models/dalec/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/dvmdostem/R/version.R b/models/dvmdostem/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/dvmdostem/R/version.R +++ b/models/dvmdostem/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/ed/R/version.R b/models/ed/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/ed/R/version.R +++ b/models/ed/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/fates/R/version.R b/models/fates/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/fates/R/version.R +++ b/models/fates/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/gday/R/version.R b/models/gday/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/gday/R/version.R +++ b/models/gday/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/jules/R/version.R b/models/jules/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/jules/R/version.R +++ b/models/jules/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/ldndc/R/version.R b/models/ldndc/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/ldndc/R/version.R +++ b/models/ldndc/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/linkages/R/version.R b/models/linkages/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/linkages/R/version.R +++ b/models/linkages/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/lpjguess/R/version.R b/models/lpjguess/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/lpjguess/R/version.R +++ b/models/lpjguess/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/maat/R/version.R b/models/maat/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/maat/R/version.R +++ b/models/maat/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/maespa/R/version.R b/models/maespa/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/maespa/R/version.R +++ b/models/maespa/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/preles/R/version.R b/models/preles/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/preles/R/version.R +++ b/models/preles/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/sibcasa/R/version.R b/models/sibcasa/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/sibcasa/R/version.R +++ b/models/sibcasa/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/sipnet/R/version.R b/models/sipnet/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/sipnet/R/version.R +++ b/models/sipnet/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/stics/R/version.R b/models/stics/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/stics/R/version.R +++ b/models/stics/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/models/template/R/version.R b/models/template/R/version.R index 660621ff760..0e58d885272 100644 --- a/models/template/R/version.R +++ b/models/template/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/allometry/R/version.R b/modules/allometry/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/allometry/R/version.R +++ b/modules/allometry/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/assim.batch/R/version.R b/modules/assim.batch/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/assim.batch/R/version.R +++ b/modules/assim.batch/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/assim.sequential/R/version.R b/modules/assim.sequential/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/assim.sequential/R/version.R +++ b/modules/assim.sequential/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/benchmark/R/version.R b/modules/benchmark/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/benchmark/R/version.R +++ b/modules/benchmark/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.atmosphere/R/version.R b/modules/data.atmosphere/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/data.atmosphere/R/version.R +++ b/modules/data.atmosphere/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.land/R/version.R b/modules/data.land/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/data.land/R/version.R +++ b/modules/data.land/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/data.remote/R/version.R b/modules/data.remote/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/data.remote/R/version.R +++ b/modules/data.remote/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/emulator/R/version.R b/modules/emulator/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/emulator/R/version.R +++ b/modules/emulator/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/meta.analysis/R/version.R b/modules/meta.analysis/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/meta.analysis/R/version.R +++ b/modules/meta.analysis/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/photosynthesis/R/version.R b/modules/photosynthesis/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/photosynthesis/R/version.R +++ b/modules/photosynthesis/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/priors/R/version.R b/modules/priors/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/priors/R/version.R +++ b/modules/priors/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/rtm/R/version.R b/modules/rtm/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/rtm/R/version.R +++ b/modules/rtm/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") diff --git a/modules/uncertainty/R/version.R b/modules/uncertainty/R/version.R index 660621ff760..0e58d885272 100644 --- a/modules/uncertainty/R/version.R +++ b/modules/uncertainty/R/version.R @@ -1,3 +1,3 @@ -# Set at package build time, used by pecan.all::pecan_version() +# Set at package install time, used by pecan.all::pecan_version() # to identify development versions of packages .build_hash <- Sys.getenv("PECAN_GIT_REV", "unknown") From 83af3ed5a02ca45db857ba507fadfb8a722581e8 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 10 Oct 2024 22:17:43 -0700 Subject: [PATCH 13/13] only display hash for dev versions --- base/all/R/pecan_version.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/base/all/R/pecan_version.R b/base/all/R/pecan_version.R index 76d7fe0a1e3..7d686af6d1f 100644 --- a/base/all/R/pecan_version.R +++ b/base/all/R/pecan_version.R @@ -104,6 +104,7 @@ pecan_version <- function(version = max(PEcAn.all::pecan_releases$version), y = PEcAn.all::pecan_version_history, all = TRUE) res <- drop_na_version_rows(res[, cols_to_return]) + rownames(res) <- res$package class(res) <- c("pecan_version_report", class(res)) res @@ -119,7 +120,7 @@ drop_na_version_rows <- function(df) { # Look up git revision, if recorded, from an installed PEcAn package get_buildhash <- function(pkg) { - # Set if installed from r-universe or via install_github() + # Set if pkg was installed from r-universe or via install_github() desc_sha <- utils::packageDescription(pkg, fields = "RemoteSha") if (!is.na(desc_sha)) { return(substr(desc_sha, 1, 10)) @@ -139,7 +140,10 @@ print.pecan_version_report <- function(x, ...) { if (is.null(dots$right)) { dots$right <- FALSE } xx <- as.data.frame(x) - xx$build_hash[is.na(xx$build_hash)] <- "" + # only print hash for dev versions + # (typically x.y.z.9000, but we'll use anything with a 4th version component) + skip_hash <- is.na(xx$installed[,4]) | is.na(xx$build_hash) + xx$build_hash[skip_hash] <- "" xx$build_hash <- sub(".{4}\\+mod$", "+mod", xx$build_hash) xx$installed <- paste0( xx$installed,