Skip to content

Fix VersionSpec globs #3889

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

Merged
merged 16 commits into from
Apr 18, 2025
Merged

Fix VersionSpec globs #3889

merged 16 commits into from
Apr 18, 2025

Conversation

AntoinePrv
Copy link
Member

@AntoinePrv AntoinePrv commented Apr 10, 2025

@jaimergp @jdblischak this should solve a number of cases. I'm happy to add more test cases if you have some to suggest.
Fix #3601

Note that full regex on versions are not implemented.

@AntoinePrv AntoinePrv added the type::bug Something isn't working label Apr 10, 2025
@AntoinePrv AntoinePrv linked an issue Apr 10, 2025 that may be closed by this pull request
3 tasks
@AntoinePrv AntoinePrv added release::bug_fixes For PRs fixing bugs and removed type::bug Something isn't working labels Apr 10, 2025
jjerphan added a commit to jjerphan/mamba that referenced this pull request Apr 10, 2025
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 91.29032% with 27 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@51890d3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
libmamba/tests/src/specs/test_match_spec.cpp 50.94% 26 Missing ⚠️
libmambapy/src/libmambapy/bindings/specs.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3889   +/-   ##
=======================================
  Coverage        ?   62.91%           
=======================================
  Files           ?      299           
  Lines           ?    36955           
  Branches        ?     2777           
=======================================
  Hits            ?    23252           
  Misses          ?    13651           
  Partials        ?       52           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I have a few questions and suggestions.

@jdblischak
Copy link
Contributor

@AntoinePrv how can I locally test this branch? I couldn't find any developer docs on how to setup a local development environment (eg I checked CONTRIBUTING.rst.

I tried following the instructions to build micromamba from source, but I assume I did something wrong because micromamba built from this PR behaved exactly the same as micromamba built from main (64a620a).

Details of attempt to test behavior with source build of micromamba

# Setup
docker run --rm -it condaforge/miniforge3 bash
mamba init
source ~/.bashrc
git clone https://github.com/mamba-org/mamba.git
cd mamba/
mamba env create -n mamba-from-source --file dev/environment-micromamba-static.yml
mamba activate mamba-from-source

# Build latest from main
git log -n 1 --pretty=reference
## 64a620a2 (ci: Adapt code coverage workflow (#3890), 2025-04-11)
cmake -B build-main/ \
    -G Ninja \
    ${CMAKE_ARGS} \
    -D CMAKE_INSTALL_PREFIX="${CONDA_PREFIX}" \
    -D CMAKE_BUILD_TYPE="Release" \
    -D BUILD_LIBMAMBA=ON \
    -D BUILD_STATIC=ON \
    -D BUILD_MICROMAMBA=ON
cmake --build build-main/ --parallel
./build-main/micromamba/micromamba --version
## 2.1.0

# Trailing glob works
./build-main/micromamba/micromamba create -n test --dry-run 'python=3.*'
## + python               3.13.3  hf636f53_100_cp313  conda-forge      33MB
# Internal glob fails
./build-main/micromamba/micromamba create -n test --dry-run 'python=3.*.1'
## error    libmamba Could not solve for environment specs
##     The following package could not be installed
##     └─ python =3.0*.1 * does not exist (perhaps a typo or a missing channel).
## critical libmamba Could not solve for environment specs
# Leading glob fails
./build-main/micromamba/micromamba create -n test --dry-run 'python=*.13.3'
## error    libmamba Could not solve for environment specs
##     The following package could not be installed
##     └─ python =0*.13.3 * does not exist (perhaps a typo or a missing channel).
## critical libmamba Could not solve for environment specs

# Build from PR 3889
git remote add AntoinePrv https://github.com/AntoinePrv/fork-mamba-org-mamba.git
git fetch AntoinePrv
git checkout -t AntoinePrv/fix-version-spec
git log -n 1 --pretty=reference
## fab70f0f (Cleanup, 2025-04-14)
cmake -B build-pr3889/ \
    -G Ninja \
    ${CMAKE_ARGS} \
    -D CMAKE_INSTALL_PREFIX="${CONDA_PREFIX}" \
    -D CMAKE_BUILD_TYPE="Release" \
    -D BUILD_LIBMAMBA=ON \
    -D BUILD_STATIC=ON \
    -D BUILD_MICROMAMBA=ON
