Skip to content

Commit 12cb57a

Browse files
authored
Merge pull request #1229 from LourensVeen/issue_1190_non_conda_forge_packages
Add a check for mixed-source conda environments to ./setup
2 parents c13954a + 84b9038 commit 12cb57a

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

setup

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ configure() {
7777
if [ "a${ENV_TYPE}" = "a" ] ; then
7878
print_environment_step
7979
can_install="no"
80+
elif [ "a${MIXED_CONDA_PACKAGES}" != "a" ] && [ "a${AMUSE_ENABLE_MIXED_PACKAGES}" = "a" ] ; then
81+
print_mixed_packages
82+
can_install="no"
8083
elif [ "a${HAVE_PIP}" = "a" ] || [ "a${HAVE_WHEEL}" = "a" ] ; then
8184
print_pip_wheel_step
8285
can_install="no"

support/setup/environment.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ detect_installed_packages() {
7777
}
7878

7979

80+
# Determine whether we have a Conda environment with mixed packages
81+
#
82+
# Users of Anaconda have the Anaconda channels set by default, and if they then add
83+
# conda-forge and start installing packages will too often end up with some packages
84+
# from one source and some from the other. This leads to some very weird errors.
85+
#
86+
# This checks whether everything is installed either from conda-forge or by pip, and
87+
# sets MIXED_CONDA_PACKAGES to a list of packages that are not from conda-forge or pip.
88+
# If we're not in a conda environment or everything is fine, then MIXED_CONDA_PACKAGES
89+
# will be an empty string.
90+
check_mixed_conda_packages() {
91+
MIXED_CONDA_PACKAGES=""
92+
if [ "a${ENV_TYPE}" = "aconda" ] ; then
93+
ALIEN_PACKAGES="$(echo "${CONDA_LIST}" | tr '^' '\n' | grep -v '^#.*\|conda-forge\|pypi' | cut -d ' ' -f 1,4)"
94+
if [ "a${ALIEN_PACKAGES}" != "a" ] ; then
95+
MIXED_CONDA_PACKAGES=''
96+
for p in ${ALIEN_PACKAGES} ; do
97+
MIXED_CONDA_PACKAGES="${MIXED_CONDA_PACKAGES} ${p}"
98+
done
99+
fi
100+
fi
101+
}
102+
103+
80104
# Determine if we have the required features to build the framework
81105
#
82106
# This uses the following variables:
@@ -212,6 +236,7 @@ find_packages() {
212236
analyse_environment() {
213237
detect_environments
214238
detect_installed_packages
239+
check_mixed_conda_packages
215240
check_build_framework
216241
check_build_sapporo_light
217242
find_packages

support/setup/help.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ again to continue."
134134
}
135135

136136

137+
print_mixed_packages() {
138+
# Note that MIXED_CONDA_PACKAGES starts with a space
139+
printf '%b\n' "${BOLD}${COLOR_YELLOW}* (error) Fix mixed-source packages *${COLOR_END}${END_BOLD}
140+
141+
Installation is disabled because packages from mixed sources were found in your Conda
142+
environment. This can cause some very weird problems. AMUSE is designed and tested with
143+
packages from conda-forge. The following packages were not installed from conda-forge:
144+
145+
${MIXED_CONDA_PACKAGES}
146+
147+
To reinstall them from conda-forge, you can try:
148+
149+
conda install --channel conda-forge --override-channels${MIXED_CONDA_PACKAGES}
150+
151+
If you're sure you know what you're doing, then you can disable this check by setting
152+
the environment variable AMUSE_ENABLE_MIXED_PACKAGES to 1 and running ./setup again."
153+
}
154+
155+
137156
print_pip_wheel_step() {
138157
printf '%b\n' "${BOLD}${COLOR_YELLOW}* (2/4) Install pip and wheel *${COLOR_END}${END_BOLD}
139158

0 commit comments

Comments
 (0)