Skip to main content

ftw.profilehook

ftw.profilehook provides a hook for executing custom code after a generic setup profile is installed.

Motivation

We often use import steps for executing code after import a generic setup profile. Registering a lot of setup handlers is bad because it extends the import duration of every profile and the amount of import steps are limited in generic setup, causing bad effects when exceeded. Import steps are meant to import things from any profile, not for executing code after importing a specific profile. Because of these reasons ftw.profilehook exists and provides an easy method to solve this issue.

Usage

Add ftw.profilehook as dependency in your setup.py:

setup(...
      install_requires=['ftw.profilehook'])

Register your hook function in ZCML (configure.zcml):

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
    xmlns:i18n="http://namespaces.zope.org/i18n"
    xmlns:profilehook="http://namespaces.zope.org/profilehook"
    i18n_domain="my.package">

  <include package="ftw.profilehook" />

  <genericsetup:registerProfile
      name="default"
      title="my.package"
      directory="profiles/default"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      />

  <profilehook:hook
      profile="my.package:default"
      handler=".hooks.default_profile_installed"
      />

</configure>

Do things in your hook (hooks.py):

from my.package.interfaces import IMyRoot
from zope.component import alsoProvides


def default_profile_installed(site):
  mark_site_as_my_root(site)


def mark_site_as_my_root(site)
  if not IMyRoot.providedBy(site):
    alsoProvides(site, IMyRoot)

After your profile (my.package:default) is installed, your hook is executed.

Before-Import Hook

The standard hook (profilehook:hook) is executed after importing the profile. By using the profilehook:before_import_hook directive, you can register hooks which are executed before importing the profile.

<profilehook:before_import_hook
    profile="my.package:default"
    handler=".hooks.before_installing_default_profile"
    />

Changelog

1.3.0 (2018-09-28)

  • Fix error when uploading a tarball in portal_setup. [jone]

  • Add plone 5.1.x test cfg. [mathias.leimgruber]

1.2.1 (2016-05-12)

  • Fix compatibility with ftw.inflator. [jone]

1.2.0 (2016-05-11)

  • Support before-import hooks. [jone]

1.0.0 (2014-08-15)

  • Initial implementation. [jone]

Metadata

Release files for ftw.profilehook 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ftw.profilehook 1.3.0
File Size Uploaded Provenance
ftw.profilehook-1.3.0.tar.gz 13.9 kB Without provenance Details

Release files / ftw.profilehook-1.3.0.tar.gz

Download URL ftw.profilehook-1.3.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
99e1b984b7ac9e242a558da17608a5d0fcbc92bc16e6461900e8feb7806661d3
BLAKE2b-256 checksum
How to use checksums
ba25e2b3c9666e212942494816b521f2aeb198e24f499bb06c3fe97f2ac55cf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14

Security for ftw.profilehook 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page