How to auto update requirements.txt when a new/updated package is installed

Viewed 625

How would I go about auto updating the requirements.txt file for when I install/update a package?

My main idea would be when I push an update to git it would auto create the requirements.txt file (or something along those lines).

I understand there are many 3rd party tools out there, but none of them seem to do this either: pipreqs, pipenv, poetry.

1 Answers

Poetry kind of does this. It has a pyproject.toml file where you declare dependencies. This can be edited manually or more often is updated when you do poetry add. Then there is a poetry.lock file that contains version information for all dependencies, both direct and transitive. This file is updated any time you run poetry install. If you regularly run poetry install to update your dependencies, then you can commit the changes to the lock file.

Depending on the exact syntax you use for dependency versions in pyproject.toml, poetry install can update to the latest patch of a dependency. I think it will update to the latest minor version. But it will not automatically update to a new major version because these can introduce breaking changes that require some human attention.

Related