Effective PyCharm (2021 edition) Transcripts
Lecture: Concept: Packaging
0:00 We want to work with an existing package in PyCharm.
0:03 We just opened up the package directory.
0:06 Probably the one that contains the setup py is the top level is the best way
0:10 to go and when we do PyCharm automatically detect things we need to do to get
0:15 the package set up and ready to go.
0:16 For example, it will say look there's all these dependencies.
0:19 You're going to need to install these into your virtual environment that you've created.
0:22 You used a virtual environment. Right?
0:24 So it's going to just give us a button click to get this set up and
0:27 then we'll have at least most of the dependencies installed.
0:31 We'll also be able to say things like 'from.exceptions'.
0:34 The dot relative import works really well in packages.
0:39 One of the things you often need to do is install the package locally in development
0:43 mode so you can go over your tools,
0:44 click run setup py task pops up a dialog in here,
0:48 you can type all sorts of things we did to we start out by saying developed
0:52 to set up the package to work on and then later when we were ready to
0:57 ship it, we said 'bdist wheel' and that actually created a distribution version of wheel
1:02 that we could upload with twine to 'pypi.org'.
1:06 Miracle that was working with an existing package.
1:09 What if we want to create 'zapify'
1:11 an amazing package that will zap the bugs using abstract syntax trees somehow magically
1:16 Well we're going to create that package.
1:19 So what we can do is we can create a new python project that's empty with
1:23 a virtual environment so called it Zapify.
1:25 and have an empty Venv here when I talked about it,
1:30 I did this on the terminal or the command prompt.
1:32 I went over and I actually created the structure for us just because I was talking
1:37 about what constitutes a package. There's actually an option new python package here in
1:42 PyCharm It doesn't do a lot for you If I want to create a python
1:45 package called zapify it will create a directory called zapify.
1:48 and put a Dunder 'init.py' in it.
1:50 That's empty. That's all we did over on the finder and command prompt.
1:56 Once we have that though, we need a setup_py to do real package things
1:59 Of course we can work with the package locally long as the pass the ride.
2:03 But we can't share it.
2:05 We can't upload it up to PyPI we can have someone else download init
2:08 and install it into their virtual environment for that.
2:11 We're going to need a setup py file and there's a couple of things you always
2:14 have to specify. Luckily PyCharm has a nice little dialogue for that.
2:18 So what we can do is if we select the top level of the project and
2:22 you do not already have a setup.py
2:24 You go to tools and you'll have this option there click that
2:26 It gives you this dialogue to fill out all the pieces.
2:29 Like what's your author email? What's the description which the version,
2:33 what's the author kind of odd.
2:34 The author and emailer visually separated but you know it doesn't matter.
2:38 You fill this dialogue out and then boom it creates this setup. py.
2:44 Use even set up tools so it sets the name the version the packages.
2:47 If you have sub packages when you do this,
2:49 we didn't have any when I click the button but if you did it usually automatically
2:54 detects them for you which is fantastic.
2:56 So it fills this out and then we can do all the nice setup operations like
3:00 create the distribution, the wheel for distribution and so on.
3:04 Really cool way to get up and running quickly with PyCharm and new packages.