场景:
- 我们维护一些公司内部使用的 conda 软件包
- 对于其中一些软件包,我们对它们的使用地点和使用方式知之甚少(用户在本地 python 安装中下载并安装这些软件包)
- 为了更好地支持使用这些软件包的用户和项目,我们希望详细了解这些软件包的用法。
我想在用户安装软件包时在标准输出上显示一条消息:
Please let us know that you're using the xxx package: send an e-mail to <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="153b3b3b55706d74786579703b767a78" rel="noreferrer noopener nofollow">[email protected]</a>, notify us on the teams channel, or update the wiki page ... directly. Thanks!
问题:
- 制作
conda install
的最简单方法是什么?成功安装软件包后显示自定义消息?最好能在 Linux 和 Windows 上运行。
最佳答案
这可以通过 post-link
script in your recipe. 来完成如文档中所述,您必须将消息写入 ${PREFIX}/.messages.txt
,而不是 stdout
或 stderr
。
食谱示例:
foobar-recipe/
├── meta.yaml
├── post-link.bat
└── post-link.sh
# meta.yaml
package:
name: foobar
version: 0.1
#!/bin/bash
# post-link.sh
cat << EOF >> ${PREFIX}/.messages.txt
*****************************
Thanks for installing foobar!
*****************************
EOF
(对于 Windows,实现 post-link.bat
。)
构建它:
$ conda build foobar-recipe
测试安装:
$ conda create -y -n test-foobar --use-local foobar
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /opt/miniconda/envs/test-foobar
added / updated specs:
- foobar
The following NEW packages will be INSTALLED:
foobar opt/miniconda/conda-bld/osx-64::foobar-0.1-0
Preparing transaction: done
Verifying transaction: done
Executing transaction: /
*****************************
Thanks for installing foobar!
*****************************
done
#
# To activate this environment, use
#
# $ conda activate test-foobar
#
# To deactivate an active environment, use
#
# $ conda deactivate
关于python - 安装 conda 包后在标准输出上显示自定义消息的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65331382/