Skip to main content

A simple builder hooks system for the Whey build system

Project description

whey-mixin

PyPI version PyPI status PyPI pyversions GitHub license

A plugin for Whey build system to add simple build steps

Usage

First, reassign your Whey builders to be handled by mixin. The following are supported, use as many or as few as you like.

[tool.whey.builders]
sdist = "whey_mixin_sdist"
wheel = "whey_mixin_wheel"
binary = "whey_mixin_binary"
exe = "whey_mixin_exe"
dmg = "whey_mixin_dmg"
deb = "whey_mixin_deb"
rpm = "whey_mixin_rpm"

Next, make the code for your hooks. We will place ours in a build_hooks.py file in the root directory of our project.

from whey.mixin import BuilderMixin

def build_messages(self: BuilderMixin):
  # This makes Babel a build dep
  from babel.messages.mofile import write_mo
  from babel.messages.pofile import read_po

  # pkgdir is the base folder for your module, constructed from
  # the root folder, tool.whey.source-dir, and tool.whey.package
  locales = self.pkgdir / "locales"
  if self.verbose:
    print("  Building messages")

  # Find all .po files for all languages
  for po in locales.glob("*/LC_MESSAGES/*.po"):
    with po.open("rt", encoding="UTF-8") as f:
      # po.parts[-3] extracts the language part of the path
      # po.stem is the domain
      catalog = read_po(f, po.parts[-3], po.stem)

    # Here we construct the path relative to the build directory
    # (/build by default). Be sure to create the subdirs!
    mo = self.build_dir / po.relative_to(self.project_dir).with_suffix(".mo")
    mo.parent.maybe_make(parents=True)
    with mo.open("wb") as f:
      write_mo(f, catalog)

    # This reports to Whey they we've written a file, so that
    # it will include it in the final package
    self.report_written(mo)

    if self.verbose:
      print("    Wrote language file:", mo)

Next, configure whey-mixin itself. You can supply global or builder-specific hooks. You may also specify the base class to use per builder. By default, it uses Whey's default SDistBuilder for sdist, and its WheelBuilder for wheel and binary; there is no default for anything else, so those must be specified.

Make sure to add any dependencies into you build deps

[build-system]
requires = ["whey", "whey-mixin", "Babel"]
build-backend = "whey"

[tool.whey.mixin]
hooks = [
  "build_hooks:build_messages"
]

[tool.whey.mixin.exe]
class = "my_builders:ExeBuilder"
hooks = []

Both hooks and class are entry points which specify the function or class to load, respectively. For use with this system, they will generally be relative to the root directory of your project. However, that's not required, and they can be from other modules as well.

Hooks specified in tool.whey.mixin run before build-specific hooks. They will run for every mixin builder, so if you don't want that, you will have to put the hook in individual build configs.

If a module defines its own named entry point that you wish to add hooks to, you may use the key entry-point instead of class to specify the entry point name.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whey_mixin-0.1.3.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

whey_mixin-0.1.3-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page