Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to
your earbuds. This is episode 121, recorded March 13th, 2019. I'm Michael Kennedy. And I'm
Brian Okken. And this episode is brought to you by Datadog. Check them out at pythonbytes.fm
slash Datadog. More on that later. Brian, how you been? I'm, well, actually I had a rough week
last week, but I think I'm getting back to it. Where'd you get in a fight with a dentist?
Yeah, I went to like two dentists and two doctors just to fix one tooth, but yeah,
it's all done now. Well, glad to hear you're doing better at least.
You know, I would say the future is looking bright. What do you think?
Yeah, especially with Python 3 coming everywhere.
Yeah, absolutely. All right. So what's your first item here?
Well, the first item is, oh yeah, you were doing like a whole transition thing. So yeah,
I get it now. Futurize and auto-futurize. So Futurize is, there's a website called pythonfuture.org
and they have this thing called Futurize that you can turn it on in stages. So it has a whole bunch of
different modular switches. And the idea is to automate your conversion from Python 2 to Python 3.
So like one thing you can do is like a fix the print statement, but nothing else, things like that?
Is that the idea?
Yeah. There's a whole bunch of different little modular things you can do. And I don't, I actually
didn't dig into it enough to know if you can really, really go really small and granular and only change
a few things at once. But one of the things they do have is a staged conversion. So they have split up
a bunch of their stuff into relatively safe fixes, things like changing the exception syntax using print
function. So the print function is easy to change, making sure that your classes have an object-based
class. And apparently the iterator syntax changed, but I apparently that I didn't realize that.
And a handful of other things that are really safe to just change. So there's a stage one that just
changes all that stuff. And then the stage two where there's some more risky items, possibly
they've do more kind of wrap some of the Python 2 style stuff with Python 3 style code. And, you know,
of course all of this would only be for large projects because small projects, just go do it yourself, man.
Anyway, if you're going to try to do all these modular things, it'd be kind of neat if you could test
between hand and save all your changes. Timothy Hopper put together something called
auto-futurize that is a shell script that uses Git to save all your changes and then talks to run your,
is assuming you're using talks to check your code. And it goes and go ahead, does all of these changes
to your code and test it in between. And if it does a little bit of a change and your tests pass,
it does the rest of it. And then it doesn't check in things that don't work. So this is kind of fun
and it'd be fun to try on a project. Yeah. I like the idea of both of these. I can totally envision
like some high paid consultants sitting down to do the Python 2 conversion for the companies that put
their head in the sand until January. And then they come in and they just, you know, run this for the
morning, go have a long lunch, come back. Everyone will be super happy how quickly they did it. And
it'll be great. The machine will do all the conversion. Yeah. There'll be like two files
that they have to hand edit to fix. And exactly. It's going to take a few weeks, but we'll see if
we can get it done without too much of a problem. Hey, that's a new business idea. Maybe I should
start another side business. It's a little shady, but you know, it's all right.
So thanks Tim for, for Christmas money for next year.
Yeah. Thank you, Tim. And that's a cool, actually, you know, in all seriousness,
it's a cool project and I think it's going to help a lot of folks.
Speaking of helping folks, Anthony Shaw, he's putting a lot of content out there for everyone.
And the reason we talk about him so often is often he's doing some kind of blog post,
he's written some kind of cool article. And he went kind of meta recently and did a live stream.
I think it was on YouTube of how he goes about writing these posts, how he does research,
how he thinks about the different formats, all that kind of stuff.
Yeah. So I was just, it's still on my to-do list to watch. So you watched it and it was pretty good.
I watched it. Yeah. About 20 minutes of it. Didn't have a chance to watch the whole thing,
but it was, it's good. Him just writing a post and you just watch him write it. He goes through
and talks about the different posts he's written, some of the trade-offs and how he works and things
like that. So he talks about one of his posts called modifying the Python language in six minutes,
which is like a deep code focused article. He talks about listicles. And so he talks about five
easy coding projects to do with kids. He did, he talks about what is popular and like why those
are popular, which is pretty interesting. He says one type of article he likes to write is like
question articles. So why is Python slow, for example? And of course to, you know, disprove that or
whatever. And then also the tourist, like I'm going to take you on a tour or something. So a tourist guide
to the CPython source code. So if you're looking to up your writing game or get inspired, you know,
if you sit down and you're like, Oh, we got to write about something. What am I going to do? Well,
here's a bunch of ideas like, do I want to write a listicle? Do I want to write a tour? Do you want
to write a question? And so it really helps focus the mind and get you going, I think.
Yeah, definitely going to check this out because he's pretty much crushing it. And I'd like to
kind of learn from that technique. So yeah, very, very well done. Nice job, Anthony. I feel like
you've chosen a very controversial topic for the next one. Not so much, but, but a pretty interesting.
Yeah, I guess I just totally forgot that it was controversial. And I know it was like big thing at the
time, but it's the walrus operator or peps 572. And I kind of love the walrus operator because
it's the, what semi or the colon with the equal sign. And it's basically excitement expression
that's coming in Python three eight. And it's kind of hard to describe on audio, but it's a,
so a lot of the times, if you were to say, I do a lot with dictionaries, or if I'm looking into
some data database or something, I want to find out if an element is there. And if it is there,
I want the value. And it's always this two stage thing. And it'd be great. And pattern matching is
another one, regular expressions. If there is a match, then search for it and get this stuff.
Otherwise don't do something. And, being able to do this as one assignment expression is going to,
I think, help out quite a bit. Anyway, you can play with it now. So that that's the whole point of this
is, Alexander Holtner. Yes. I wrote an article saying that now that the alphas,
some of the alpha releases for Python three, eight are out, you can try these out. And he wrote a post
demonstrating exactly what I was talking about, getting elements out of a dig, iterating through
dictionaries and grabbing keys out of their elements. If they, if they exist, he used pyenv and, to
grab the new releases. I don't know why, but I'm just one that I like to just download the stuff.
So I've added the links to the, the two, three, eight alphas available so far.
People want to try it out. So. Yeah. The one that I really like here is the
list expression, which could be a generator or it could be set expression or whatever, but
a list comprehension, because those have to be one line. And if you want to assign a variable and
then test it and then do other stuff with it, you can't really get really do that.
And without the walrus operator, if you're going to like apply like a function to the elements that
you're looping over and then you want to use those, you have to basically get access or compute that
twice for each element. And the walrus lets you do it all in one. So these little expressions are kind
of like the lambda has the, you know, the colon and then the body type of syntax. It's a little bit
like that kind of in line and that definitely seems nice to me. Yeah. That's a pretty cool use.
I hadn't, hadn't really seen that before this article. I guess I didn't pay much attention,
but using it as a, in a comprehension is pretty cool. Yeah. Cool. Yeah. Also your little nested
for loop if test, it's pretty nice. You know, I guess I'm coming around to the walrus operator,
honestly. Yeah. I mean, once I start using three, eight, I'll be using it all the time. It'd be like,
be like using f-strings, I think to say, okay, well now it's three, eight and above because I don't want to
use anything else. I'm not there yet, but awesome. All right. Well, before we get onto the next one,
which I'm pretty thrilled about, cause it's simple and amazing. I just want to tell you quickly about
Datadog. So they're sponsoring this episode. Of course, Datadog is a monitoring and analytics
service that brings all your metrics and logs and distributed traces together. And their client
automatically instruments things like asynchronous libraries, such as Async IO and popular frameworks
like Django or tornado to help you visualize your performance. If you want to trace your requests
across service boundaries and figure out where your app is slow or find errors, you know, go over to
pythonbytes.fm/Datadog. Got a cool free trial there and you get a nice little Datadog t-shirt too.
So check them out. It helps support the show. Now to the awesome thing. We talked about click and we
talked recently about argparse and other cool ways to build command line applications, right? Yeah.
And there's of course the tried and true input, right? You got input. What is your question? And
you set the value and then you maybe have to test it. We'll see whether it's an integer. And then like,
if there's an error, you say, no, there's an error. You can't say that you got to say an integer.
And there's all these, these challenges, right? So maybe I've got a list of things I'd like them to
pick from like what kind of, you know, maybe you're building a site and like through a generator says,
well, what kind of data backend do you want? I want Django ORM. I want SQLAlchemy. I want raw SQLite,
whatever. You might give them a list and say, well, pick one, two, three, or four, right?
Which box do you want? Well, with bullet, have you seen bullet?
I'm just looking at it right now and it's pretty exciting.
It's incredible, right? So what you get is imagine like a dropdown combo box,
like you would have on the web that is the list and you can click, but in the command line as a
command line or even, so it says choose something and you can arrow through it. It has like little
indicator of which one you're on. Oh man, it is slick. It supports colors and emojis and it has a
scroll bar. You can like even scroll through them if there's too many choices to fit on the screen.
Yeah. It's, it's pretty cool and it's easy to use. So that's nice. There's also other types of inputs.
Like you can have a password. It says enter your password or what is the password? And it does the
star marking, which is cool. It has yes, no questions and numbers. It only, you know, a number
input. You can only enter numbers. They won't accept, you know, junk that won't parse. So you
don't have to go through all those steps. it's pretty incredible, right? Yeah. So we need somebody
to write cookie cutter with, with bullet prompts. Exactly. I was thinking of cookie cutter.
Exactly. Cause the cookie cutter asks all those types of questions all the time. Yeah. It would be
beautiful to have bullet just, you know, beautifying all these things. So there's one idea people want
to contribute to open source. Another one is right here on bullet. you know, there's probably other
types of input besides passwords. Yes, no. And numbers like maybe multi-select. I don't know,
but also looking for windows support. I think right now this does not work on windows because the way
the terminal works versus on, you know, a POSIX system. So pretty cool though. Still, still digging it.
So go bullet. Go bullet. Yeah. So we actually have a couple of items to do with pip and packages and
installing. You go first. Okay. Well, last week, I think it was last week. Maybe it was the week
before we talked a little bit about, maybe you want to try something different than, Travis for your,
uh, pipelines, for your continuous integration. The exodus after all the layoffs and all that
business, huh? Yeah. Well, I mean, or just maybe you're just wanting to try Azure anyway,
Azure just because it looks neat. There's an article that I thought was super cool. That was,
um, hosting private pip packages using Azure artifacts. And the idea is for the, of the article
is let's say if I'm using Azure pipelines to do actually a data pipeline, doing a whole bunch of
different stages of changing the data or whatever, whatever you do with data pipelines, some of the
work can be packaged up and used, in later stages with just like a pip install. That'd be
cool. And then how, how do you do that? There's a few gotchas that they get through and they, for
instance, in one part, you can't just use the normal pipelines just by itself, but you can use
the CI pipelines from Azure DevOps tool to get the packages into an artifact form. And basically it's
all the hacks that you need to do to make this work. I just thought that was cool. It was neat.
Yeah. I think that sounds really cool as well. And now go ahead and leverage those artifacts to,
to make your pipelines, which is cool.
I don't think you can make these public. They're mostly, you know, you're using it for your own
stuff. So they're a little bit private. Like they're talking about using a credential,
hooking up your credentials so that a pip install can get those correctly. and then I also wanted,
one of the things we did, did talk about last week was, Anthony Shaw's, pytest Azure
pipelines, pytest plugin. We've already covered that last week, but one of the things that's cool that
happened since then is that plugin has now part of the recommended pipeline recommended setup from
Microsoft itself. Yeah, that's pretty cool. Well done. So it's definitely going to be sort of the
de facto way over there now. Yeah. So I want to talk about something pretty unique. maybe we
haven't touched on this before. It has to do with GUIs. So, last week we spoke about mixing in
the asyncio. I know this was two weeks ago, the asyncio pipeline, sort of event loop and mixing that
in with cute. So cute for Python and PyQ and things like that. So all GUIs have event loops, right?
They're always just going around and around going, did something happen? Did they click a button? I'm
looking for, you know, like mouse move. I'm looking for key down, resize events. And it just, you know,
passes it on to like the various event handlers. Well, asyncio is another loop that kind of goes
around and around process those things, but like, how do we put those together? So a guy named Andy
Bolka sent us a message after hearing the first conversation about what was it? He was async
QT cute was the name of the project. After hearing about that, he's like, Hey, I work on WX Python.
And, you know, there's a cool thing called WX async as well. And it does a really similar thing.
And it basically merges those two event loops into one thing, which is pretty cool. So he wrote a
really nice in-depth medium article about it called async and await for WX Python.
Oh, very nice. Yeah. So one of the challenges with WX Python apparently is doing background work,
right? So you try to like call service or you try to do something. And then, you know,
if you don't take extra measures, it's going to block up that event loop. That is the GUI thread.
And it's just like your app's going to freeze and not respond and do all sorts of bad stuff. You're
not supposed to do in desktop apps. So with this, you can have async handlers that, you know,
run in the background. So if you're like waiting on a call to go to the service, you just await that.
And like the event loop keeps on chugging. So it's pretty cool. Obviously you can do threading
and multiprocessing and that kind of stuff, but this is a little bit cleaner. And if you want to
use async and await. Yeah. Nice. The other thing that he talks about in his article is about this
sort of viral nature of using async and await. So if I define a function, I say async def something,
the function that's going to call it may well have to itself be async so it can await it. And then like
the things that call that have to become asyncified and so on. It creates this kind of
like from the bottom up spread of async, like invading all of your code, which that can be a
challenge. And it talks a little bit about that, but I would just wanted to throw a shout out, which
to something I think we've spoken about before. If I haven't, we should definitely make it in full
featured item later, but unsync. Have I mentioned unsync on the show? I don't remember.
All right. Well, that's probably going to be a new thing if we haven't. I'll double check. But
unsync is a super simple library that puts a unifying API on multiprocessing, threading,
and asynchronous methods. And it manages its own little background queue running somewhere else on
another thread. It allows you to do a lot of things like just blocking on those running sub method
calls to get the result so that you don't actually have the problem. You can sort of use it to stop
this async spread of these methods. So anyway, you know, it's an interesting article. It's interesting
it covers that. And I want to throw unsync out there as one of the cool solutions for it.
Yeah. That's a good thing to bring up. I kind of didn't think about that. I mean, I'm used to it
in C++ world that if you're running multi-threaded, everything's got to be multi-threadable.
Yeah. It starts to go crazy. And it's just like, yeah, similarly. Yeah. Yeah. Anyway. Okay.
Pretty cool. All right. Well, that's it for our main items. I have a couple of follow-up ones and I
have a set of jokes for you. I have a joke generator for you even. How's that?
Oh, that's great. Yeah. All right. You got anything you want to let people know about?
No. So you just released a new testing code episode.
Yeah. That released an episode talking about a fun alternative to our version of TDD that's called
TCR test commit revert with the idea of what happens if every time your tests fail, you just throw away
all your code that you've changed since the last good commit. And it seems absolutely crazy, but it's a fun
thing to talk about. Yeah. It does seem a little crazy, but also, yeah, it seems fun. Yeah. And then
there are a whole bunch of cool people lined up. I've got like six interviews lined up. So there's
going to be lots of good content coming up soon. Yeah. Sweet, sweet. All right. Well, I have a couple
of things, a correction, some self-aware acknowledgements, and then a joke. So correction, we spoke about the
MongoDB licensing and the AWS kerfuffle where AWS said, well, you're going to change your license. So we
can't use MongoDB as our own service. Well, fine. We'll rewrite a new implementation that has nothing to do
with you, but is, you know, wire protocol identical and things like that. Well, mostly I got that right.
However, Will S sent me a message said, Hey, I actually posted a message on the comment section
of that episode and said, Hey, you said they switched to the AGPL. They actually had already been on the
AGPL. And what they switched to is something called the SSPL server side license. And it turns out that
the OSI open source initiative doesn't even recognize SSPL as an open source
license because the way some of its conditions. And so it's interesting in some sense that like
MongoDB might not even be open source anymore based on its license, not in the traditional,
what is its license mean sense anyway.
Right. I took the perspective of, let's say I've got a service out there. I'm just like a,
to have a side project where I've got a service out there where I just run my own instance of
Mongo and have amusing that. Do I have to worry about this license change? And the answer is no.
Yeah. That's what I saw as well. It's like, but if you want to be a cloud provider and you want to
offer the service to others, then you do.
Right. But if the service you're offering isn't Mongo, it's just some other service that happens to use
Mongo. Yeah. You're good.
Yeah. Like businessinsider.com or whatever.
Yeah.
Yep. Okay. So MongoDB license, sorry, it's SSPL. That's the change. It was already AGPL. Thank you,
Will, for that. So Brian, do you know that legacy Python is self-aware and has actually entered the
fifth stage of grief?
No.
So people out there can try this. So if you type Python 2 dash M and you run any module,
so like Python 2 dash M pip list, like that's a meaningless command. You'll get the output that
says deprecation. Python 2.7 will reach its end of life on January 1st, 2020. Please upgrade your
Python as Python 2.7 won't be maintained after that date. Moreover, my word, a future version of
pip will drop support for Python 2.7.
Oh, wow. Yeah. Well, that makes sense.
Yeah. So, I mean, I feel like that's acceptance, right? It's like, yeah, I'm going away. Sorry.
Anyway, there's a funny Twitter thread as well that I threw out when I first saw that going by. So that's cool.
And then finally, we talked about pip and packaging and stuff. There's this thing that Dan Bader from
RealPython shot me over and said, hey, have you seen this? This is kind of cool. Called PyDist.
So this is a thing, a service, I guess, that is in beta. And the idea is you can use it as your
package source, right, for pip and whatnot. And you can have public and private dependencies there.
It'll mirror the public ones and keep a copy of them and never, ever delete them, even if they were
deleted from pip, PyPI, so that you always have them there stable. It's pretty cool. It's supposed to do a
bunch of other stuff, like show you, like, if you use this package, here are all the packages that
depend upon it and what you're going to get, which is not really available right now and things like
that. But it looks like it maybe at some point become a paid service. I don't know. It's in free
beta. They don't say one way or the other. So anyway, maybe that's helpful to people out there.
Interesting though. Cool.
All right. You ready for a joke?
Definitely.
This is super hilarious. All right. Let's do this. pip install --user.
PyJokes.
Okay.
All right. You got to do it.
Or better. I'm super loving PipX. So PipX install PyJokes if you got that, because that
that is the business these days. PipX is awesome. It's like homebrew, but for Python executables.
Okay. This is going to take two then.
All right. Let me, I'll do a couple and then you can give me one at the end. So what this is,
this is a package that you can install that gives you a command line access to developer jokes.
Really?
Yeah. Okay. So once you install, I'm going to type PyJoke. There are two ways to write error-free
programs. Only the third one works. All right. Let's see what else we got. This one, I think
you'll like this one. A QA engineer walks into a bar, runs into a bar, crawls into a bar, dances
into a bar, tiptoes into a bar, rams a bar, jumps into a bar. Okay. That's it. How many programmers
does it take to change a light bulb? None. They just make darkness a standard. Let's see.
A good programmer is someone who always looks both ways before crossing a one-way street.
See, these are like, once you, once you install PipX and sell PyJokes, these are at your hand.
And you're like, I'm feeling a little down. What are we going to do? Why do Java programmers
wear sunglasses? Because they can't see sharp. Huh? So like there's, it just doesn't stop.
Apparently.
Well, we don't even have to have anybody submit any jokes for us anymore. We just use these.
We have the fountain of, the endless fountain of jokes. Although I'm sure there is some limit
to how many jokes are in there. You can go to their website and actually submit a joke to be
included in the app. Oh, okay. Which is all good. So I have to make sure I update it every once in a
moment. Yeah. That's why you need PipX because then you have to do PipX update all and it does it.
Okay. Cool. Sweet. Anyway, that's our joke. If people can go out there and install PyJokes,
the package and run it. Although they might not need us anymore, Brian. Yeah, they will. Because they'll need
our wonderful transitions from one thing to another. That's right. That's right. All right. Well,
a lot of fun as always and I'll chat with you later. Okay. Bye.
Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's
Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item
you want featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for
sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for
listening and sharing this podcast with your friends and colleagues.