Package: indico-patcher
Indico PatcherThe Swiss Army knife forIndicoplugin development.Indico plugin development primarily relies onflask-pluginengine,Jinjatemplate hooks or coresignalsto extend and modify system functionality. This, however, falls short in many other cases. Indico Patcher offers a clean interface to patch Indico code at runtime, allowing for things such as:Adding or overriding properties and intercepting methods in classesReordering, modifying and removing fields in WTForms formsAdding new columns and relationships to SQLAlchemy modelsAdding new members to EnumsFor more examples and usage information, please refer to thepatching guide. For general information about Indico plugin development, please refer to theofficial guide. Not yet supported cases are tracked inTODO.md.InstallationIndico Patcher is available on PyPI asindico-patcherand can be installed withpip:pipinstallindico-patcherUsageIndico Patcher is a library designed to be used by Indico plugins. It provides apatchfunction that can be used as a decorator to patch Indico classes and enums.fromindico_patcherimportpatchThe@patchdecorator will inject the members defined in the decorated class into a given class or enum. Check below for some examples.ExamplesAdding a new column and a relationship to an already existing SQLAlchemy model:@patch(User)class_User:credit_card_id=db.Column(db.String,ForeignKey('credit_cards.id'))credit_card=db.relationship('CreditCard',backref=backref('user'))Adding a new field to an already existing WTForms form:@patch(UserPreferencesForm)class_UserPreferencesForm:credit_card=StringField('Credit Card')defvalidate_credit_card(self,field):...Adding a new member to an already defined Enum:@patch(UserTitle,padding=100)class_UserTitle(RichIntEnum):__titles__=[None,'Madam','Sir','Rev.']madam=1sir=2rev=3For more examples and usage information, please refer to thepatching guide.Caveats[!WARNING]
With great power comes great responsibility.Runtime patching is a powerful and flexible strategy but it will lead to code that may break without notice as the Indico project evolves. Indico Patcher makes patching Indico dangerously easy so keep in mind a few things when using it.Think of Indico Patcher as a last resort tool that abuses Indico internal API. Indico developers may change or completely remove the classes and enums that you are patching at any time.If you can achieve the same result with a signal or a template hook, you should probably do that instead. These are considered stable APIs that Indico developers will try to keep backwards compatible or communicate breaking changes.If the signal or hook that you need doesn't exist, consider contributing it to Indico viapull requestor asking for it in theIndico forumor the official#indico channel.DevelopmentIn order to developindico-patcher, install the project and its dependencies in a virtualenv. This guide assumes that you have the following tools installed and available in your path:git(available in most systems)make(available in most systems)poetry(installation guide)pyenv(installation guide)First, clone the repository locally with:gitclonehttps://github.com/unconventionaldotdev/indico-patchercdindico-patcherBefore creating the virtualenv, make sure to be using the same version of Python that the development of the project is targeting. This is the first version specified in the.python-versionfile and you can install it withpyenv:pyenvinstallYou may now create the virtualenv and install the project with its dependencies in it withpoetry:poetryinstallContributingThis project uses GitHub Actions to run the tests and linter on every pull request. You are still encouraged to run the tests and linter locally before pushing your changes.Run linter checks with:poetryrun--makelintRun tests with:poetryrun--maketestRun tests against all supported Python versions with:tox