summaryrefslogtreecommitdiffstats
path: root/Doc/packaging/commandhooks.rst
blob: fd333574b584343c7c98d829c4d8742f2ca12d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.. TODO integrate this in commandref and configfile

=============
Command hooks
=============

Packaging provides a way of extending its commands by the use of pre- and
post- command hooks. The hooks are simple Python functions (or any callable
objects) and are specified in the config file using their full qualified names.
The pre-hooks are run after the command is finalized (its options are
processed), but before it is run. The post-hooks are run after the command
itself. Both types of hooks receive an instance of the command object.

See also global setup hooks in :ref:`packaging-setupcfg`.


Sample usage of hooks
=====================

Firstly, you need to make sure your hook is present in the path. This is usually
done by dropping them to the same folder where `setup.py` file lives ::

  # file: myhooks.py
  def my_install_hook(install_cmd):
      print "Oh la la! Someone is installing my project!"

Then, you need to point to it in your `setup.cfg` file, under the appropriate
command section ::

  [install_dist]
  pre-hook.project = myhooks.my_install_hook

The hooks defined in different config files (system-wide, user-wide and
package-wide) do not override each other as long as they are specified with
different aliases (additional names after the dot). The alias in the example
above is ``project``.