3

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.

torek
  • 448,244
  • 59
  • 642
  • 775
mike_gundy123
  • 469
  • 5
  • 18
  • This sounds like an interesting idea. How do you expect git to know which packages should be added or changed? This doesn't seem like something that git could know. You might be able to do with with a git hook on commit rather than on push. But that seems risky unless you have a thorough test suite to find any breaking changes. – Code-Apprentice Aug 17 '21 at 19:03
  • What's the representation of your requirements (from which you'd generated the file) if it's _not_ `requirements.txt`? – jonrsharpe Aug 17 '21 at 19:11
  • Ig it doesn't have to be through git, but it was just an idea. Maybe some thing that checks the venv vs the current version of the requirements.txt and see if there are any changes and auto update that way? – mike_gundy123 Aug 17 '21 at 19:16

1 Answers1

0

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.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268