📖 An ode to Poetry

Posted February 2020

Poetry

Recently Over a year ago, when I first started this post, I’d been moving over Python projects from pipenv to Poetry. Not to be hipster – well maybe a bit – but mainly out of growing discontent. Hacker News had a typically heated discussion around this, which led me to give up on everything, but at least note to try Poetry soon.

Now it’s gone 1.0 and the dust has settled, it seemed only right to finish the post…

Pipenv: the good bits

Shall I compare thee to a summer’s day?

A lightweight dependencies file

A single file to declare. I mean, a lot like requirements.txt but, better?

Runtime and dev dependencies

This is something many other build systems have had, and NPM made particularly popular. As the number of excellent Python-made dev tools (pytest, black, precommit etc) goes up then this seems quite useful.

A lockfile too (eventually)

Yay, now we can freeze things. Like all the other package managers.

Pipenv: the bad bits

Why didst thou promise such a beauteous day?

Admittedly, I think a lot of the problem was really the implied promise that Python packaging would finally be fun, and isolated, and repeatable, and fast. Arguably:

  • As boringly reliably as Maven
  • As flexible as Gradle
  • As popular as NPM
  • As fast as Yarn (or Gradle on a good day)
  • As smart as Stack or Cargo
  • As isolated as NPM / Stack

Though thou repent, yet I have still the loss

The final straws were the endless version upgrades and broken releases. Maybe it’s fixed now, but it lost trust for a lot of people, and the speed issues were noticeable on some projects too.

A bit of Poetry

What is your substance, whereof are you made?

Well, Poetry is a new newish newer not so new build system for Python, with a modern CLI and a decent dependency graph resolution algorithm. Version one is out any minute now at last (see the extended 1.0 release notes) 🎉.

Thou art more lovely and more temperate

  • 🚀 Faster - I can’t prove this, but it always seems faster.
  • 💅 Prettier. Yes this is subjective, but it matters - whether just colour output or well-designed CLI. Even the site is pretty…
  • 🧙 Does dependency resolution properly.
  • 🎁 Does packaging too! Yes, you can now get rid of horrible setup.py files forever (edit: not forever, but sometimes at least)
  • 🔍 You can show resolution results for debugging: poetry show -t is especially nice.
  • 🆕 You can export to requirements.txt natively now: poetry export -f requirements.txt -o requirements.txt

So long lives this, and this gives life to thee

Some gotchas
  • Full virtualenv management isn’t quite there… (it creates a virtualenv at initialisation if there isn’t one).
  • Update: 1.0 now has poetry env which does quite a lot.
Bugs aplenty with 1.0

There are quite a lot of open bugs at the moment. Not a good metric necessarily, but we’ve found problems…

  • PyPi repo incorrect by default.
  • Nightmares with virtualenv and private repos. To be fair, I think it’s Python’s venv itself (combined with Ubuntu 19’s Python distro), but we’ve found that pip of a very old version is installed, and this doesn’t play nicely with private repos and Poetry 1.0’s usage of --index-url and --extra-index-url (I think). Either way, the workaround is:

    for every affected project…

Last thoughts

Support

Since switching PyCharm got native Pipenv support, but hey.

In fairness Pycharm Poetry support is in discussion, at least. In fact, go vote on it! A lot of people would love to see this in PyCharm. Note it’s not really implementable as a standard plugin either (read the question I posted there).

Tips

Over the last year I’ve come to love this config (updated for 1.x): poetry config virtualenvs.in-project true as many more tools / IDEs play nicer if you keep a local .venv.