Professional Project & Dependency Management in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome back in today's video we're going to learn how to professionally manage python projects and dependencies using poetry so let us get right into it [Music] alright so poetry is an all-in-one tool for managing python projects and dependencies and in this video today I want to show you briefly how to work with it and how we don't have to use multiple tools to do multiple things like managing dependencies building a project publishing a project working with virtual environments we can use poetry to do all of this with one tool and we're going to start by installing it and for this we're going to open up the command line of our choice in my case CMD and we're going to type pip install poetry and once this is installed we're going to navigate to the directory that we want to be working in so in my case this is going to be the current directory and here we're going to now create a new project using poetry and this is done by typing poetry new and then a project name for example neural 9 project and this is going to create the structure that we need for a package basically and here we have the neural 9 project directory inside of the neural 9 project directory we have another package called neuronline project with an init file in it and we also have a test directory here with another init file for the tests obviously and we also have the configuration as a Tomo file here so we have some data like name version description authors but also dependencies and also the build system that is used and now we can do a lot of different things with poetry so for example we can add dependencies easily but before we do that we can also specify that we want to use a virtual environment because if I go now into the command line I am in this project here I can now go ahead and type for example pip freeze to see what packages are installed and you can see that it's going to print all the packages that I have in my basic python installation if I don't want to have that I can also specify a virtual environment or I can create a virtual environment by specifying a python version and for that I can first type on Windows where python on Linux you type I think which and then python3 and you're going to see the path to the different python installations and the one that I want to use for this virtual environment is this python 3.9 version so I'm going to copy the path here and I'm going to say poetry and for environment use and then I'm going to pass the path and if I uh press enter now it's going to create a virtual environment and you can also see where it is created so it's going to give me that path I can then copy that and I can navigate to it or to be precise I can navigate to the scripts directory in it and call the activate executable or batch file I'm not sure and then you can see I'm working now with this virtual environment and in here I can say pip freeze and you will be able to see that there are no dependencies here and I can also type warp hip and you can see that it's using this virtual environment pip so this is how you activate virtual environment how you create one and how you use one and now what we can do is we can add dependencies easily by saying poetry add and then just some modules so for example I might want to use pandas and if I type poetry at pandas it's going to install the dependencies here it's going to install all the things that are needed for pandas like numpy also for example and once the installation is done we're going to see a couple of things first of all we're going to see that when I type pip freeze we can now see all these um dependencies here but we can also see that we have in the Tomo file here the dependency pandas and we can also see that we have a log file that is important for the installations here we can see that all these packages are tracked here as well um so we have numpy for example here we have pandas here in the log file so this is done automatically for us now what's also nice is we can also specify certain dependencies only for development so I can say for example poetry add and then I can say that I want to use my Pi for uh the typing but I don't want to use it or I don't want to force the user of the package to install it if they don't want to so I can say here Dash capital d to say that this is a development dependency and I can say my pi uh install my Pi indents going to add the dependency here but it's going to only add it for uh development purposes so we're going to see that in the Tomo file that we have now here the development dependencies my pi and we have pandas which is an overall dependency so this is how you do that and uh what you can also do here is if you want to publish your package let's say you have some code in here you have some uh some stuff that you have implemented you want to publish this package on uh Pi Pi or I think it's Pi Pi what is what how is this pronounced I'm not sure uh basically on the on the platform where you get your pip packages from so that people can say pip install neural 9 project what you can do here is you can build the wheel file by saying poetry builds uh we're actually just poetry built and this is going to then build the whole project as a wheel file and you can see that we get this directory here dist and you can see that we get this wheel file and we also get uh the compressed version here as a gz file gzip file um this is also what you can do here and then you can either publish it manually or you can do it directly with poetry I'm not going to go through the exact process here I have a video on how to publish packages with Pip I might make one with poetry as well but basically you have to set up the authentication once you have this you can say poetry publish to publish the package in my case now it's going to say that I'm not authenticated so it's not going to be able to do that but you could just use poetry publish once you have the configuration to publish the package on the PIP platform and then you can also uh show what packages you have once you have a couple of things installed you might want to have an overview what packages are installed why are they installed what packages are depending on each other by saying poetry show dash dash tree and then you're going to see what you have here installed so you can see my Pi with all these dependencies here pandas depending on numpy and stuff like that and then you have this python date util which is depending on six and so on um and that's basically it now there are some more advanced uh features here probably as well if you look into documentation but this is already quite a powerful tool and I discovered it actually because I worked with a package that I downloaded from GitHub and I saw in a make file we have these poetry commands where we just build and add and run and stuff like that it's very very um comfortable or convenient to have a tool which with which you can manage dependencies and what you can use to just build and publish with basic commands like build and publish so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting the like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music]
Info
Channel: NeuralNine
Views: 38,880
Rating: undefined out of 5
Keywords: project management, python, python project management, poetry, python poetry, dependency management
Id: Qks3eqlImy8
Channel Id: undefined
Length: 7min 59sec (479 seconds)
Published: Mon Jan 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.