From 84b9038e39802728a6286a1d4c75ab996353deef Mon Sep 17 00:00:00 2001 From: Lourens Veen Date: Tue, 10 Mar 2026 16:23:39 +0100 Subject: [PATCH] Add a check for mixed-source conda environments to ./setup --- setup | 3 +++ support/setup/environment.sh | 25 +++++++++++++++++++++++++ support/setup/help.sh | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/setup b/setup index 47c76fb22a..a0e74d6eff 100755 --- a/setup +++ b/setup @@ -77,6 +77,9 @@ configure() { if [ "a${ENV_TYPE}" = "a" ] ; then print_environment_step can_install="no" + elif [ "a${MIXED_CONDA_PACKAGES}" != "a" ] && [ "a${AMUSE_ENABLE_MIXED_PACKAGES}" = "a" ] ; then + print_mixed_packages + can_install="no" elif [ "a${HAVE_PIP}" = "a" ] || [ "a${HAVE_WHEEL}" = "a" ] ; then print_pip_wheel_step can_install="no" diff --git a/support/setup/environment.sh b/support/setup/environment.sh index f5f4fb9352..3646e97eb6 100644 --- a/support/setup/environment.sh +++ b/support/setup/environment.sh @@ -77,6 +77,30 @@ detect_installed_packages() { } +# Determine whether we have a Conda environment with mixed packages +# +# Users of Anaconda have the Anaconda channels set by default, and if they then add +# conda-forge and start installing packages will too often end up with some packages +# from one source and some from the other. This leads to some very weird errors. +# +# This checks whether everything is installed either from conda-forge or by pip, and +# sets MIXED_CONDA_PACKAGES to a list of packages that are not from conda-forge or pip. +# If we're not in a conda environment or everything is fine, then MIXED_CONDA_PACKAGES +# will be an empty string. +check_mixed_conda_packages() { + MIXED_CONDA_PACKAGES="" + if [ "a${ENV_TYPE}" = "aconda" ] ; then + ALIEN_PACKAGES="$(echo "${CONDA_LIST}" | tr '^' '\n' | grep -v '^#.*\|conda-forge\|pypi' | cut -d ' ' -f 1,4)" + if [ "a${ALIEN_PACKAGES}" != "a" ] ; then + MIXED_CONDA_PACKAGES='' + for p in ${ALIEN_PACKAGES} ; do + MIXED_CONDA_PACKAGES="${MIXED_CONDA_PACKAGES} ${p}" + done + fi + fi +} + + # Determine if we have the required features to build the framework # # This uses the following variables: @@ -212,6 +236,7 @@ find_packages() { analyse_environment() { detect_environments detect_installed_packages + check_mixed_conda_packages check_build_framework check_build_sapporo_light find_packages diff --git a/support/setup/help.sh b/support/setup/help.sh index 8e9f04ae6b..a8a5bfc1f1 100644 --- a/support/setup/help.sh +++ b/support/setup/help.sh @@ -134,6 +134,25 @@ again to continue." } +print_mixed_packages() { + # Note that MIXED_CONDA_PACKAGES starts with a space + printf '%b\n' "${BOLD}${COLOR_YELLOW}* (error) Fix mixed-source packages *${COLOR_END}${END_BOLD} + +Installation is disabled because packages from mixed sources were found in your Conda +environment. This can cause some very weird problems. AMUSE is designed and tested with +packages from conda-forge. The following packages were not installed from conda-forge: + + ${MIXED_CONDA_PACKAGES} + +To reinstall them from conda-forge, you can try: + + conda install --channel conda-forge --override-channels${MIXED_CONDA_PACKAGES} + +If you're sure you know what you're doing, then you can disable this check by setting +the environment variable AMUSE_ENABLE_MIXED_PACKAGES to 1 and running ./setup again." +} + + print_pip_wheel_step() { printf '%b\n' "${BOLD}${COLOR_YELLOW}* (2/4) Install pip and wheel *${COLOR_END}${END_BOLD}