安装我的 conda 包后在 stdout 上显示自定义消息的最简单方法

Simplest way to display custom message on stdout upon install of my conda package

场景:

我想在用户安装软件包时在标准输出上显示一条消息:

Please let us know that you're using the xxx package: send an e-mail to ...@example.com, notify us on the teams channel, or update the wiki page ... directly. Thanks!

问题:

这可以通过 post-link script in your recipe. 完成,如文档中所述,您必须将消息写到 ${PREFIX}/.messages.txt,而不是 stdoutstderr

示例食谱:

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