From 960decbccdf91546c8c213f9fafcff23a74f3c13 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Fri, 15 Sep 2023 16:08:04 -0700 Subject: [PATCH] runner.conda: Explicitly install the latest package version during setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This our intent and expectation, and it's good to be explicit about it. It may surface more installation issues, such as the one we observed in monkeypox CI¹ with the latest version not being installable, but obscuring those or surfacing them later on is _probably_ worse than addressing them head on earlier. This change will mean that any macOS 10.14 users, if any, would have to use NEXTSTRAIN_CONDA_BASE_PACKAGE="nextstrain-base ==20230615T171309Z" since newer versions aren't installable for them.² This behaviour also parallels update's behaviour since "runner.conda: Explicitly specify a nextstrain-base version when updating" (d6e4f2b). It was an oversight (on my part) to not use the same behaviour during setup, but at the time I was focused on fixing an update bug. Related-to: Related-to: ¹ ² --- nextstrain/cli/runner/conda.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/nextstrain/cli/runner/conda.py b/nextstrain/cli/runner/conda.py index 3bd0a635..1cd0840c 100644 --- a/nextstrain/cli/runner/conda.py +++ b/nextstrain/cli/runner/conda.py @@ -247,23 +247,30 @@ def setup_prefix(dry_run: bool = False, force: bool = False) -> bool: if not dry_run: shutil.rmtree(str(PREFIX)) - # Conda packages to install. + # We accept a package match spec, which one to three space-separated parts.¹ + # If we got a spec, then we use it as-is. + # + # ¹ # - # HEY YOU: If you add/remove packages here, make sure to account for how - # update() should make the same changes to existing envs. - # -trs, 1 Sept 2022 - packages = ( - NEXTSTRAIN_BASE, - ) + if " " in NEXTSTRAIN_BASE.strip(): + install_spec = NEXTSTRAIN_BASE + else: + latest_version = (package_distribution(NEXTSTRAIN_CHANNEL, NEXTSTRAIN_BASE) or {}).get("version") + + if latest_version: + install_spec = f"{NEXTSTRAIN_BASE} =={latest_version}" + else: + warn(f"Unable to find latest version of {NEXTSTRAIN_BASE} package; falling back to non-specific install") + + install_spec = NEXTSTRAIN_BASE # Create environment print(f"Installing Conda packages into {PREFIX}…") - for pkg in packages: - print(f" - {pkg}") + print(f" - {install_spec}") if not dry_run: try: - micromamba("create", *packages) + micromamba("create", install_spec) except InternalError as err: warn(err) traceback.print_exc()