Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
May 31, 2024

Conversation

ucodery
Copy link
Collaborator

@ucodery ucodery commented May 20, 2024

addresses #252

Copy link
Contributor

@kenseehart kenseehart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected indirection bug

examples/extension-hatch/examplePy/temperature.c Outdated Show resolved Hide resolved
examples/extension-hatch/examplePy/temperature.c Outdated Show resolved Hide resolved
static PyObject *
temperature_celsius_to_fahrenheit(PyObject *self, PyObject *args)
{
long celsius;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend adding fahrenheit variable and make the assignment correctly named (fahrenheit = ...celsius and celsius = ...fahrenheit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great suggestion. All seems to work now, thanks!

@ucodery ucodery marked this pull request as ready for review May 21, 2024 03:47
@lwasser
Copy link
Member

lwasser commented May 23, 2024

@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!

Copy link
Contributor

@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
Copy link
Member

lwasser commented May 23, 2024

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

Copy link
Contributor

@lwasser

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

@lwasser
Copy link
Member

lwasser commented May 23, 2024

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

Copy link
Contributor

@lwasser

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

Copy link
Member

@lwasser lwasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ucodery i have a few questions but we can merge this. my questions

  1. license - it's super tiny but should we be consistent in all of our packages?
  2. 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.

am i missing something?

'examplePy',
'c',
version: '0.1.dev0',
license: 'BSD-3',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use MIT throughout as that is the generally recommended (simpler) license? Choose a license suggests it and we decided to go that route too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't even notice. I took this part right from the scientific python example and didn't proof. I can change it to MIT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! yes lets change.

@@ -0,0 +1,3 @@
An example Python package used to support Python packaging tutorials
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ucodery could you add a bit more about how this works with meson-python? the key elements that make it work which i suspect are the meson.build files?

it seems like hatch just magically recognizes it and then builds for us. thank you AGAIN for this. i know this was a lot of work between you - @kenseehart and @ryanskeith !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "magic" is that this project declares mesonpy as its backend in pyproject.toml, which is a universal tool-agnostic standard. Hatch is compliant with PEP standards, thus it acquiesces and when asked to build the project uses mesonpy to create the wheel, which hatch can then do more tool-agnostic actions with, like install locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so related to below - what i'm remembering is folks arguing about hatch's approach to plugins ... i could probably find it for you. this might have been BEFORE pycon 2023 (so before we met) ... and that argument could actually have been around hatchling (the backend) and at the time hatch did NOT support other backends.

this makes sense to me now. thank you for the explanation. in this case i think you are saying hatch the front-end tool just runs build and build knows to use mesonpy which knows to find the meson.build file? so everything just works as it should.

@lwasser lwasser changed the title create meson example Add: hatch plus meson-python python package example to guidebook May 31, 2024
@ucodery
Copy link
Collaborator Author

ucodery commented May 31, 2024

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.

Copy link
Member

@lwasser lwasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ucodery once you've made the license update to MIT please merge! :)

@ucodery ucodery requested a review from lwasser May 31, 2024 19:58
@ucodery ucodery merged commit a59643b into pyOpenSci:main May 31, 2024
4 checks passed
@ucodery ucodery deleted the meson branch May 31, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants