Python Poetry – dependency manager plus packaging tool

I was hearing about this awesome new kid on the block called Poetry. I had taken a look on it in the past (approx two years ago) and it looked not as finished as pipenv, so had stuck with pipenv + setup.py. But over the weekend, I decided to take another look at it after hearing that Poetry 1.0 has been released. And it looked really promising. Looks like I can finally say goodbye to my pipenv+setup.py based workflow which I was never comfortable with.

Install:

Caution: Even though the library is in 1.0 .. meaning build stable, there are some cautions one needs to take. The official install instructions will make a mess if you have multiple Python versions in your computer, in particular.. Python2.7 as default.

Firstly, the official documentation is here: https://python-poetry.org/docs/
But you need to keep a few things in mind before you install.

  1. DON’T install it inside your existing virtual environment, or a virtual environment you plan to use for your project. Reason: poetry is a python project with dependencies and your project is also a python project with dependencies. If you put them both in the same virtual environment, there are bound to be clashes.
  2. install poetry like so: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3.7 Notice that I explicitly specified python3.7. If it was just python, poetry would have installed with python2.7, which is horrible since Python2.7 is officially retired. I use Python3.7. Hence this version.
  3. After installing, you will need to source your ~/.profile file to make sure that poetry path is exported to your shell. source ~/.profile
  4. Now, when your run poetry --version, you will get a warning like:

    See the py2.7, it still referring to default Python on my system, which is Python2.7.
    To finally get rid of this warning, and a BIG oversight by poetry team (IMHO), is to edit this file
    ~/.poetry/bin/poetry.
    The very first line, sets up the python interpreter as /usr/bin/python which is Python2.7 for many linux distros, including mine. Change this to #!/usr/bin/env python3.7

That’s it, poetry is installed. You can go ahead and do
poetry --version in your shell and all should be fine now. Happy coding!!

Update…
Ugh.. looks like I won’t be making switch so fast. There is no official way to generate setup.py. There are hacks but nothing official. I guess, I will stick to pipenv+setup.py for now. Python setup.py is still the most common way of building packages and is supported in almost all platforms. Curently poetry only supports a setup.py less build. I think this will change in near future and will try it again.




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *