pyOpenSci / python-package-guide

scientific Python package recommendations & guidance curated by pyOpenSci
https://www.pyopensci.org/python-package-guide/
Other
70 stars 43 forks source link

Add: hatch plus meson-python python package example to guidebook #274

Closed ucodery closed 1 month ago

ucodery commented 1 month ago

addresses #252

lwasser commented 1 month ago

@all-contributors please add @ryanskeith

-- Ryan THANK YOU for your help with this pr. Cheng shared your GH handle with me! without you @kenseehart and @ucodery i don't think we would have gotten this solution working for some time. thank you all!

hey @ucodery i know we have a LOT of pr's to go through - i'm just adding ryan here as a contributor since he was so so helpful in getting this package to correctly install. Ken more from me as well once i've caught up a bit more! you all are amazing! i know the community will really benefit from this PR in a BIG WAY!

allcontributors[bot] commented 1 month ago

@lwasser

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

lwasser commented 1 month ago

@all-contributors please add @ryanskeith @kenseehart for code, review

allcontributors[bot] commented 1 month ago

@lwasser

I've put up a pull request to add @ryanskeith! :tada:

lwasser commented 1 month ago

@all-contributors please add @kenseehart for code, review

allcontributors[bot] commented 1 month ago

@lwasser

I've put up a pull request to add @kenseehart! :tada:

ucodery commented 1 month ago

This is a hatch question - i had understood that there was something more complex about hatch that required plugins or something custom to be able to use hatch with other back ends? But in this case, we were running hatch build to build the package and then we were installing it and it ran.

to me (bare with me i'm still learning about extensions) - i don't see any plugins here just a meson.build file (well two of them) and a pyproject.toml + init file.

It is not more complex than you perceive. To build a Python distribution that links to foreign code, the author must choose a backend that supports compiling/ linking to that foreign code (mesonpy being a prime example). Once chosen this backend must be designated in the pyproject.toml build-system table and also any conventions of that backend must be followed (so two meson.build files had to be written here. This has nothing to do with Python or PyPA etc but has to do with the upstream meson project).

Once that is done the author (and any uses of the source) are free to use any frontend they want. Here we used Hatch and because PEP-517/518 are almost universally supported it just works. Hatch has always worked this way.

What I think you are remembering, and what is a potentially more complex setup, is hatchlings support of plugins. (remember hatch != hatchling). By using plugins it is possible to use hatchling as the build-backend and still compile extension modules. The first example of this that has apparently been completed (I have not used any hatch plugins) is scikit-build-core's plugin.