Effective PyCharm Transcripts
Chapter: Packages
Lecture: Opening existing packages

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In order to begin exploring PyCharm's package features. Let's start by working with an existing package. So over here on the GitHub PSF,
0:09 Git Hub organization, we have requests, one of the most popular Python packages you've probably heard of it.
0:15 Use it to go and make http requests instead of a browser using Python.
0:20 So let's go and actually get that installed on downloaded and set up on our system So we could theoretically work on it.
0:27 So first of all, let's go to the desktop and we'll just get clone this Then we could open this way through PyCharm by open from source control but
0:36 just kinda start this way, show a little more grassroots way. So I want to open up this,
0:41 remember drag and drop on the PyCharm Mac os others open directory and browse to it. Here it is this is request and this is like the homepage that you
0:51 would see for if you just went to the GitHub Repo, right, This is the Read me over here is the code. We don't need this. We go to request.
0:59 Here's the actual code like here's where you have requests, general method and then the various specializations down here.
1:07 Like give me the head, the post, that put, the patch, and so on. The first thing we need to do is make sure that we have a working PyCharm
1:13 interpreter. We don't So I'm gonna create a new one here. Then PyCharm says there's some requirements for this package.
1:23 Many packages themselves have requirements and when you pip install the package,
1:27 you get the transitive closure of those dependencies and their dependencies and so on. So let's go over here and click install these.
1:34 It turns out that PyCharm actually misses one for this package but it doesn't really
1:38 matter because we're going to need to do some other stuff to work with it anyway so this can take a little moment.
1:43 I'm gonna let it run and then we'll go from there. Success we've got it all installed now in order for us to work with us and
1:50 have Python believe that this package, this source code here. This is actually what we're supposed to work with.
1:57 Not some other package that might be installed in some other way or to have this one set up. What we need to do. We need to go down here.
2:04 There's a couple ways we can do it. One of them is we can say "Python setup.py develop" that will basically install requests
2:11 in place rather than copying it over to site packages which means as you edit these
2:16 files will immediately pick up the changes which is exactly what you want while you're working on the package now, how do I know to do this?
2:23 Maybe I don't PyCharm has some cool tricks or helpers up its sleeve here, go to tools here, notice there's a bunch of things but one of them is
2:32 run a setup py task and check this out. We can do things like we could create a binary distribution like a wheel.
2:40 If we wanted to push this to PyPI we could install it, we could register it, we could do all sorts of things but what we want
2:47 is develop, install package in development mode. And we can also just type development. It asks us if there are any options,
2:54 there are none. So we could go notice we're actually installing a couple other dependencies
2:59 that for some reason are not listed in the setup py but are actually needed. There we go. We've got it all set up and installed and notice there's this
3:07 "request.egg-info". This is what Python uses to know about installed packages.
3:13 And so it's gone right into the root directory so we can come down here into our little console and we can say import requests and which requested.
3:22 We just get we got this one right here. Let's see how we might know that. So we come over and do a couple of things just to show you that this
3:31 is the version we're working with. Let's just say print right at the top.
3:34 You would never ever do this but we can make a print statement run during import So we could say running custom version of requests.
3:44 Yeah. Now if we go down here and we make sure we have a fresh version we import request notice it says running custom version of requests.
3:55 This is the one that we just made the changes to and you can see that they're getting added immediately. Well that's pretty fun.
4:02 But let's go to the API down here and add something a little more fun. Let's say we're going to add a grab it method here.
4:12 Real simple way to come over here and say I want to grab a URL data and print it out and return it if you want to return to
4:19 his text. And what we're gonna do is we're gonna say response equals uh just get on a call to get this at the top of the function passed through the
4:28 URL, make sure it worked raised for status, turn 'response.text'. I think of this as like a simplified way to just call it, grab text from the URL.
4:40 Okay. And let's go to the top up here, make sure that this is getting imported. We don't make our grab it text export here,
4:51 then we won't be able to use it as part of the package. All right now, we should be able to go and write some Python code.
4:58 That's gonna do this. Let's go over here to our desktop and in the request Remember on windows you don't do the dot And this is scripts not been why
5:12 these have to be different. I don't know, I understand why the dot not why the bin is different.
5:17 Okay, so let's go over here and we can say import requests. We gotta run Python, we say import requests. There's our custom version of requests.
5:26 Super cool. And let's say some call it HTML is going to be requests.grab_text Go get it from 'talkpython.fm'. Oh, it's taken a minute.
5:42 That's a good sign. What is our text Huge. That's too much. Let's do a little just the 1st 250 characters. What do we get not enough to see the title?
5:54 Let's do 500. Maybe we need more. But you can see we're getting the 'talk Python to me' podcast details right off the website. How cool is that?
6:03 So we're able to go get a package off source control, put it onto a machine, put it into development mode,
6:12 add a feature to it, granted not a super important feature. Right? You can put these two things together to for yourself, grab text, give it to URL.
6:21 Boom, Here comes the text back or an exception. If there's an error, we did this by creating a folder where the package lived
6:28 then we created virtual environment and activated. Then we came over and we did tools run setup py task and then we're good
6:38 to go, we just make changes. Tried, tried working with the code Probably what you would do is one of two
6:43 things and practice as you would create a little example app that would consume it and
6:48 then exercise it if you want to be fairly dynamic or like they have over here you would create some tests that you could run.


Talk Python's Mastodon Michael Kennedy's Mastodon