16

I would like to understand current state of Python build systems and requirements management.

Imagine, that I checked out sources of some project that is using poetry (or pipenv). And this project has pyproject.toml file with build system specified. Of course I can look into pyproject, see that this one is using Poetry, install poetry and run poetry install, but I would like to avoid it.

Question: Is there a build-system-agnostic way to build Python project?

By "build" I mean install all the necessary requirements for the project to be run in-place.

With requirements.txt I would achieve that by running pip install -r requirements.txt.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Andrey Tatarinov
  • 530
  • 1
  • 3
  • 11
  • 5
    `pip install .`? See [PEP 517](https://www.python.org/dev/peps/pep-0517/) and [PEP 518](https://www.python.org/dev/peps/pep-0518/). – L3viathan Nov 05 '19 at 10:56
  • I have a bad news for you as it seems that `pyproject.toml` is not enough (for `setuptools` at least) to build *.whl with metadata. For some reasons `setup.cfg` is required and only some data are extracted from `pyproject.toml`. Full tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/ – Maciek Feb 09 '22 at 13:52

1 Answers1

13

To install the project (and its dependencies), recent versions of pip are perfectly capable of doing this:

python -m pip install path/to/project

or

python -m pip install --editable path/to/project

To build distributions (sdist and wheel) of the project, currently build is the only build back-end agnostic tool I know of:

python -m build

It is also possible to use pip to build a wheel distribution of the project (but no sdist):

python -m pip wheel --no-deps path/to/project

For the content of the pyproject.toml file itself, see:

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • 1
    Maybe it's not directly related to the question, but how should the `pyproject.toml` then be formatted? Because I have been trying to get it to work and I couldn't find a good resource on it. – Maarten-vd-Sande Feb 26 '20 at 15:00
  • Yes, a bit out of scope considering the original question. Writing the `pyproject.toml` is build-system-dependent though, so which one are you targetting (_setuptools_, _flit_, _poetry_, etc.)? – sinoroc Feb 26 '20 at 15:11
  • @Maarten-vd-Sande Maybe this helps: https://stackoverflow.com/a/60046331/11138259 – sinoroc Feb 26 '20 at 15:21
  • @maarten-vd-Sande For the formatting of `pyproject.toml`, see: https://stackoverflow.com/a/64151860 – sinoroc Jan 06 '23 at 10:00