Custom build steps / Moving Bokeh off setup.py

Project Jupyter had a similar need and just switched to Hatch.

You could configure a custom build hook by making a file named by default hatch_build.py:

from hatchling.builders.hooks.plugin.interface import BuildHookInterface

class CustomHook(BuildHookInterface):
    def initialize(self, version, build_data):
        if self.target_name == 'wheel':
            ...
        elif self.target_name == 'sdist':
            ...

then in pyproject.toml put:

[tool.hatch.build.hooks.custom]

or to be explicit:

[tool.hatch.build.targets.wheel.hooks.custom]
[tool.hatch.build.targets.sdist.hooks.custom]

edit: also for:

Hatch creates reproducible sdists

4 Likes