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

on main: conda-lock install fails with "Cannot find platform in lockfile" if lock filename does not end with conda-lock.yml #154

Open
lesteve opened this issue Feb 21, 2022 · 3 comments
Labels
question Further information is requested

Comments

@lesteve
Copy link
Contributor

lesteve commented Feb 21, 2022

On commit 67f8da0 (latest commit at the time of writing). This is not a real blocker since I can make sure conda lock files end with conda-lock.yml but it is a surprising behaviour.

To reproduce:

cat << EOF >! test-environment.yml                      
channels:
  - conda-forge

dependencies:
  - pyyaml          
EOF

conda-lock -p linux-64 -f test-environment.yml --lockfile lock.yml
conda-lock install -n new-test-env lock.yml

Output:

Locking dependencies for ['linux-64']...
 - Install lock using: conda-lock install --name YOURENV lock.yml
Traceback (most recent call last):
  File "/home/lesteve/miniconda3/envs/conda-lock/bin/conda-lock", line 33, in <module>
    sys.exit(load_entry_point('conda-lock', 'console_scripts', 'conda-lock')())
  File "/home/lesteve/miniconda3/envs/conda-lock/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/lesteve/miniconda3/envs/conda-lock/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/lesteve/miniconda3/envs/conda-lock/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lesteve/miniconda3/envs/conda-lock/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lesteve/miniconda3/envs/conda-lock/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/lesteve/dev/conda-lock/conda_lock/conda_lock.py", line 1158, in install
    do_validate_platform(lockfile)
  File "/home/lesteve/dev/conda-lock/conda_lock/conda_lock.py", line 136, in do_validate_platform
    platform_lockfile = extract_platform(lockfile)
  File "/home/lesteve/dev/conda-lock/conda_lock/conda_lock.py", line 117, in extract_platform
    raise RuntimeError("Cannot find platform in lockfile.")
RuntimeError: Cannot find platform in lockfile.

There are two places in conda_lock/conda_lock.py that relies on lock_file.endswith(DEFAULT_LOCKFILE_NAME).

For the record I tried --no-validate and I don't really understand the output (there are some warnings about sections being ignored, plus it seems to solve the environment which I don't really expect when I create an environment from a lock file)

❯ conda-lock install -n new-test-env lock.yml --no-validate-platform 
INFO:root:EnvironmentSectionNotValid: The following sections on '/tmp/lock.yml' are invalid and will be ignored:
INFO:root: - metadata
INFO:root: - package
INFO:root: - version
INFO:root:
INFO:root:Collecting package metadata (repodata.json): ...working... done
INFO:root:Solving environment: ...working... done
INFO:root:Preparing transaction: ...working... done
INFO:root:Verifying transaction: ...working... done
INFO:root:Executing transaction: ...working... done
INFO:root:#
INFO:root:# To activate this environment, use
INFO:root:#
INFO:root:#     $ conda activate new-test-env
INFO:root:#
INFO:root:# To deactivate an active environment, use
INFO:root:#
INFO:root:#     $ conda deactivate
INFO:root:
@mariusvniekerk
Copy link
Collaborator

mariusvniekerk commented Feb 21, 2022

Due to the fact that conda-lock supports multiple output formats it relies in a rather large part on the extension used in specifying the output format. If you want to have various named lockfiles i would recommend names like

foo.conda-lock.yml

The actual bug here is allowing creation of a unified lockfile without the correct extension.

@lesteve
Copy link
Contributor Author

lesteve commented Feb 22, 2022

OK thanks for your answer! Since I am not aware of conda-lock details, I am kind of giving you the naive user vibe 😉

@mariusvniekerk mariusvniekerk added the question Further information is requested label Mar 2, 2022
@basnijholt
Copy link
Contributor

basnijholt commented Jan 6, 2023

I also just ran into this problem.

The actual bug here is allowing creation of a unified lockfile without the correct extension.

I couldn't actually create a lock file:

conda-lock lock --file qms-lab.yml -c file://$PWD/local_mirror5 -c conda-forge -c defaults -p linux-64  --lockfile qms-lab.lock.yml

gave me:

  File "/nfshome/basnijholt/mambaforge/bin/conda-lock", line 10, in <module>
    sys.exit(main())
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 1341, in lock
    lock_func(
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 1071, in run_lock
    make_lock_files(
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 407, in make_lock_files
    lock_content = lock_content | create_lockfile_from_spec(
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 349, in __or__
    return other.__ror__(self)
  File "/nfshome/basnijholt/mambaforge/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 360, in __ror__
    assert self.metadata.channels == other.metadata.channels
AssertionError

Nothing here indicated to me that the wrong name was used.

I manually renamed the file, and after getting the same error message as reported above, I found this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants