Giter Club home page Giter Club logo

whey-mixin's Introduction

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.

whey-mixin's People

Contributors

logicplace avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.