mamba-org / mamba

The Fast Cross-Platform Package Manager
https://mamba.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.79k stars 348 forks source link

[feature-request] Check for updates given a spec file #3301

Open jchorl opened 4 months ago

jchorl commented 4 months ago

Howdy!

I was thinking about how to implement something like dependabot support for conda yamls. There are many open issues, e.g. https://github.com/dependabot/dependabot-core/issues/2227

Given a spec (e.g. a yaml spec), how can one check for updates for any of the dependencies? Of course, this is complicated because some deps may have updates available but those may cause the env to not solve.

Here is an example. Consider this yaml spec file:

name: testenv
channels:
  - conda-forge
  - bioconda
  - defaults
dependencies:
  - pandas==1.5.3

Is there a micromamba command that could tell you that pandas can be updated? North star is probably to output a diff (this is not a proper diff, just for explanatory purposes):

name: testenv
channels:
  - conda-forge
  - bioconda
  - defaults
dependencies:
-  - pandas==1.5.3
+  - pandas==2.2.2

I was curious if:

  1. Is there an elegant way to do this today?
  2. If not, any ideas on what'd be required?

I did explore some options. I saw the nifty micromamba env update recently added. I noticed that tends to respect the spec constraints. However, removing constraints, I was able to get it to roughly give the desired results:

(mamba) root@6c3ad4c31204:/work# micromamba create -f testupdate/environment.yml -y
(mamba) root@6c3ad4c31204:/work# micromamba activate testenv
# remove the ==1.5.3 pin from the env file
(testenv) root@6c3ad4c31204:/work# micromamba env update -f testupdate/environment.yml --dry-run
conda-forge/linux-64                                        Using cache                                                          
conda-forge/noarch                                          Using cache                                                          
bioconda/linux-64                                           Using cache                                                          
bioconda/noarch                                             Using cache                                                          

Pinned packages:                                                                                                                 

  - python=3.11                                                                                                                  

Transaction                                                                                                                      

  Prefix: /opt/conda/envs/testenv                                                                                              

  Updating specs:                                                                                                                

   - pandas                                                                                                                      
  Removing specs:                                                                                                                

   - pandas                                                                                                                      

  Package          Version  Build            Channel           Size                                                              
─────────────────────────────────────────────────────────────────────                                                              Install:                                                                                                                       
─────────────────────────────────────────────────────────────────────                                                                                                                                                                                             
  + python-tzdata   2024.1  pyhd8ed1ab_0     conda-forge      144kB                                                              

  Upgrade:                                                                                                                       
─────────────────────────────────────────────────────────────────────                                                            

  - pandas           1.5.3  py311h2872171_1  conda-forge     Cached                                                              
  + pandas           2.2.2  py311h14de704_1  conda-forge       16MB                                                              

  Summary:                                                                                                                       

  Install: 1 packages                                                                                                            
  Upgrade: 1 packages                                                                                                            

  Total download: 16MB                                                                                                           

─────────────────────────────────────────────────────────────────────  

However this approach seemingly requires an env to already exist. Even if we added e.g. a --ignore-pins option, it would still require activating an env (I think).

I also tried a different approach:

(mamba) root@c52ca3073641:/work# ./build/micromamba/micromamba env create --no-pin --dry-run -f testupdate/environment.yml 

error    libmamba Could not lock non-existing path '/root/.mamba/pkgs'     

Transaction                                                                                                                      

  Prefix: /opt/conda/envs/joshtest3                                                                                              

  Updating specs:                                                                                                                

   - pandas==1.5.3

...
  + pandas               1.5.3  py311h2872171_1      conda-forge       14MB
...

I thought this might do it, but looks like it still respected the pin of pandas. I'm not sure what --no-pin does.

Any insight appreciated!