mamba-org / mamba

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

Handle <TOKEN> in conda-lock v2 files #1923

Open jonashaag opened 2 years ago

jonashaag commented 2 years ago
# Create environment.yml:
echo 'channels: [some-authenticated-channel, conda-forge]' > environment.yml
echo 'dependencies: [some-authenticated-package]' >> environment.yml

# Create lock file:
conda-lock --platform osx-arm64

# Tokens are represented as <TOKEN> in conda-lock.yml:
grep TOKEN conda-lock.yml
# Note that if there are multiple distinct tokens (by multiple authenticated channels),
# ALL of them are represented as <TOKEN>

# This fails:
micromamba create -f conda-lock.yml -n lock123
jonashaag commented 2 years ago

cc @ThomasBlauthQC @pavelzw

sanzoghenzo commented 2 years ago

I think I'm hitting the same issue here, but I'm not sure it is the exact problem.

To expand on this (and to have confirmation from @jonashaag that it has the same problem), my environment look like this:

name: test-env
channels:
  - https://my-repo.local/t/$QUETZ_API_KEY/channels/stable
  - conda-forge
dependencies: [...]

since I specified an environment variable, my conda-lock.yml doesn't use <TOKEN>, but correctly reports the envvar:

metadata:
  channels:
    - url: https://my-repo.local/t/$QUETZ_API_KEY/channels/stable
      used_env_vars:
        - QUETZ_API_KEY
    - url: conda-forge
      used_env_vars: []
  content_hash:
    linux-64: 7990ba69418de229c9b451e474195eb23a06c8e535f5842ec9d8eeff3e051955
  platforms:
    - linux-64

if I try to use this lock file, though, I got

$ micromamba create -p /tmp/env --yes --file conda-lock.yml
...
Transaction starting
critical libmamba Download error (6) Couldn't resolve host name [https://my-repo.local$QUETZ_API_KEY/channels/stable/noarch/pysws-utils-2.5.2-pypy_0.tar.bz2]
    Could not resolve host: my-repo.local$QUETZ_API_KEY

It looks a lot like this conda issue I've stumbled upon some time ago, in which I suggested to change the token regex to /t/(.*?)/ and then expand the environment variable.

Of course, the regex could be left as is if the environment variable is expanded before the regex parsing!