Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Version parsing for mamba v1 #936

Merged
merged 14 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ if [ "$BATCH" = "0" ]; then
# to perform the initialization.
#
# Otherwise (i.e. as of 2.0.0), we use the `mamba shell init` command
if [ "$("$PREFIX/bin/mamba" --version | cut -d' ' -f2 | cut -d'.' -f1)" -lt 2 ]; then
if [ "$("$PREFIX/bin/mamba" --version | head -n 1 | cut -d' ' -f2 | cut -d'.' -f1)" -lt 2 ]; then
case $SHELL in
# We call the module directly to avoid issues with spaces in shebang
*zsh) "$PREFIX/bin/python" -m mamba.mamba init zsh ;;
Expand Down
28 changes: 28 additions & 0 deletions examples/miniforge-mamba2/EULA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) 2016, Example, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Example, Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL EXAMPLE, INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The License has to be read correctly so that dollar signs don't lead to an unset
parameter error:
You have to pay US $8, if you can read this.
25 changes: 25 additions & 0 deletions examples/miniforge-mamba2/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Miniforge3-mamba2
version: 25.0.0-2
company: conda-forge
license_file: EULA.txt

channels:
- conda-forge

write_condarc: True
keep_pkgs: True
transmute_file_type: .conda

specs:
- python 3.12.*
- conda 24.11.2
- mamba 2.0.5
- pip
- miniforge_console_shortcut 1.* # [win]

# Added for extra testing
installer_type: all
post_install: test_install.sh # [unix]
post_install: test_install.bat # [win]
initialize_by_default: false
register_python: False
8 changes: 8 additions & 0 deletions examples/miniforge-mamba2/test_install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo Added by test-install script > "%PREFIX%\test_install_sentinel.txt"
SetLocal EnableDelayedExpansion

@ECHO ON
call "%PREFIX%\Scripts\activate.bat
conda info || exit 1
conda config --show-sources || exit 1
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert 'conda-forge' in info['channels'], info"
64 changes: 64 additions & 0 deletions examples/miniforge-mamba2/test_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

set -eo pipefail
echo "Added by test-install script" > "$PREFIX/test_install_sentinel.txt"

echo "sourcing..."
# shellcheck disable=SC1091
source "$PREFIX/etc/profile.d/conda.sh"

conda activate "$PREFIX"

echo "+ conda info"
conda info -v

echo "+ conda config"
conda config --show-sources

echo "+ Testing conda channels"
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert 'conda-forge' in info['channels'], info"
echo " OK"

EXPECTED_MAMBA_VERSION="2.0.5"

# Get versions with conda
MAMBA_VERSION=$(conda list "^mamba$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")
LIBMAMBA_VERSION=$(conda list "^libmamba$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")
LIBMAMBAPY_VERSION=$(conda list "^libmambapy$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")

