Skip to content

Question: Simple example #14

@peekxc

Description

@peekxc

This is more of a question born out of my own ignorance on Python's build internals. I would like to use extensionlib to build native extension modules interfaced with pybind11. There is a simple example of how to do this with setuptools + setup.py (and other build tools). I'm trying to figure out how to do this with extensionlib + hatch but I can't figure it out.

  1. Do I use the custom build hook to compile native extensions, or do I need to make my own build-hook plugin?

Something like:

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomHook(BuildHookInterface):
    def initialize(self, version, build_data):
        if self.target_name == 'wheel':
            ...
  1. ...or does extensionlib scaffold these build hooks via entry-points? If I have something like this:
# pyproject.toml
...
[project.entry-points.extensions]
hatch_build = "my-pkg:ExampleExtensionModules"

then this should instantiate a ExampleExtensionModules class in a hatch_build.py file, yes? And then build things with the build runner? Something like:

# hatch_build.py
from extension.runner import BuildRunner
from extension.interface import ExtensionModules

class ExampleExtensionModules(ExtensionModules):
    def __init__(self, name: str, root: str, metadata: dict, config: dict):
      super().__init__(name, root, metadata, config)
      runner = BuildRunner('.', ...)
      ....

    def inputs():
      return(["src/my_pkg/ext/"]) # this stores my __init__.py + extension module source files 

    ....

I can't seem to parse how to connect the build script with the pyproject.toml file / with hatch build; hatch build --ext silently returns without error and without building anything in the simple example I'm trying to get going now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions