joshua-auchincloss / hatch-cython

cython hooks for hatch
MIT License
22 stars 3 forks source link

question: dynamic build targets #55

Open PhilipVinc opened 3 months ago

PhilipVinc commented 3 months ago

Hello,

I have a complex setup.py script that I would like to transition to hatch-python and modularise a bit.

The script is complicated because it declares 3 different Cython extensions (cpu_bridge, cuda_bridge, amd_bridge...) where the first one (cpu) is mandatory and always built, while the others may or may not be built depending on the environment (whether we find cuda or amd packages/libraries installed).

Is there a way to implement this through the include_somelib logic? Maybe a function hook that returns a boolean saying wether the extension should or not be built?

joshua-auchincloss commented 2 months ago

Hey @PhilipVinc , thanks for the question - interesting use case (makes sense for what we should support). At the moment, I believe include_* should support the functionality you are looking for. You'll want to create a scripts/ directory with the {cuda,amd} detection logic in dedicated callables - if it has it, return the paths to the files to compile as a list, else returning an empty list. In hatch.toml, you'll then want something along the lines of:

# hatch.toml

[build.hooks.wheel.cython.options]

include_cuda = { pkg = "scripts.extras", include = "include_cuda" }

This should add the additional build targets for compilation. Let me know if you have issues with this type of configuration, happy to expand functionality to align with how people want to use this library.