if [ "$MAMBA_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: Mamba version mismatch: expected $EXPECTED_MAMBA_VERSION, got $MAMBA_VERSION"
exit 1
fi

if [ "$LIBMAMBA_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: libmamba version mismatch: expected $EXPECTED_MAMBA_VERSION, got $LIBMAMBA_VERSION"
exit 1
fi

if [ "$LIBMAMBAPY_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: libmambapy version mismatch: expected $EXPECTED_MAMBA_VERSION, got $LIBMAMBAPY_VERSION"
exit 1
fi

echo "+ Testing mamba 2 installation"
mamba --version | grep -q "$EXPECTED_MAMBA_VERSION"

echo "+ mamba info"
mamba info

echo "+ mamba config sources"
mamba config sources

echo "+ mamba config list"
mamba config list

echo "+ Testing mamba 2 version"
mamba info --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert info['mamba version'] == '$EXPECTED_MAMBA_VERSION', info"

echo "+ Testing libmambapy 2 version"
python -c "import libmambapy; assert libmambapy.__version__ == '$EXPECTED_MAMBA_VERSION', f'libmamba version got: {libmambapy.__version__}; expected: ${EXPECTED_MAMBA_VERSION}'"

echo "+ Testing mamba channels"
mamba info --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert any('conda-forge' in c for c in info['channels']), info"
echo " OK"
4 changes: 2 additions & 2 deletions examples/miniforge/construct.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Miniforge3
version: 25.0.0
version: 25.0.0-1
company: conda-forge
license_file: EULA.txt

Expand All @@ -13,7 +13,7 @@ transmute_file_type: .conda
specs:
- python 3.12.*
- conda 24.11.2
- mamba 2.0.5
- mamba 1.5.12
- pip
- miniforge_console_shortcut 1.* # [win]

Expand Down
41 changes: 27 additions & 14 deletions examples/miniforge/test_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,39 @@ echo "+ Testing conda channels"
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert 'conda-forge' in info['channels'], info"
echo " OK"

echo "+ Testing mamba installation"
EXPECTED_MAMBA_VERSION="1.5.12"

# Get versions with conda
MAMBA_VERSION=$(conda list "^mamba$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")
LIBMAMBA_VERSION=$(conda list "^libmamba$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")
LIBMAMBAPY_VERSION=$(conda list "^libmambapy$" --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); print(info[0]['version'])")

if [ "$MAMBA_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: Mamba version mismatch: expected $EXPECTED_MAMBA_VERSION, got $MAMBA_VERSION"
exit 1
fi

if [ "$LIBMAMBA_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: libmamba version mismatch: expected $EXPECTED_MAMBA_VERSION, got $LIBMAMBA_VERSION"
exit 1
fi

if [ "$LIBMAMBAPY_VERSION" != "$EXPECTED_MAMBA_VERSION" ]; then
echo "ERROR: libmambapy version mismatch: expected $EXPECTED_MAMBA_VERSION, got $LIBMAMBAPY_VERSION"
exit 1
fi

echo "+ Testing mamba 1 installation"
mamba --version
echo " OK"

echo "+ mamba info"
mamba info

echo "+ mamba config sources"
mamba config sources

echo "+ mamba config list"
mamba config list
echo "+ Testing mamba version"
mamba --version | grep mamba | cut -d' ' -f2 | grep -q "$EXPECTED_MAMBA_VERSION"
mamba --version | grep conda | cut -d' ' -f2 | grep -q 24.11.2

echo "+ Testing mamba 2 version"
mamba info --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert info['mamba version'] == '2.0.5', info"
echo " OK"

echo "+ Testing libmambapy 2 version"
python -c "import libmambapy; assert libmambapy.__version__ == '2.0.5', f'libmamba version got: {libmambapy.__version__}; expected: 2.0.5'"
echo " OK"
mamba info --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert info['mamba_version'] == '$EXPECTED_MAMBA_VERSION', info"

echo "+ Testing mamba channels"
mamba info --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert any('conda-forge' in c for c in info['channels']), info"
Expand Down
19 changes: 19 additions & 0 deletions news/936-version-parsing-mamba-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix version parsing when `mamba` v1 is used (#936)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
9 changes: 6 additions & 3 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,9 @@ def test_example_extra_files(tmp_path, request):
),
reason="Known issue with conda-standalone<=23.10: shortcuts are created but not removed.",
)
def test_example_miniforge(tmp_path, request):
input_path = _example_path("miniforge")
@pytest.mark.parametrize("example", ("miniforge", "miniforge-mamba2"))
def test_example_miniforge(tmp_path, request, example):
input_path = _example_path(example)
for installer, install_dir in create_installer(input_path, tmp_path):
if installer.suffix == ".sh":
# try both batch and interactive installations
Expand All @@ -435,13 +436,15 @@ def test_example_miniforge(tmp_path, request):
installer,
install_dir,
installer_input=installer_input,
request=request,
# PKG installers use their own install path, so we can't check sentinels
# via `install_dir`
check_sentinels=installer.suffix != ".pkg",
uninstall=False,
)
if installer.suffix == ".pkg" and ON_CI:
_sentinel_file_checks(input_path, Path(os.environ["HOME"]) / "Miniforge3")
basename = "Miniforge3" if example == "miniforge" else "Miniforge3-mamba2"
_sentinel_file_checks(input_path, Path(os.environ["HOME"]) / basename)
if installer.suffix == ".exe":
for key in ("ProgramData", "AppData"):
start_menu_dir = Path(
Expand Down
Loading