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: text on Hatch backend compatibility #228

Merged
merged 7 commits into from
Apr 15, 2024

Conversation

ucodery
Copy link
Collaborator

@ucodery ucodery commented Apr 8, 2024

closes #111



In this packaging guide we recommend using `hatch` along with it's preferred back-end `hatchling`. One reason to use
hatch with an alternate back-end is for creating an extension module. A Python extension module is one that is make up,
either in part or entirely, of compiled code. In this case the back-end chosen (such as `meson-python`) must know how to
Copy link
Member

Choose a reason for hiding this comment

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

oooh this is good @ucodery have you actually tested this by chance? i know a while back i tested pdm but i haven't had a change to test out hatch with meson-python (which a lot of the scientific community is using). but this is a really excellent addition to this page!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did no testing for this PR 🙈. I've built extension modules with setuptools or maturin but never coupled with hatch, and never used meson-Python for anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, I think I tested that everything works as expected. It's a little meta, but meson-python the project uses mesonpy as it's own backend. So I cloned the repo, set up a new virtualenv with only hatch in it, and built meson-python with no change to its pyproject.toml.

Copy link
Member

Choose a reason for hiding this comment

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

wow thank you!! you rock!

i'm curious - did your pyproject.toml look something like this:

https://github.com/pyOpenSci/examplePy/blob/main/example6_pdm_meson/pyproject.toml

essentially that was my playing around with building using meson-python / mesonpy and pdm. please also note that i've only worked on pure python packages so my knowledge of complex builds is minimal!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used the pyproject.toml exactly as it came down from git - so it looked like this https://github.com/mesonbuild/meson-python/blob/main/pyproject.toml.
Using hatch only as a front-end means that it is in my python environment, but not necessarily defined in project code at all. (Not at all in this case. If the project was making use of hatch environments but not using hatchling, then the pyproject.toml would have a reference to both build tools).

Copy link
Collaborator

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Lovely! Thank you @ucodery

@@ -13,7 +13,32 @@ back-end tools.

1. **Pure-python packages:** these are packages that only rely on Python to function. Building a pure Python package is simpler. As such, you can chose a tool below that has the features that you want and be done with your decision!

2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-python extensions, then you need to select a build back-end tool that allows you to add additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. In this case, you could use setuptools. However, we suggest that you chose build tool that supports custom build steps such as Hatch with Hatchling or PDM. PDM is an excellent choice as it allows you to also select your build back-end of choice. We will discuss this at a high level on the complex builds page.
2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-python extensions, then you need to select a build back-end tool that allows you to add additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. We suggest that you chose build tool that supports custom build steps like Hatch.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-python extensions, then you need to select a build back-end tool that allows you to add additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. We suggest that you chose build tool that supports custom build steps like Hatch.
2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-Python extensions, then you need to select a build backend tool that allows additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool (such as JavaScript) to support your workflow, you will need to select a tool that supports additional build setups. We suggest that you chose build tool that supports custom build steps like Hatch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A small nit (@lwasser): what is our preferred spelling of front-end and back-end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW I was following the style in this file which was consistently -end.

Also not sure why you added JavaScript? Can JS build python projects and is this common? I was referring to frontends like build and pip.

Copy link
Member

Choose a reason for hiding this comment

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

i think i tend to use the - as @ucodery this would be another good place to have that vale style checker. as many including Jeremiah have pointed out I often forget which style we prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I've made all the requested changes, except everything still uses"-end".

(except that one time build-backend is used. A reason for a style change @lwasser ? "build-back-end" is probably not what we want 🤣 )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah @ucodery ...I was thinking about JupyterLab and how we distribute JS code and Python code. All looks good to me.

Copy link
Member

Choose a reason for hiding this comment

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

@ucodery i think build-backend is good ... i'm sorry i think i missed that it was spelled build-back-end 😆 agreed that is not what we want. let me actually look at the text here ...

