Skip to main content

Hatchling plugin for building extensions via meson

Project description

hatch-meson

Hatchling plugins that allow building native extensions using Meson and bundling them into your python projects that use Hatchling.

Should I use this?

If you want to build python wheels that contain native extensions built using Meson... you probably should use meson-python and not use this project.

Why does this exist then?

Meson is great for building native libraries due to its simple, straightforward build syntax. This simplicity is one of its most compelling features, but at the same time can make it impossible to accomplish something that the Meson designers did not intend to make possible.

As a Hatchling build plugin, this project allows you to leverage Meson to handle what it does best, and use other Hatchling plugins for tasks Meson doesn’t support.

When using hatch-meson, it is intended that you only use meson for things that require a build system, and that you use Hatchling features for other aspects of packaging a python project.

How is this different from meson-python

The initial version of hatch-meson contains a lot of code that is copied directly from meson-python, as are the initial set of tests, so it's not that different. I also periodically pull in fixes and tests that are merged into meson-python. However, there are some differences.

  • Creating a source distribution only uses Hatchling, so scripts added via meson.add_dist_script are not ran
  • Currently this does not bundle libraries into your wheel
  • Editable installs are supported, but with key differences
    • Built artifacts are copied into the source tree
    • Importing your project will not automatically trigger a rebuild
  • It is not required to use py.install_sources to specify all of your python files. You can if you want, but it is recommended to use Hatchling's standard mechanisms for doing this instead
  • Will not create wheels that contain both purelib and platlib packages
  • If the Python pkgconf package is installed in the build environment, hatch-meson will point Meson's native file pkg-config binary at the installed pkgconf-pypi script so Meson can lookup dependencies exposed by other wheels

While hatch-meson will try to support many of the same things that meson-python supports, it is not a goal to have the exact same behavior.

Documentation

TODO, but much of the meson-python documentation applies. Except the parts that don't.

All of the options supported in pyproject.toml can be found in the dataclasses at src/hatch_meson/config.py

Usage

Use this pyproject.toml to retrieve the name/version from your meson.build:

[build-system]
build-backend = "hatchling.build"
requires = ["hatch-meson"]

[project]
dynamic = ["name", "version"]

[tool.hatch.version]
source = "meson"

[tool.hatch.build.hooks.meson]
[tool.hatch.metadata.hooks.meson]

If you prefer to use the standard Hatchling project settings, you can omit the version and metadata hooks.

[build-system]
build-backend = "hatchling.build"
requires = ["hatch-meson"]

[project]
name = "myproject"
# version needs to be either specified here or you can use a different hatch
# plugin to set the version


[tool.hatch.build.hooks.meson]
[tool.hatch.metadata.hooks.meson]

Building an sdist and wheel can be done using standard python build tooling. Refer to the hatch documentation for more details.

Credit

The meson-python project drove a lot of changes in meson to make it possible to build wheels using meson. Much of the code and tests for this package are directly copied from the meson-python project, and this would have been way more work if it didn't exist.

All bugs in hatch-meson are probably my fault.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_meson-0.1.2.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hatch_meson-0.1.2-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file hatch_meson-0.1.2.tar.gz.

File metadata

  • Download URL: hatch_meson-0.1.2.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatch_meson-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1d741db8f57adacc0be013218763c166d2b0ec6cdbc7ed9eccf899a352e4f164
MD5 c49dd5721005b8f65ce498c4add6a776
BLAKE2b-256 cc50e96b7419440ae165d346fda18bf83fce2252530f1211e1e959c1ee8dcbee

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_meson-0.1.2.tar.gz:

Publisher: ci.yml on virtuald/hatch-meson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hatch_meson-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: hatch_meson-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatch_meson-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 340549aed66a0730674327954749204ed473057ab1039e9e1fdc076cb9bef413
MD5 0ef33db8e15522104d583aeab59ce581
BLAKE2b-256 394ab4103601667ad2f4a9eca558f82bc7f12e2395554a23fcc61e3b73608dbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_meson-0.1.2-py3-none-any.whl:

Publisher: ci.yml on virtuald/hatch-meson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page