Éric Araujo | 823759e | 2011-06-04 18:46:25 +0200 | [diff] [blame] | 1 | .. TODO integrate this in commandref and configfile |
| 2 | |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 3 | ============= |
| 4 | Command hooks |
| 5 | ============= |
| 6 | |
| 7 | Packaging provides a way of extending its commands by the use of pre- and |
| 8 | post- command hooks. The hooks are simple Python functions (or any callable |
| 9 | objects) and are specified in the config file using their full qualified names. |
| 10 | The pre-hooks are run after the command is finalized (its options are |
| 11 | processed), but before it is run. The post-hooks are run after the command |
| 12 | itself. Both types of hooks receive an instance of the command object. |
| 13 | |
Éric Araujo | 823759e | 2011-06-04 18:46:25 +0200 | [diff] [blame] | 14 | See also global setup hooks in :ref:`packaging-setupcfg`. |
| 15 | |
| 16 | |
Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 17 | Sample usage of hooks |
| 18 | ===================== |
| 19 | |
| 20 | Firstly, you need to make sure your hook is present in the path. This is usually |
| 21 | done by dropping them to the same folder where `setup.py` file lives :: |
| 22 | |
| 23 | # file: myhooks.py |
| 24 | def my_install_hook(install_cmd): |
| 25 | print "Oh la la! Someone is installing my project!" |
| 26 | |
| 27 | Then, you need to point to it in your `setup.cfg` file, under the appropriate |
| 28 | command section :: |
| 29 | |
| 30 | [install_dist] |
| 31 | pre-hook.project = myhooks.my_install_hook |
| 32 | |
| 33 | The hooks defined in different config files (system-wide, user-wide and |
| 34 | package-wide) do not override each other as long as they are specified with |
| 35 | different aliases (additional names after the dot). The alias in the example |
| 36 | above is ``project``. |