3.7. Hooks#
While most aspects of your project and its workflows
are already highly customizable via the provided control center configurations,
there may still remain some complex routines you wish to add
that are not covered by the available options.
Therefore, PyPackIT also allows you to add custom plugins for maximum flexibility.
These can hook into different stages of your workflows to perform arbitrary tasks.
Plugins are defined in Python modules added to a subdirectory named hooks
located at the root of the control center directory.
For each workflow, PyPackIT looks for a specific Python file in this directory.
Each file must contain a class named Hooks
with a predefined signature,
which will be instantiated at the beginning of the corresponding workflow.
This class must define specific methods for hooking into certain stages of the workflow.
At each stage, if a corresponding method exists, it will be called with a set of relevant arguments.
Also, before running your hooks, PyPackIT will look for a requirements.txt
file
in the hooks
directory, and will install the specified packages using pip
.
Control Center’s hooks
Subdirectory Structure
Note that in contrast to the control center YAML files,
the hooks
subdirectory and its constituent files
must be exactly named and located as described here.
You are however free to add any other additional files or subdirectories.
For example, if you want to implement multiple complex hooks,
you can modularize your code by creating a Python package in the hooks
directory,
adding it to your hooks/requirements.txt
file,
and importing it in your hook modules.
🏠 <REPOSITORY ROOT> ┃ ┣ 🗂 .control ┃ ┃ ┃ ┣ 🗂 hooks ┃ ┃ ┃ ┃ ┃ ┣ 📄 cca.py ┃ ┃ ┃ ┃ ┃ ┣ 📄 cca_inline.yaml ┃ ┃ ┃ ┃ ┃ ┗ 📄 requirements.txt ┃ ┗ ... ┗ ...
Note that the cca_inline.py
module serves a slightly different purpose,
which is documented in the Templating section.
3.7.1. CCA#
CCA plugins hook into the Continuous Configuration Automation pipeline
that processes your control center configuration files to synchronize your repository.
They can be added to the Hooks
class in the cca.py
module,
which is included in your repository by default.
This class can define 9 public methods, corresponding to the 9 stages of the CCA pipeline.
No return value is expected from any of the methods, but most are given mutable input arguments
that they may modify in-place.