conda-incubator / conda-project

Tool for encapsulating, running, and reproducing projects with Conda environments
https://conda-incubator.github.io/conda-project/
BSD 3-Clause "New" or "Revised" License
28 stars 10 forks source link

[feat] initialize from an existing environment #162

Closed AlbertDeFusco closed 4 months ago

AlbertDeFusco commented 4 months ago

In this PR

Using the --from-environment <name or prefix path> flag the environment.yml and conda-lock.<env-name>yml files will be generated from an existing conda environment.

The conda-lock.<env-name>.yml for the current platform is constructed by performing a full conda env export so that the environment is captured as-is into the lockfile. Only packages for the current platform are written in to the lock. When someone attempts to install on another platform conda-project will automatically lock the missing platforms, but not modify the original platform, unless the environment.yml file was changed.

The environment.yml captures the requested conda and pip packages as follows. You'll see that conda packages are prefixed with its channel and the full version is captured in the spec even if a specific version was not originally requested. This helps keep the environment close to the original if the original platform is re-locked and when other platforms are locked.

You'll see that all four major platforms are listed in the environment.yml, but a full cross-platform solve is not attempted by default. The user could do conda project init --from-environment <env-or-path> --lock, which will capture the current platform according to the above procedure and then lock the remaining platforms.

name: data-science-work
channels:
  - defaults
  - anaconda-cloud
  - conda-forge
dependencies:
  - defaults::hvplot=0.9.2
  - defaults::pip=23.3.1
  - defaults::scikit-learn=1.3.0
  - defaults::pandas=2.1.4
  - conda-forge::wheel-filename=1.4.1
  - defaults::panel=1.3.8
  - defaults::python=3.11.5
  - defaults::python-libarchive-c=2.9
  - defaults::ipykernel=6.25.0
  - defaults::intake=0.6.8
  - conda-forge::ratelimit=2.2.1
  - pip:
    - anaconda-catalogs==0.2.0
    - torch==2.2.2
variables:
prefix: /Users/adefusco/Applications/miniconda3/envs/data-science-work
platforms:
  - osx-arm64
  - linux-64
  - osx-64
  - win-64
codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.23%. Comparing base (8aab898) to head (1dabb92). Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #162 +/- ## ========================================== + Coverage 97.89% 98.23% +0.33% ========================================== Files 9 9 Lines 996 1074 +78 ========================================== + Hits 975 1055 +80 + Misses 21 19 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jjhelmus commented 4 months ago

LGTM