conda / conda-lock

Lightweight lockfile for conda environments
https://conda.github.io/conda-lock/
Other
495 stars 103 forks source link

Fix logic for running without --file sources #231

Open riccardoporreca opened 2 years ago

riccardoporreca commented 2 years ago

Running w/o sources for dependencies is allowed by design (and would use the sources from the lockfile).

However, the CLI interface checks the existence of an environment.y(a)ml file for such cases, as this is the default:

https://github.com/conda-incubator/conda-lock/blob/7d9bd6d67d59fdd30d92a2ace3ee344aafa6a2b1/conda_lock/conda_lock.py#L1134-L1143

How to reproduce

# environment-foo.yml
channels:
- conda-forge
dependencies:
- python=3.8.12
- numpy=1.22.3
platforms:
- win-64
conda-lock -f environment-foo.yml --lockfile conda-lock.yml
# Locking dependencies for ['win-64']...
# INFO:conda_lock.conda_solver:win-64 using specs ['python 3.8.12.*', 'numpy 1.22.3.*']

Running with lock-file only shows the help because no environment.y(a)ml exists:

conda-lock --lockfile conda-lock.yml
# Usage: conda-lock lock [OPTIONS]
# [...]

If we just create an empty environment.yml, the CLI gets past the check above and the rest behaves as expected

conda-lock --lockfile conda-lock.yml
# Locking dependencies for ['win-64']...
# INFO:conda_lock.conda_solver:win-64 using specs ['python 3.8.12.*', 'numpy 1.22.3.*']
riccardoporreca commented 2 years ago

Actually, a similar logic is implemented in run_lock() (introduced in df566dcfdd1ba4e127efe27649748a088b573d97), which however accounts for the presence of the lock-file:

https://github.com/conda-incubator/conda-lock/blob/7d9bd6d67d59fdd30d92a2ace3ee344aafa6a2b1/conda_lock/conda_lock.py#L920-L944

This should make the logic in the CLI unnecessary (although we might want to rely on DEFAULT_FILES instead of allowing only for environment.yaml)