mesonbuild / meson-python

Meson PEP 517 Python build backend
https://mesonbuild.com/meson-python/
MIT License
118 stars 59 forks source link

Custom meson arguments for editable installs #575

Closed amolenaar closed 4 months ago

amolenaar commented 4 months ago

In Meson-python you can already define arguments to be passed to meson setup/compile/install/dist (tool.meson-python.args.*).

For editable installs it would be nice to add additional arguments. In my case, I like to create debug builds as editable installs, so I can hook up a debugger if something breaks in the C code.

Having the ability to configure extra meson arguments for editable installs will:

  1. Make the the pip install command simpler. pip install --no-build-isolation --config-settings=setup-args="-Dbuildtype=debug" -e . can be written as pip install --no-build-isolation -e ., which is quite a bit simpler.
  2. Tools like PDM do not have an option for config settings, so there's currently no other way than to edit pyproject.toml in order to create debug builds.

Edit: while adding editable arguments, it would also be nice to have an equivalent of the MESONPY_EDITABLE_VERBOSE env var in pyproject.toml.

dnicolodi commented 4 months ago

As you point out, there already is an interface to pass arguments to meson for a specific build: config settings. I don't see how specifying the arguments on the command line is more complicated that specifying them under a dedicated key in pyproject.toml. If PDM does not support passing config settings to the build backend, it is a bug in PDM: the PEPs that established pyproject.toml based builds clearly define this interface as the one to be used to pass options affecting the build. Similarly, there is a config setting to affect the verbosity of editable build.

TL;DR: arguments specified in pyproject.toml are the ones that should affect every build. Arguments specific to a single build are to be passed via config settings.

rgommers commented 4 months ago

2. Tools like PDM do not have an option for config settings, so there's currently no other way than to edit pyproject.toml in order to create debug builds.

This seems like an unexpected gap in functionality. I've found that PDM generally follows packaging standards and issues often get addressed quickly. Have you looked for an issue on the PDM issue tracker? If there isn't one for this topic, maybe you can open one?

1. Make the the pip install command simpler. pip install --no-build-isolation --config-settings=setup-args="-Dbuildtype=debug" -e . can be written as pip install --no-build-isolation -e ., which is quite a bit simpler.

There's a downside to this (beyond more complexity in meson-python): if you hard-code non-default behavior like this, it will be surprising to users/contributors that are not you - meson-python always behaving the same will be easier to learn about.

If this is only for yourself, the typical answer is to define a command alias. Something like:

alias mypkg-editable="pip install --no-build-isolation -e . -Csetup-args ....[etc]"
amolenaar commented 4 months ago

Thanks for the feedback. This makes sense. I agree that meson-python is not the right place.

I'll check with the PDM folks if it's possible to support config-settings for the install target.