从meta.yaml创建和更新conda环境
cenv-tool的Python项目详细描述
Conda环境管理器:cenv
由于meta.yaml(必需)中存在冗余的依赖关系信息 创建conda包)和environment.yml(作为定义文件 对于开发和生产过程中的conda环境,cenv (缩写为conda-env-manager)是为了使meta.yaml 唯一相关的文件,并从 此meta.yaml中的定义。 要创建/更新的conda环境的名称在节中定义 extra和meta.yaml中的变量env_name。
CENV运行的步骤:
- 如果环境已经存在,则备份创建 移除以前的环境。
- 创建在meta.yaml中定义的环境。 如果在创建过程中发生任何故障并且创建了备份,则 可以使用命令重置备份版本。
- 如果在配置文件中启用environment.yml,则在创建后导出 /环境更新。
CENV的使用将conda命令减少为使用以下命令:
- conda activate ...激活环境
- conda deactivate停用环境
- conda info显示有关当前激活环境的信息
- conda search ...在conda中搜索包的可用性 频道。
- conda remove -n ... --all删除环境
- cenv创建/更新环境
文件
有关完整文档,请参见 cenv documentation。
安装
使用pip安装cenv:
pip3 install cenv_tool
现在运行init_cenv创建相关的配置文件并添加 自动激活并自动更新外壳函数到.bashrc/.zshrc。
自动激活和自动更新
默认情况下,这些功能将被停用,即使通过 正在运行init_cenv。
自动激活功能
自动激活功能激活名为 extra-位于conda-build/meta.yaml的meta.yaml中的节,如果 环境存在。 要激活自动激活功能,请运行:
autoactivate_toggle
自动更新功能
自动更新检查meta.yaml的内容是否更改。 当前状态以md5sum的形式存储在conda-build/meta.md5中。 如果更改,则调用CENV进程。
对于自动更新功能运行:
autoupdate_toggle
使用量
创建或更新项目conda环境所需的所有步骤如下 自动运行:
cenv
注意:
If you use cenv, each environment should only be created, updated and modified using ^{tt3}$! This means the commands ^{tt26}$, ^{tt27}$ are not used anymore. Changes of the dependencies of the environment are defined inside the ^{tt1}$ and are applied by using ^{tt3}$.
This means:
- 需要新的依赖项=>;将其添加到meta.yaml并运行cenv。
- 不再需要依赖项=>;将其从meta.yaml中删除并运行 cenv。
- 需要其他版本的依赖项=>;更改依赖项的版本 在meta.yaml中并运行cenv。
提取有关项目conda环境的所需信息 来自meta.yaml。 此meta.yaml应位于 ./conda-build/meta.yaml。 项目配置在meta.yaml的extra部分中定义。 在那里,您可以在 env_name。 此外,您还可以定义仅在开发过程中需要的需求,而不是 包含在生成的conda包中。 这些要求必须在dev_requirements-部分中定义。
必须将meta.yaml的所有其他部分定义为默认值。
对于CENV有效的meta.yaml应该如下所示:
{%set data = load_setup_py_data() %}package:name:"example_package"version:{{data.get("version")}}source:path:..build:build:{{environ.get('GIT_DESCRIBE_NUMBER',0)}}preserve_egg_dir:Truescript:python -m pip install --no-deps --ignore-installed .requirements:build:-python 3.6.8-pip-setuptoolsrun:-python 3.6.8-attrs >=18.2-jinja2 >=2.10-ruamel.yaml >=0.15.23-six >=1.12.0-yaml >=0.1.7-marshmallow >=3.0.0rc1*test:imports:-example_packageextra:env_name:exampledev_requirements:-ipython >=7.2.0
注意:
In the ^{tt42}$ the minimal version of each package has to be defined! The same is required for the ^{tt40}$-section. Not defining a version will not create or update a conda-environment, because this is not the purpose of the conda-usage. The validity of the ^{tt1}$ is checked in ^{tt3}$ using the ^{tt46}$ package. You can additionally add upper limits for the version like the following: ^{tt47}$
如果运行CENV,则环境将从内部定义创建/更新 这个meta.yaml。 创建以前环境的备份可确保撤消更改 如果在环境重建过程中发生任何错误。
注意:
^{tt3}$ can only update the environment if it is not activated. So ensure the environment to be deactivated before running ^{tt3}$.
默认情况下,将conda环境定义导出到environment.yml 已关闭。 如果要启用此功能,则需要修改 ~/.config/cenv.yml如配置部分所述。
cenv命令的输出示例:
┣━━ Cloning existing env as backup ... ┣━━ Removing existing env ... ┣━━ Creating env ... ┣━━ Removing backup ... ┗━━ Exporting env to environment.yml ...
cenv
要创建用于开发CENV的环境,请手动运行预提交挂钩:
pyenv local3.7.3 pre-commit run --all-files poetry shell