Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use case of pipenv?

Tags:

I'm reading about this new shiny tool called pipenv and can't understand what is the use case of this tool.

  1. To create a package I still need to maintain setup.py and requirements.txt.
  2. To create development environments I most likely still need tox and virtualenv.
  3. To create packages or wheels I still need to use pip, because pipenv devs don't care about this feature

So what's the point of yet another tool and config files with different syntax? What problem does pipenv solve?

like image 850
maln0ir Avatar asked Apr 30 '18 23:04

maln0ir


1 Answers

All of the functions of setup.py, tox, requirements, virtualenv, etc. are critical for someone distributing a library that needs to be built and tested against multiple versions of Python and possibly multiple versions of their requirements.

The docs mention this, but I'll reiterate. Pipenv is aimed at application developers and service providers. In those cases, you're typically building a single configuration, and your aggressively updating your version set. In addition, you need to be able to roll back easily to a prior version set.

What you got with requirements.txt was version pinning, so you could roll back, but pip never enforced version consistency, so you could construct a requirements.txt that had contradictory versions. It's python, so most of the time you can get away with it, but having consistent versions does mitigate that class of problems.

pip-tools can construct consistent version sets, but you're now dealing with three separate utilities: pip, pip-tools and virtualenv. This is great if everyone is always careful to run all three to keep things up to date, and of course they don't.

What pipenv adds is combining the management of all three of those and enforcing version consistency at all times.

If you do something as simple as git checkout, all you have to do is run pipenv sync --dev to update your virtualenv.

With pip, you'd have to blow away the virtualenv entirely and rerun pip install as pip won't remove existing packages.

If you set up your Pipfile to have "yourpackage" = {path=".", editable=true}, then you can update a requirement in setup.py and pipenv update will ensure your virtualenv is updated accordingly, or report an error.

To be clear, there is no use case that is handled by pipenv alone; you can do it with other tools. But it does have an audience in mind, application developers, and it is differentiated by providing a much more consistent experience for users. I've also found that, in practice, it's quite helpful for library development too, as a test suite is an application in itself.

like image 153
Ben Avatar answered Sep 28 '22 17:09

Ben