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

250 Views Asked by At

The scenario:

  • We maintain some conda packages that are used internally in the company
  • For some of these packages we have little knowledge of where and how the packages are used (the users download and install the packages on their local python installations)
  • To better support the users and projects that consume the packages, we would like to know more about the usages of these packages.

I would like to display a message on stdout when the user installs a package:

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

Question:

  • What would be the easiest way to make conda install display a custom message upon successful package installation? Preferably something that works on both Linux and Windows.
1

There are 1 best solutions below

0
On BEST ANSWER

This can be done with a post-link script in your recipe. As noted in the documentation, you must write your message to ${PREFIX}/.messages.txt, not stdout or stderr.

Example recipe:

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

(For Windows, implement post-link.bat.)

Build it:

$ conda build foobar-recipe

Test Install:

$ 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