Why doesn't pip write installed packages to pyproject.toml?

Me, right now, with the current state of things I would say no. That is out of scope for pip as it currently is. If the suggested pip add some-library is meant to add some-library to the project.dependencies key of pyproject.toml, then no, because pip does not deal with modifying this kind of data, pip is only a consumer of such data.

Is that what you had in mind or something else?

Maybe there is some misunderstanding as to what pyproject.toml is and contains. The primary goal of pyproject.toml is to contain metadata (and configuration settings) for one specific library (or application) during its development, test, and build phases.

pyproject.toml is not meant to contain information about a (virtual) environment. Some development workflow tools kind of blur the lines about this, in that using their add command changes both the content of pyproject.toml and the content of the development environment. But we should not get confused about this: it is an environment meant to be used for the development and testing of the library (or application), it is not meant for actual use (deployment in production).

1 Like