hi there
Serdar Yegulalp here from Infoworld at
IDG
today i'll be talking about poetry an
all-in-one system for managing projects
in python
you might remember in my last video i
talk about pip-end a system for managing
dependencies in python projects
poetry does that but also a whole lot
more
what i mean by all-in-one is this some
languages like go and rust have command
line utilities for managing every aspect
of a project
setting it up satisfying requirements
keeping those requirements up to date
compiling and running managing the
execution environment and so on
python does not have a single official
utility for all this but third parties
have made up the difference in one of
those third party projects
is poetry poetry is useful not just
because it manages python projects but
because it manages projects for all your
python installations
to that end you don't install it in
python as such but as a separate
application
so to that end i'm going to install
poetry using the powershell commandlet
described in its documentation
and once poetry is installed it can be
run from the command line by way of the
command
poetry now that we have poetry installed
and running let's create a new python
project with it
all you have to do is go into a
directory where you want your project
directory to appear
and type poetry new with the name of the
project in this case just
my project as you can see poetry creates
the directory and populates it with some
basic project scaffolding
if we look at the directory we'll see a
few files there pi project.toml
is the definition file for the project
this should not be edited directly
though poetry will handle that
readme.rst as a boilerplate readme file
that you can fill in as you need for
your project
tests is a subdirectory to hold unit
tests so you can start writing them side
by side with your existing code
something i really need to get into the
habit of doing
and finally a subdirectory with the
project's name which holds the project's
actual code
by default a new poetry project doesn't
have a virtual environment associated
with it
to do that we use poetry's end views
command
and we pass along the path to the exact
python executable we want to use
i have a few different python
executables in my system so i'm going to
use python 3.8
to create the environment for this
specific project
once the environment's created we'll get
back the path to the environment
which we can then use to configure an
ide or some other work environment
now i've mentioned before how poetry
manages dependencies for a project much
like pip band
poetry lets you specify dependencies for
the project itself
and for its development separately so
for this project if i want to add one or
more dependencies
i just use the poetry add command in
this case i'm going to be adding the
dependency piglet
poetry will then install the needed
dependencies in the project's virtual
environment and
lock them to the version specified now
if i want to add a dependency for
development
i can use the same command but i just
use the d flag to indicate that this is
a development dependency and an actual
project dependency
so i will do that with black and my pie
now you'll notice that when a project's
dependencies are created
a lock file is also created for them in
the project directory
this lists all the projects and their
specific versions
so that projects dependencies are
reproducible this way if you pass a
project along to another person with the
lock file included
they can use poetry to install the exact
same requirements with the exact same
dependencies
if you like this video please leave a
comment below don't forget to subscribe
to the idg techtalk channel on youtube
and for more python tips be sure to
follow us on facebook youtube and
infoworld.com
