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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file whey_mixin-0.1.3.tar.gz.

File metadata

  • Download URL: whey_mixin-0.1.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10

File hashes

Hashes for whey_mixin-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ff74e7c56f5bee2047cdb90de84c38ccf3e70b170d267b8277a8c625e12e07a7
MD5 5cf0ffbd165df0476b44a29d954386a7
BLAKE2b-256 f1443fd9cabad6786aeb8970b1e26cc1c9b3112cf2ffbd8af982bac52d90a56f

See more details on using hashes here.

File details

Details for the file whey_mixin-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: whey_mixin-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10

File hashes

Hashes for whey_mixin-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d626b915841a53af7a9256129dd4d285bfcdbf8d4576a78418523c739fbd94e5
MD5 48b1d35e8235bd61adc60eb90381699c
BLAKE2b-256 2403a29398c30854265eb282b67c266038cce654a83ec618bf196ae5c1d23a4f

See more details on using hashes here.

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