From fed2bbabf30c99e8c2312d323f5e1ae1d7dada0e Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Tue, 3 Dec 2024 19:00:24 -0500 Subject: [PATCH 1/3] Use `--json` instead of grep to check conda updated https://github.com/conda/conda/issues/14418#issuecomment-2513806325 --- _conda_environment.yml | 1 + _scripts/check_conda_updated.sh | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/_conda_environment.yml b/_conda_environment.yml index c3a17c7..9bdc046 100644 --- a/_conda_environment.yml +++ b/_conda_environment.yml @@ -4,6 +4,7 @@ channels: dependencies: - compilers=1.8.* - curl=8.10.* + - jq=1.7.* - make=4.* - ruby=3.3.* - shellcheck=0.10.* diff --git a/_scripts/check_conda_updated.sh b/_scripts/check_conda_updated.sh index 6ec08c1..c44a66e 100644 --- a/_scripts/check_conda_updated.sh +++ b/_scripts/check_conda_updated.sh @@ -3,8 +3,6 @@ # Check that all installed conda packages are up to date function check_conda_updated () { TEMP_FILE="$(mktemp)" - conda update --all --dry-run | tee "$TEMP_FILE" - # grep for the message that conda update prints if packages are up to date. - # grep exits with 0 if it is not found (meaning that updates are available). - grep -q "requested packages already installed" "$TEMP_FILE" + mamba update --all --dry-run --json | tee "$TEMP_FILE" + jq -e '.success and (.actions | length) == 0' "$TEMP_FILE" } From 71ab775d49968256c93a827f7fa2630709dbf8d2 Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Tue, 3 Dec 2024 19:04:06 -0500 Subject: [PATCH 2/3] Draft post: Conda updated? --- _posts/2050-12-03-conda-updated.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 _posts/2050-12-03-conda-updated.md diff --git a/_posts/2050-12-03-conda-updated.md b/_posts/2050-12-03-conda-updated.md new file mode 100644 index 0000000..1fed9d8 --- /dev/null +++ b/_posts/2050-12-03-conda-updated.md @@ -0,0 +1,18 @@ +--- +layout: post +title: Conda updated? +--- + +Using a tip from +[Travis Hathaway](https://github.com/conda/conda/issues/14418#issuecomment-2513806325), +here is a shell one-liner to check if a conda environment is up to date: + +```shell +conda update --all --dry-run --json | jq -e '.success and (.actions | length) == 0' +``` + +It exits (`-e`) with `0` if the environment is already updated and `1` if +updates are available. + +I use this in CI so that I get an email if my `environment.yml` file is holding +any packages back. From 2bb042e2cfec2f2a0c21e791d90ab4d5420b5b2e Mon Sep 17 00:00:00 2001 From: Max Kapur Date: Tue, 3 Dec 2024 19:15:41 -0500 Subject: [PATCH 3/3] Remove `--no-default-packages` flag from `mamba env create` No idea why this stopped working all of a sudden. --- configure.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configure.sh b/configure.sh index 7ba1042..591eac1 100755 --- a/configure.sh +++ b/configure.sh @@ -47,8 +47,7 @@ function configure_conda_environment () { mamba env create \ --prefix "$CONDA_PREFIX" \ --file "$CONDA_ENV_YML" \ - --yes \ - --no-default-packages + --yes fi }