by fphilipe · 10y ago · 0 comments
The main problem with requirements.txt, as I see it, is that you don't get exact versions unless you specify it in your requirements.txt. So you'd have to have a loose requirements.txt and then generate a second requirements file after having done `pip install -r requirements.txt` to get the exact versions that were installed.
Further, if you happen to "accidentally" `pip install some-package` in your virtual environment, your app might now be using different packages locally without you noticing. With Pipfile the need for virtual environments is pretty much gone, assuming that at runtime it will automatically load the version of a package specified in the lockfile, which is not clear to me yet from the README.
pip freeze > requirements.txt
it will have all the files' versions specifiedgenerate a second requirements file after having done `pip install -r requirements.txt` to get the exact versions that were installed
So you'd need to have a `requirements.txt` with loose versions suitable for upgrading your apps deps, run `pip install -r requirements.txt` and then `pip freeze > requirements.locked.txt`. Then everyone should be using `pip install -r requirements.locked.txt` as well as during your build. But that's cumbersome and error prone and doesn't free you from having the wrong version of a dep in case you `pip install some-package` later on.
What fphilipe is talking about is something like
$ cat requirements.txt
requests>=2.12.1,<3.0.0
$ pip install -r requirements.txt
$ pip freeze > requirements.locked.txt
$ cat requirements.locked.txt
requests==2.12.1
This way you can run pip install -r requirements.txt when you want to update your dependencies and then lock the resolved dependencies in requirements.locked.txt so that you get deterministic builds when the code runs in production environments where reproducibility and reliability are important. It also gives you a clearer idea of what are top level dependencies and what are transitive dependencies because the transitive dependencies will only be listed in requirements.locked.txt. However this system has limitations and isn't standardized. If you want to have different groups, say development, production, testing. You end up with + requirements.development.txt
+ requirements.development.locked.txt
+ requirements.production.txt
+ requirements.production.locked.txt
+ requirements.test.txt
+ requirements.test.locked.txt
And even if you can tell which are your transitive dependencies by comparing .locked.txt to .txt it does not tell you why a given transitive dependency is in your locked dependencies e.g you don't know which of your top level dependencies is pulling it in.Pipfile looks like a definite improvement over the pip install, pip freeze workflow.
It's nearly impossible to further develop the result of 'pip freeze'.
$ pip install pip-chill
$ pip-chill > requirements.txt
Note: I built it because I got tired of reading through long auto-generated requirements files.But that's not always an option. Bower exists for a reason - all that duplication / bloat is unacceptable for browsers to download. It can also mean hell for static initialization / mutable state, because there's no longer a single owner of the global resource.