Copy link
Member

Choose a reason for hiding this comment

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

@willingc @ucodery i left another note inline. i have no preference. i say go with what is simplest and i'll add it to vale locally to remind myself not to go rogue 😆 or we do a slack poll. i really have no opinion here but agree consistency is ideal.

package-structure-code/complex-python-package-builds.md Outdated Show resolved Hide resolved
package-structure-code/complex-python-package-builds.md Outdated Show resolved Hide resolved
package-structure-code/complex-python-package-builds.md Outdated Show resolved Hide resolved
package-structure-code/complex-python-package-builds.md Outdated Show resolved Hide resolved
@lwasser
Copy link
Member

lwasser commented Apr 9, 2024

@ofek I know you are really busy but do you by chance have a bit of time to review this PR adding information about using hatch with other build backends (meson being the one the scientific community prefers). The only time we'd advise someone to do this would be if they have extensions as hatchling has nice defaults.

@lwasser lwasser changed the title hatch backend compat Add: text on Hatch backend compatibility Apr 9, 2024
In this packaging guide we recommend using `hatch` along with it's preferred back-end `hatchling`. One reason to use
hatch with an alternate back-end is for creating an extension module. A Python extension module is one that is make up,
either in part or entirely, of compiled code. In this case the back-end chosen (such as `meson-python`) must know how to
compile the extension language and bind it to Python but `hatchling` is only capable of building pure Python modules.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not strictly true; there is no built-in functionality but you can build extension modules with plugins. For example, a major one is coming very soon: scikit-build/scikit-build-core#637

ucodery and others added 4 commits April 9, 2024 15:44
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Copy link
Collaborator

@willingc willingc left a comment

Choose a reason for hiding this comment

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

TYVM @ucodery

Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

Thanks for the edit!

@@ -13,7 +13,35 @@ back-end tools.

1. **Pure-python packages:** these are packages that only rely on Python to function. Building a pure Python package is simpler. As such, you can chose a tool below that has the features that you want and be done with your decision!

2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-python extensions, then you need to select a build back-end tool that allows you to add additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. In this case, you could use setuptools. However, we suggest that you chose build tool that supports custom build steps such as Hatch with Hatchling or PDM. PDM is an excellent choice as it allows you to also select your build back-end of choice. We will discuss this at a high level on the complex builds page.
2. **Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-Python extensions, then you need to select a build back-end tool that allows additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. We suggest that you chose build tool that supports custom build steps like Hatch.
Copy link
Member

Choose a reason for hiding this comment

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

@ucodery ok i think i see - i wrote back-end instead of backend originally. build-back-end just looks weird to me

and then i found this 😆

shall we use frontend and backend and then build-backend ?! we really need a style checker. i'm dangerous without some tool reminding me to be consistent.

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 this looks good to me!!

@ofek @willingc thank you so so much for the input!!
Jeremy i think we can make a call on how to spell out backend / back-end / back end 😆 and go with it. should we just write backend and then open a issue that someone else could tackle to make it consistent throughout?

i'm approving this however so you have two approvals! Feel free to merge!

@ofek
Copy link
Contributor

ofek commented Apr 11, 2024

Happy to help! FYI I prefer the non-hyphenated version.

@ucodery
Copy link
Collaborator Author

ucodery commented Apr 11, 2024

I went ahead and remove the extra -, mostly just for this file. I'll probably still merge this evening if nothing else comes up.

@ucodery ucodery requested a review from lwasser April 12, 2024 21:52
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'm happy for you to merge this whenever you feel like it's ready and you've addressed @ofek and @willingc comments (which i think you have). thank you again for this pr!!

@ucodery ucodery merged commit 4fef077 into pyOpenSci:main Apr 15, 2024
4 checks passed
@ucodery ucodery deleted the hatch-backend branch April 15, 2024 16:47
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.

Fix build tools section - hatch now supports other backends
4 participants