cmake --build build-pr3889/ --parallel
./build-pr3889/micromamba/micromamba --version
## 2.1.0
# Trailing glob works
./build-pr3889/micromamba/micromamba create -n test --dry-run 'python=3.*'
## + python               3.13.3  hf636f53_100_cp313  conda-forge      33MB
# Internal glob fails
./build-pr3889/micromamba/micromamba create -n test --dry-run 'python=3.*.1'
## error    libmamba Could not solve for environment specs
##     The following package could not be installed
##     └─ python =3.0*.1 * does not exist (perhaps a typo or a missing channel).
## critical libmamba Could not solve for environment specs
# Leading glob fails
./build-pr3889/micromamba/micromamba create -n test --dry-run 'python=*.13.3'
## error    libmamba Could not solve for environment specs
##     The following package could not be installed
##     └─ python =0*.13.3 * does not exist (perhaps a typo or a missing channel).
## critical libmamba Could not solve for environment specs

@AntoinePrv
Copy link
Member Author

@jdblischak we have doc on dev environment but I guess you have everything right.

I believe that I have not anticipated this case. python=3.*.1 get split into python + =3.*.1 and the leading = in the version prevents it from being treated as a glob (we see =3.0*.1 meaning it is treated as a 0*). If you try python 3.*.1 I think it would work. I think we should handle python=3.*.1 as glob, but I am not sure about precedent here. @jaimergp ? @jjerphan ?

@jjerphan
Copy link
Member

I think we should handle python=3.*.1 as glob, but I am not sure about precedent here.

I think this also must be handled, yes.

@AntoinePrv AntoinePrv force-pushed the fix-version-spec branch 2 times, most recently from a4af69a to 3d5176c Compare April 17, 2025 07:58
Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @AntoinePrv.

}));
}

SECTION("python=3.*.1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, @jdblischak.

@jdblischak
Copy link
Contributor

jdblischak commented Apr 17, 2025

we have doc on dev environment but I guess you have everything right.

Thanks! I'm embarrassed I missed these instructions. Using a combination of the docs on Development Environment and Micromamba Installation (to initialize micromamba to use micromamba activate), I was able to install libmamba and libmambapy.

In case it could be useful to other contributors, here is the code I ran in a Docker container to test this PR:

docker run --rm -it ubuntu:24.04 bash
apt-get update
apt-get install --yes bzip2 curl git tar
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
./bin/micromamba shell init -s bash -r ~/micromamba
source ~/.bashrc
micromamba --version
## 2.1.0

git clone https://github.com/mamba-org/mamba.git
cd mamba/
git remote add AntoinePrv https://github.com/AntoinePrv/fork-mamba-org-mamba.git
git fetch AntoinePrv
git checkout -t AntoinePrv/fix-version-spec
git log -n 1 --pretty=reference
## d5346f1b (Nit fixes, 2025-04-17)

micromamba create --yes -n mamba -c conda-forge \
  -f dev/environment-dev.yml -f dev/environment-dev-extra.yml
micromamba activate mamba

cmake -B build/ -G Ninja --preset mamba-unix-shared-debug-dev
cmake --build build/ --parallel
./build/libmamba/tests/test_libmamba
cmake --install build/ --prefix "${CONDA_PREFIX}"
python -m pip install --no-deps --no-build-isolation libmambapy/
python -m pytest libmambapy/tests

@jdblischak
Copy link
Contributor

Also, I ran the same Python test code as I did with libmambapy 2.0.4 in #3601 (comment) to confirm that internal and leading version globs now behave as I expect:

import libmambapy

libmambapy.version.version_info
## ('2', '1', '0')

import libmambapy.specs as specs

specs.VersionSpec.parse("0.0.*")
specs.VersionSpec.parse("0.*.0")
specs.VersionSpec.parse("*.0.0")

# Trailing glob works as expected
specs.VersionSpec.parse("0.0.*").contains(specs.Version.parse("0.0.1"))
## True
specs.VersionSpec.parse("0.0.*").contains(specs.Version.parse("1.0.0"))
## False

# Internal glob now works as expected
specs.VersionSpec.parse("0.*.0").contains(specs.Version.parse("0.1.0"))
## True
specs.VersionSpec.parse("0.*.0").contains(specs.Version.parse("1.0.0"))
## False

# Leading glob now works as expected
specs.VersionSpec.parse("*.0.0").contains(specs.Version.parse("1.0.0"))
## True
specs.VersionSpec.parse("*.0.0").contains(specs.Version.parse("0.0.1"))
## False

Copy link
Contributor

@jdblischak jdblischak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AntoinePrv!

@jjerphan jjerphan merged commit 5f4759e into mamba-org:main Apr 18, 2025
37 checks passed
@AntoinePrv AntoinePrv deleted the fix-version-spec branch April 18, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::bug_fixes For PRs fixing bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistencies with globs in MatchSpec parsing
3 participants