2

When building a python project using the python build module, is there a way to override settings in pyproject.toml on the command line?

For instance, suppose pyproject.toml contains:

[build-system]
build-backend = "foo"

I would like to know if it is possible to override foo (say with myfoo) on the command line python -m build. This is just an example.

My question is more general than that example. Whatever upstream defined in a pyproject.toml, a downstream user/packager may want or need to override something that upstream defined for any number of reasons.

Juan
  • 1,204
  • 1
  • 11
  • 25
  • From a quick glance at the `build` package, there's no configurable way that I can see to do this. My immediate thought is that you could copy the project or sdist, and use `tomllib` to rewrite the pyproject.toml file with your desired changes. Then build the copied+mutated directory – flakes Jul 19 '23 at 22:16
  • Can you add some more context for why you'd want this? Are you trying to test new versions of your backend on existing packages? Or testing migrating to a new backend altogether? – flakes Jul 19 '23 at 22:26
  • @flakes - Regarding more context, I added more about possible motivations in the question. But for the specific case of changing the name of the backend tool that the upstream project defined, a downstream user may be using a platform where the backend may have a different name, or as you say the user may desire to test alternative versions of the backend without having to modify pyproject.toml for each testing iteration. – Juan Jul 19 '23 at 22:33
  • For the general case, I think you'd probably want to look at copying the source and modifying the pyproject.toml manually or using `tomllib` to manipulate it once copied. For overriding packages that get installed as backend components, you could look into using [devpi](https://pypi.org/project/devpi/) or `pypiserver` package to provide an override to the pypi server used for creating venvs. I did something similar here https://github.com/devpi/devpi/issues/932 – flakes Jul 20 '23 at 00:22

0 Answers0