python - 安装 conda 包后在标准输出上显示自定义消息的最简单方法

标签 python conda packaging conda-build

场景:

  • 我们维护一些公司内部使用的 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,而不是 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

关于python - 安装 conda 包后在标准输出上显示自定义消息的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65331382/

相关文章:

perl - 使用 perl 包从 YAML 文件创建 conda 环境

python-3.x - 在我的 ubuntu 服务器上以管理员身份运行 conda install,我得到 "Missing write permissions:/home/ubuntu/anaconda3"

python - 设置 PyCharm 远程 conda 解释器

python 跨平台应用程序

java - 小程序无法在浏览器上运行

python - 如何在 python 中使用 pdf2image 将 pdf 从 url 转换为图像?

javascript - Django POST 请求中禁止的 CSRF token 丢失或不正确,即使我在表单中有 csrf token

python - 如何将 Pandas 中的单个时间序列转换为多个序列

python - 多列表理解

javascript - 将 Bower 包从私有(private) Git 存储库注册到私有(private) Bower 主机