Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 306, recorded October 18th, 2022.
I'm Michael Kennedy.
And I'm Brian Oken.
Very exciting to have a whole bunch of things to share this week.
Also, I want to say thank you to Microsoft for startups for sponsoring yet another episode of this one.
Brian, we've had a very long, dry summer here in Oregon.
And I was afraid that we would have like terrible fires and it'd be all smoky and all sorts of badness.
And there've been plenty of fires in the West, but not really around here for us this summer.
We kind of dodged the bullet until like today.
It's a little smoky today.
We smoke, go inside.
Yeah.
I thought we dodged it, sadly.
No.
So I think it's affecting my voice a little bit.
So apologies for that.
We'll put that filter on you and we'll make you sound like someone else and you'll be fine.
Yeah.
It's also affecting me.
So who knows?
But anyway, we'll make our way through.
We will fight through the fire to bring you the Python news.
Hopefully they get that actually put out soon.
All right.
The post office.
Yeah.
Let's kick it off.
What's your first thing?
So I've got, let's put it up.
So I've got to stream.
I've got awesome pytest speed up.
So this is awesome.
Yeah.
So actually, some people may have noticed the testing code is not really going on lately.
And so one of the things that makes it easier for me is when I see cool testing related articles,
I don't have a decision anymore.
I can just say, hey, it's going to go here.
Now, testing code will eventually pick up something again, but I'm not sure when.
So for now, if I find something cool like this article, I'll bring it up here.
So this is.
I think I make you show up every week.
Yeah.
Talk about fun stuff anyway.
So this is a GitHub repo.
And we're kind of seeing more of this of people writing instead of blogging.
They just write like a readme as a repo.
I know.
This is such a weird trend.
I totally get it.
And it's good.
But it's also weird.
But it's kind of neat that people can update it.
So if they can just keep it up and you can see people.
That's right.
You get a PR to your blog post.
That's not normally how it goes.
Yeah.
So I'm not sure.
But it's probably harder to throw Google Analytics at it, right?
Oh, yeah.
We'll see whether you should do that or not.
So anyway, so this comes to us from Nate Zupan.
Cool name, by the way.
And he also has, we'll include a link in the show notes to a talk he gave at a plon in Namar 2022.
So just recently.
Anyway, so he goes through best practices to speed up your pytest suite.
And he's just kind of lists them all at the top here, which is nice.
Hardware first.
Well, first of all, when he goes into the discussion, he talks about measuring first.
So before you start speeding anything up, you should measure because you want to know if your changes had any effect.
And if it's making support a little bit weirder, then you don't want to make the change if it's only marginal.
So I like that he's talking about that of like each step of the way here, measure to make sure it makes a difference.
Right.
So first off, and I'm glad he brought this up, is check your hardware.
Make sure you've got the fast hardware if you have it.
So one of the, and I've noticed this before as well, is, so here we go, measure first.
So some CI systems allow you to have self-hosted runners, and it's something to consider.
The, whether your CI is in the cloud or you've got virtual, like a server with some virtual machines around to be able to run your test runners.
They're not going to be as fast as physical hardware if you've got some hardware laying around that you can use.
So that's something to consider to throw hardware at it.
And then test collection time, some of the, some of the problems with the speed of pytest is using, if you've got, if you run it from the top level directory of a project and you've got tons of documentation and tons of source code, it's going to look everywhere.
So don't let it look in those places.
So there's, there's ways to turn that off.
So with no recursive, so with no recursive, and giving it the, the, the directory.
I also wanted to point out, he didn't talk about this in the article, but I want to point out that something to use is, oh, it went away.
Test paths.
So use test paths to say specifically.
So the no recursive says essentially avoid these directories, but test paths pretty much says, this is where the tests are.
Look here.
So those are good.
Nice.
Yeah.
I've done that before on some projects, like on the Talk Python Training website, where there's got a ton of text files and things laying around.
And I've done certain things like that to exclude, you know, pytest and PyTarm and other, other different things to look there in those places where like, there's no code, but there's a ton of stuff here and you're going to go hunting through it.
Yeah.
So like, I really sped up the startup time for a pyramid scanning for files that have route definitions in them, right?
For URL endpoints.
Cause it would look through everything.
Apparently doesn't matter.
At least looking for files through directories with tons of stuff.
And, and this is like, it makes a big difference if you have a large project for sure.
Yeah.
It's significant.
So it was something to think about.
And documentation too.
You don't, unless you're really testing your documentation, you don't need to look there.
So hardware fast, make collection fast.
This one is something I haven't used before, but I'll play with it.
Python don't write bytecode, a environmental flag.
I guess it's, it, it comments that it might not make a big difference for you, but it might.
So, you know, I don't know.
So Python writes, writes the bytecode normally, and maybe it'd be faster if you didn't do that.
What during tests, maybe we'll try.
Um, there's a way to disable py test plugins, to, yeah, let's just go built in py test plugins.
You can say, no, like no nose or no doc test.
If you're running those.
Um, I haven't noticed that it speeds it up a lot, but it's, again, it's something to try.
And, and then a subset of tests.
So, this is especially important if you're in a TDD style and that's, and one of the things
that I think some people forget is your tech, if you've got your tests organized, well, you
should be able to run a subset anyway.
Cause you're, you've got like the feature you're working on is in a subdirectory of everything
else.
And just run those when you're working on that feature and then you don't run the whole
suite.
Uh, they talk, there's a discussion and this is, this goes along with the unit tests mostly,
but, disable networking, unless you intending to have your code using networks, network
connections.
Um, you can disable that for a set of tests or, or the whole suite.
And then also disc access trying to limit that.
And he includes a couple of ways to, to ensure those.
Um, and then, a really good discussion, a fairly chunky discussion on database access
and optimization to databases, including discussion around, rollback and, and there was
something else that I hadn't seen before.
Let me see if I can remember.
Yeah.
There's some interesting things.
I think, I know you've spoken about it in your pie test course about, using fixtures
for like setup of, of those common, common type things.
Right.
So, so one of the things I w I'm not going to do with that.
I am not familiar with is truncate.
Have you used the database truncate before?
No.
So apparently that it allows you to set the whole database up, but delete all the stuff
out of it, like the empty, the tables.
Um, and, and that, I mean, if, if part, if a big chunk of the work of setting up data
is setting, getting all the tables correct, then truncate might be a good way to clean them
out and then refill them if you need to.
But, also, yeah, like you said, paying attention to, to fixtures, that's, it's really good.
And then the last thing he brings up is just run them in parallel by default.
pytest runs single each, each, test one at a time.
And if you've got a code base that you're testing that can allow, like you're not testing a hardware
resource or something, that you can allow parallel to go ahead and turn those on,
turn on the, use xdst and turn or something else and run them in parallel.
So, really good list.
Um, and I'm glad he put it together.
Also very entertaining talk.
So we'll give it, give his talk a look.
Yeah, absolutely.
Um, Brandon out in the audience says people at work have been trying to convince me that
tests should live next to the file they are testing rather than in a test directory.
You know, I created a test directory that mirrors my app folder structure, with my test in there.
Any opinions?
I don't like that, but,
Neither do I, honestly.
If you like it, I guess.
Okay.
I've, I've heard that before, but I know I haven't heard people in Python recommending
that very often.
Yeah.
For me, I feel, I understand why, like, okay, here's the code.
Here's the test.
Maybe, maybe the test can be exactly isolated to what is only in that file.
But sometime, you know, like as soon as you start to blend together, like, okay, well,
this thing works with that class to achieve its job.
But it, you know, you kind of, it kind of starts to blur together and like, well, what
if those are in the wrong places?
Well, now it's like half here.
And I don't know.
It just, it, it leads to like lots of, I don't know.
It's like trying to go to your IDE and say, I have these seven methods.
Please write the test for it.
And it says test function one, test function two, test function three.
You're like, no, no, no.
That is not really what you're after.
But I feel it kind of leads, leads towards that.
Like, well, here's the file.
Let's test all the things in this file.
And it, which is not necessarily the way I would think about testing.
Well, also, are you really test?
I mean, it kind of lends itself to starting to test the implementation instead of testing
the behavior.
Yes, exactly.
Because you might have, if you've got a file that has no test associated with it,
somebody might say, well, why is the test for that?
And you're like, well, that file is just an implementation detail.
It's not something we need to test because you, it's, you can't access it directly from the
API.
So.
Right.
It's completely covered by these two other, other tests.
And by the way, there are other folders.
Go find them.
Yeah.
Also the stuff you're speaking about here by like making collection fast and such also
is a little bit tricky.
Potentially sharing fixtures might be a little more tricky that way.
I don't know.
My, my vote is, is to not mix it all together.
Plus, do you want to ship your test code with your product?
Maybe you do, but often you don't.
Is it harder?
Harder if they're all woven together.
That's true.
Yeah.
So anyway, that's the same thing.
Also, Henry Schreiner out there kind of says, I don't like distributing tests in wheels
on the Estes.
So like a test folder as well.
Yeah.
I'm with you.
I think Brandon, the vote here is test folder, but you know, that's just, just us.
Yeah.
Awesome.
All right.
Well, this is, yeah, that's a good find.
You want to hear my first one?
This is a, this is a bit of a journey.
It's a bit of a journey.
So let's start here.
So I have a perfectly fine laptop that I can take places if I need to for work.
Take it to the coffee shop to work.
If I'm going on like a two week vacation, it's definitely coming with me.
Right.
It's even if my intent is to completely disconnect, I still have to answer super urgent emails.
If the website goes down, any of the many websites I seem to be babysitting these days,
like I've got to work on it.
Like there could be urgent stuff.
Right.
So I just, I take it with me, but I'm on this mission to do that less.
Right.
Cause I have a 16 inch MacBook pro.
It's pretty heavy.
It's pretty expensive.
I don't necessarily want to like take it camping with me, but what if, what if something goes
wrong, Brian?
What if I got to fix it?
Do I really want to drive the four hours back?
Because I got a message that like, you know, the website's down and everyone's upset.
Can't do their courses or they can't get the podcast.
No, I don't want that.
So I would probably take the stupid thing and try to not get it wet.
So I'm on this mission to not do that.
So I just wanted to share a couple of tools and, you know, people, if they've got thoughts,
I guess probably the YouTube stream chat for this to be the best or on Twitter, they could
let me know.
But I think I found like the right combination of tools that will let me just take my iPad
and still do all the, the dev opsy life that I got to lead.
Okay.
So that it's not good for answering emails.
You know, I have like minor RSI issues and I can't type on an iPad, not even a little
like keyboard that comes with it.
Like I've got my proper Microsoft ergonomic sculpt and you can plug that into an iPad.
But once you start taking that, you know, like, well, you might as well just take the computer.
So, two tools I want to give a shout out to prompt by panic panic is a Portland company.
So shout out to the local team.
Is it at the disco or?
Exactly.
They don't really freak out that much at the disco.
Okay.
I don't even panic there.
Uh, but prompt is a SSH client for iOS in particular for iPad, but you could, I mean, if you wanted
to go extreme, you could do this on your phone, you know, how, how far are you going camping,
right?
Or where, where are you going?
And so this lets you basically import your SSH keys and do full on SSH.
SSH like you would in your, I term to, or, or terminal or whatever.
Turns your iPad into a dump terminal.
Yeah.
And it does.
So like you can easily log into, you know, the Python bytes server and over SSH do all the
things that you need to do.
So, you know, you've got to get into the server and you've got to like, okay, well, I really
have to just go restart the stupid thing or change a connection string.
Cause who knows what, right?
You could, you do it.
It seems to work pretty well.
The only complaint, the only complaint that I have for it is it doesn't have, nerd
fonts.
So my, oh my posh, dude, this is serious business.
Don't laugh.
My nerd fonts, my, like, I can't do PLS.
I can't do, oh my posh and get like the cool, like shell prompt with all the information.
No, it's all just boxes.
It's rough.
No, it's fine.
It would be nice, but it does have cool things.
Like if you need to press control shift that, or, you know, it has like a special way to pull
up the, all those kinds of keys.
So you press control and then some other type of thing, or, you know, it has up arrow down
areas.
Like if you want to cycle through your history, it's got a, it's got a lot of cool features
like that where, you can kind of integrate that.
So it works.
I think it's going to work.
I think this is the, the one half of the DevOps story.
Okay.
The other, the other part is, oh my goodness.
What if it's a code problem?
Do I really want to try to edit code over this prompt thing through the iPad on, you know,
in like Emacs or what am I getting?
No, I don't want to do that.
So the other half is GitHub in particular, the VS Code integration into GitHub.
So if you remember, like here I have pulled up on the screen, just with any public repo
or your own private ones.
This is my Jinja partial thing for like basically integrating HTMX with a flask, but you can
press the dot.
If you press dot, it turns that whole thing into a cloud hosted VS Code session.
That's awesome.
Right.
Even has autocomplete.
So if I hit like dot there, you can see it's on my autocomplete.
That's pretty cool.
But how do you press dot when you're on a webpage and, and iPad, there is no dot because you
can't pull up the keyboard.
The only thing you can do, pull up the keyboard is go to an input section.
And once you're in input, well, that just types dot.
It doesn't do that.
You're like, why?
So here's the other piece.
All right.
Here's the other piece.
So you go over here and you change github.com/Mike C. Kennedy slash Jinja partial to
github.com/dev slash whatever.
Boom.
Done.
So if you got to edit your code, you just go change the dot com to dot dev and you have an
editor.
You can check it back in.
Like in my setup, if I commit to the production branch, it kicks off a continuous deployment,
which will like automatically restart the server and reinstall like the things that might
need.
like if it has a new dependency or something, I could literally just come over here, make
some changes, do a PR over to the production branch or push some how much over to the production
branch and it's done.
It's good to go.
Isn't that awesome?
Just edit live.
Just, you know, edit your server live.
No.
Yeah.
I saw somewhere, somebody was complaining about the, prompt saying it's really hard for
me to edit my code on the server.
I'm like, why, why would you know it should be hard.
You don't do that.
Don't do that.
Yeah.
So I went to try to try this, but I have to do the two factor authentication to get
into my account.
So, yeah.
Yeah.
You got to do that.
Brandon also says, Hey, I'll buy you a keyboard case.
I absolutely hear you.
And I would love, you have no idea how jealous I am of people that can go and type on their
laptops and type on these small things like RSI.
I would be, I would be destroyed in like an hour or two.
If I did it, it's like, it's not a matter of, do I want to get the keyboard?
Like I, I just can't.
So anyway, it's not that bad to be me, but I'm not, I'm not typing on like small square
keyboards.
It just doesn't work.
It's just something I can't do.
Okay.
So just, exactly.
No, I just, I like, because when I was 30, my hands got messed up and they just, they
almost recovered, but not a hundred percent.
Right.
So I know you got more going on than I do though.
So I just got back from four days off and I took the iPad.
And I, I had to answer a few emails, but the, for me, these short emails, the, the little
key bed, the cover thing and it works fine.
Even though they're, those are expensive when you add, well, I want an iPad, but I also want
the, the, the keyboard thing.
And I want the pencil.
Suddenly it's like almost twice as much.
It is.
Absolutely.
And you know, just, people are, who've been paying attention for the last two hours.
Apple just released new iPads with M2s.
So people can go check that out if they want to spend money.
I'm happy with mine.
I'm going to keep it.
All right.
Before we move on to the next thing, Brian.
Okay.
Let me tell you about our sponsor this week.
So as has been the case as usual, thank you so much.
Microsoft for startups founders hub is sponsoring this episode.
We all know that starting a business is hard by a lot of estimates.
Over 90% of startups go out of business in just the first year.
And there's a lot of reasons for that.
Is it that you don't have the money to buy the resources?
Can you not scale fast enough?
Often it's like you have the wrong strategy or do you not have the right connections to,
you know, get the right publicity or you have no experience in marketing?
Lots, lots of problems, lots of challenges.
And as software developers, we're often not trained in those necessary areas like marketing,
for example.
But even if you know that, like there's others, right?
So having access to a network of founders, like you get in a lot of accelerators, like Y Combinator,
would be awesome.
So that's what Microsoft created with their founders hub.
So they give you free resources to a whole bunch of cloud things, Azure, GitHub, others,
as well as very importantly, access to a mentor network where you can book one-on-one calls with people
who have experience in these particular areas.
Often many of them are founders themselves and they've created startups and sold them
and they're in this mentorship network.
So if you want to talk to somebody about idea validation, fundraising, management and coaching,
sales and marketing, all those things, you can book one-on-one meetings with these people
to help get you going and make connections.
So if you need some free GitHub and Microsoft cloud resources, if you need access to mentors
and you want to get your startup going, make your idea a reality today
with the support from Microsoft for startups, founders hub.
It's free to join.
It doesn't have to be venture backed.
It doesn't have to be third-party validated.
You just apply for free at pythonbiz.fm slash founders hub 2022.
The link is in your show notes.
Thanks a bunch to Microsoft for sponsoring our show.
What's next, Brian?
Well, that article that I already read about the speeding up pytest,
it had a whole bunch of cool tools in it.
So I wanted to go through some of the tools that were in the article
that I thought were neat.
One of them for profiling and timing was a thing called Hyperfine.
And this is a not, I don't think it's a Python thing, but you like for max,
you had to brew install it.
But one of the things it does is you can give it, you give it like two things and it runs both of them
and it can run it multiple times and then give you statistics comparing them.
So it's a really good comparison tool to, you know, like if you're testing your test suite to see how long it runs.
May as well run it a couple of times and see.
Yeah.
And for people who didn't see yet the example from that first article you covered,
a lot of those were CLI flags, right?
Like dash, dash, no, no's for disabling the plugin and so on.
So you could have two commands on the command line where you like basically change the command line arguments
to determine those kinds of things, right?
Yeah.
Like, yeah, exactly.
So run it a couple of times and run it, run the test suite a couple of times each
and just to see if I add the, if it had these no flags or this other flag or with the environmental variable.
Actually, I don't know how you could do that in there.
You can set environmental variables in the command line maybe.
Yeah, I'm sure that you can somehow.
Yeah.
In line an export statement or something, who knows?
At the very least, you can run the same command twice.
You can run it, set the environmental variable and then run it again to see if it makes a difference.
So, yeah.
So that, that was neat.
I don't know why I've got the API reference in here.
Oh, the, the thing I wanted to talk about was durations.
So let me find that.
I think I lost it.
So we did talk about duration, durations.
Oh, well.
Oh, here it is.
So durations, if you give it a number, it like durations 10, it, pytest will give you like
the 10 slowest tests and tell you how far, how slow they are.
But you can, if you don't give it anything, it just does all of it.
But the, the other thing that's been fairly recent, it wasn't there when I started using
pytest is durations min.
So you can, you can give it, when you give it durations with a blank or in zero, it, it
times everything, but you can, but that might be overwhelming.
So you can give it a minimum duration in seconds to only include only time the tests are all
over a second or something like that.
Right.
It was really, if it's 25 milliseconds, like just, I don't want to see it.
Yeah.
I'm not going to spend time trying to speed that up, but yeah.
Another cool thing brought up was a pie instrument, which is a way to, it's a very pretty way to
look at, you know, the times that you're spending on different things.
It's not just for testing, but you could use it for other stuff.
But apparently there's a, in the user guide, there is specifically how to profile your tests
with pytest using pie instrument.
So that's a cool, cool bit of documentation.
This doesn't, and this doesn't actually look obvious.
So maybe I'm, maybe I'm looking at this wrong, but I'm glad, I'm glad, I'm glad they wrote
this up.
So this is kind of cool.
Basically profiling your, oh, interesting.
And you do it as a fixture.
Yeah.
And so you create the profiler, you start the profiler, then you yield nothing, which triggers
the test to run.
And then you stop the profiler and do the output.
That's really cool.
Yeah.
Pretty cool way to do that.
So profiling each test.
Yeah.
It's a bit mind bending on the coroutines.
So it's kind of cool.
They're using it as a fixture because if you had the fixtures set up as a, like it's set
up by default as a function.
So it'll go around every function.
But if you set it up as a module, you could just find the slow module test modules in your
system, which might be an easier way to speed things up.
If you're looking.
Anyway.
Oh, I was thrilled that my little pytest skip slow plugin that I developed as part of it.
I didn't even come up with the ideas for the code, but that came out of the pytest documentation,
but it wasn't a plugin yet.
But I developed this plugin during writing the second edition of the book and it showed up
in his article, which is cool.
More interesting is pytest socket, which is a plugin that can turn off.
It just turns off a socket Python socket calls.
And, and then it raises a particular exception.
So it doesn't like if you just install it, it doesn't turn things off.
You have to pass in a disable socket to your test suite and then it turns off accessing the
external world.
So this is a kind of a cool way to easily find out which tests are failing because your network
is not connected.
So go figure out if you want to say, definitely don't talk to the network or don't talk to
the database.
Turn off the network and see what happens.
Yeah.
And then you can, I mean, but even if you did want part of your test suite to access the
network, you could test it to make sure that there aren't other parts of your test suite
that are accessing it when they shouldn't.
So it'd be cool debugging.
And then file system stuff too.
There's probably fake FS, fake file system that you can mock a file system.
So even things that you want to write, you don't actually have to have the files left around.
You can leave them around just long enough to test them.
So you can use this.
That's perfect.
And then the last thing I thought was cool was a way there's a thing called blue racer.
that, that you can attach to a get, GitHub, CI to check, to check in merges.
So if somebody merges something, you can test it.
You can check to see if they've terribly slowed down your test suite.
Um, so it kind of reports that it doesn't, I don't think it fails on slower tests, but it
just sort of reports, reports what's going on.
So yeah, it gives you a little report of like, the nice what happened on the branch and
if the test suite slowed down.
So yeah, thanks to know.
Yeah.
That's a cool project.
Uh, blue racer.
Nice.
Okay.
And it's automatic, which is lovely.
Yeah.
So nice.
All right.
Well, I've got one more item for us as well, Brian.
Yay.
So we talked a little bit about, you talked about PI upgrade, the last show, I think
it was.
Yeah.
And we talked about some of these other ones.
So I want to talk about, I'm going to give a shout out to refurb, very active project last
updated two days ago, 1,600 stars.
And the idea is basically you can point this at your code and it'll just say, here are
the things that are making it seem like the old way of doing things.
You should try doing it the newer way.
So, for example, here's something, it's, it's asking if the file name is in a list,
right?
The, one of the ways you can see if, if file name equals X or file name equals Y or file
name equals Z, you can say if file name in X comma Y or comma Z, right?
And that's a more concise and often considered more Pythonic way.
But do you need a whole list allocated just to ask that question?
What about a tuple?
And here we have a with open file name as F then contents F dot read.
And then we have the split lines and so on.
And so, well, if you're using path lib, just say path dot read text.
You don't need the context manager.
You don't need two lines.
Just do it all in one.
And so on this simple little bit of code here, they just run refurb against your, this example,
Python file.
And it'll say, use duple X, Y, Z instead of list X, Y, Z for that in case.
And then what I really like about it is it finds like exactly the pattern that you're doing.
So it says you're using with open something as F, then value equals F dot read use,
you know, value equals path of X dot read text one line.
It gives you like pretty, it doesn't say you should use path read text.
It gives you in the syntax of here's the multiple lines you did do this instead.
Nice, right?
I don't, I don't think I've ever used read text.
So I learned something new.
I hadn't either, but you know what I do now.
It also says you can replace X starts with Y or starts with Z with, starts with X,
you know, or Y comma Z as a tuple.
And that'll actually test, yeah, one of the other.
Okay.
It says, instead of printing with an empty string, there's no reason to allocate an empty string.
Just call print blank.
That does the same effect.
And just, there's a whole bunch of things like that, that are really nice here.
And yeah, just, you can ask it to explain.
You're like, dude, what's going on here?
Uh, it told you told me to do one, two, three.
Uh, what, what's the motivation?
And you'll get kind of like a help text.
Here's the bad version.
Here's the good version.
Here's why you might consider that.
So for example, given a string, don't cast it again to a string, just use it.
Um, maybe more important as you can ignore errors.
So you can ignore, just do a dash, dash, ignore a number.
There's one, which I'll show you in a second, which I've started adopting that for when I use
it, or you can put a hash, no QA.
And put a particular warning to be disabled.
Or you can just say, no, just leave this line alone.
Like, I just don't want to hear it.
Don't tell me.
Uh, so as you can say, hash, no QA.
And then it won't, it'll catch like all of them.
Okay.
So I ran this on the Python bytes website and we got this.
It says, there's a part where it like builds up a list and then take some things out
trying to create a unique list.
I think this might be for like showing some of the testimonials.
It says, give me a list of all a bunch of testimonials and then randomly pick some out of it.
And then it'll delete the one it randomly picked and then pick another.
So it doesn't get duplication.
There's, there's other things like that as well.
Also in the search.
And so I write Dell X bracket Y to get rid of the element or whatever it's called item.
And they say, you know what?
Uh, on a dictionary, you should just use X dot pop of Y.
I think the Dell is kind of not obvious entirely what's going on.
Sometimes it means free memory.
Sometimes it means take the thing out of the list.
Right?
So they're like, okay, do this.
And I got the square bracket in warning instead of the, parenthesis, the tuple version.
And then also I had a list and I wanted to make a separate shallow copy of it.
So I said, list of that thing.
And I said, you can just do list dot copy or, you know, thing dot copy.
And it'll create the same thing, but it's a little more discoverable what the intention is.
Probably also more efficient.
Probably do it all at once instead of loop over it.
Who knows?
Anyway, this is what I got running against our stuff like this.
And you know what?
I fixed it all.
Cool.
Except there's this one part where it's got a whole bunch of different tests to transform a string.
And it's like line after line of dot replace, dot replace, dot replace, dot replace, dot replace.
One of those lines is to replace tabs with spaces.
Then eventually it finds all the spaces, turns them into single dashes and condenses them and whatnot.
And it says, oh, you should change X dot replace backslash T.
So tab with a space, replace that with X dot expand tabs one.
I'm like, no.
Maybe if it was just a single line where the only call was to replace the tabs, but there's like seven replaces.
And they all make sense.
Replace tabs, replace lowercase with that.
Like all these other things.
And if you just turn one of them into expand tabs, like why did, where did this come like into the sequence of replacements?
Like, why would you do this one thing?
Yeah.
And so I just put a no QA on that one and, and fixed it up.
But anyway, I found it to be pretty helpful in offering some nice recommendations.
People can check it out.
You can just run an entire directory.
You don't have to run it on one file.
Just say, you know, refurb dot slash go.
Cool.
Yeah.
We should run like several of these and then just do them in a loop and see if it ever settles down.
Exactly.
If you just keep taking its advice, does it upset the other one?
Yeah.
Like if you py upgrade and then, then refurb and then black and just, and some others.
Yeah.
Auto pepe.
Yeah.
The goal of this one is to modernize Python code bases.
If we had Python two code, I suspect it would go bonkers, but we don't.
So it's okay.
But one of the cool thing you, you mentioned you weren't going to do the expand tabs, but
I didn't know about the expand tabs.
So the tools like this also just like teach you stuff that you may not have known about
the language.
Yeah.
Like that read text versus a context manager and all sorts of stuff.
Yeah.
So the expand tabs, not where was it?
It was over here.
The expand tabs of one, that means replace the tab with one space.
So if you wanted like four spaces for every tab, you would just say expand tabs four.
Which is probably correct, right?
Yeah, of course.
Of course it is.
All right.
Well, that's it for all of our items.
You got anything else you want to throw out there?
I don't.
How about you?
I do actually.
All right.
So let's, let's see.
I got a few things.
I'll go through them quick.
So another sequence of things that I think is pretty interesting.
This is not really the main thing, but it's kind of starting the motivation.
So we have over on all of our sites on Python bytes, on Talk Python and Talk Python training,
we have the ability to do search.
So for example, over on Talk Python training, I can say in Grok API postman.
And the results you got were just like previously were like this ugly list that you'd have to
kind of make sense of.
It was, it was really not something I was too proud of, but I'm like, I'm not inspired to
figure out a different UI, but I, I got inspired last week and said, okay, I'm going to come up with
this kind of like hierarchical view showing like, okay, if I search for say,
in Grok API postman, I want to see all the stuff that matches that out of the 240 hours
of spoken word, basically, right.
On the site and all the descriptions and titles and so on.
And so like, for example, this Twilio course I talked about used all those things and actually
has one lecture where exactly it talks about all three of those things.
And then others where they're in there, but like one, one video talks about in Grok, then
another one talks about an API or, you know, some, it's not really focused.
Right.
And here just in this course, like it doesn't even exist in a single chapter, but across
a hundred days of web and Python, like all those words are said.
Right.
So I came up with this search engine and well, the search engine existed, but it wasn't running
in a, it wasn't basically hosted in a way that I was real happy with.
So what I did is I took some of our advice from 2017.
I said, you know what?
I'm going to create, I'm going to create a system B service that just runs as part of
Linux.
When I turn it on, that is going to do all the indexing and a lot of the pre-processing.
So that page can be super fast.
So for example, like the response time for this page is effectively instant.
It's like 30, 40 milliseconds.
Right.
Even though it's, it's doing tons of searching.
So I'm going to run this Python script series of scripts in the little app as a system D service,
which is excellent.
And so we talked about how you can do that.
And, you know, if you look, here's a, an example, basically you just create a system D dot
service file.
And you say like Python space, your file with the arguments and you can set up and I'll
just auto start and be managed by, you know, system control, which is awesome.
So that's all neat.
The other thing I want to give, this is the main thing I really want to give some advice
about though, is those, these, these daemons, what they look like is while true, chill out
for a while, do your thing, wait for an event, do your thing, look for a file, do your thing,
then look for it for some more, right?
You're just going over and over in this loop, like running, but often it's not busy, right?
It's waiting for something in the search thing.
It's like waiting for an hour or something.
Then it'll rebuild the search, but it could just as well be waiting for a file to appear
in some kind of upload folder and then like start processing that.
I don't know.
Right.
So it ha they almost always have this pattern of like while true, either wait for an event
and then do it or chill for a while and then do the thing.
So my recommendation, my thought here is if you combine this with multi-processing, you
can often get much, much lower overhead on your server, right?
So check this out.
So here's a, an example of the search thing on Talk Python search out of Glances.
Notice it's using 78 megabytes of RAM.
This is in the beginning of show notes, of course.
This is it just running there in the background.
Before I started using multi-processing, it was using like 300 megs of RAM constantly on
the server because it would wait for an hour and then it would load up the entire 240 hours
of text and stuff and process it and do database calls and then generate like a search result,
a search set of keyword maps and then it would, you know, would refresh those again.
But normally it's just resting.
It puts that stuff back in the database.
But if you like let it actually do the work, it will basically not, not unload those modules
and unload all that other stuff that happened in there.
So if you take the function that says just do the one thing in the loop and you just call
that with multi-processing, it goes from 350 megs to 70 megs.
No other work.
Because it, that little thing fires up, it does all the work and then it shuts back down and
it doesn't get like all that extra stuff loaded into your process.
Okay.
A little cool, right?
It is cool.
You could, I mean, for special cases like ours, I mean, for yours, you could just kick it
off yourself, right?
Or as avid, be part of your published thing when you publish new show notes.
Yeah, exactly.
I mean, I could, I could base it on some of that.
Like, yeah, it could, it gets complicated because it's hard to tell when that happens.
Yeah.
There's, there's like a, as you can see, like in this example, there's like eight worker
processes, right?
So which one should be in charge of knowing that?
I don't know.
It's, so it's, it's easy to just have that thing running and just like, you know, the
search will be up to date and it's going, but please don't overwhelm the server by loading
the entire thing and hanging on to it forever.
Yeah, exactly.
Yeah.
So anyway, I thought that was a fun story to share.
Let's do this one next.
We talked about JetBrains Fleet.
Think PyCharm.
PyCharm's like little cousin that is very much like VS Code, I guess, but as like PyCharm
heritage.
So this thing is now out of private beta is now into public beta.
So it has like Google Docs type collaboration.
It has, but it has like PyCharm source code refactoring and deep understanding that seems
pretty excellent.
So people can check that out.
It looks, looks pretty neat.
I've done a little bit of playing with it, but not too much yet.
But if you're a VS Code type of person, like this might speak to you more than PyCharm.
So that's out.
Speaking of PyCharm, I'm going to be on a webcast with Paul Everett on Thursday.
We're talking about Django and PyCharm tips reloaded.
So just kind of a bunch of cool things you can do to, if you're working in a Django project
in PyCharm, you want to be awesome and quick and efficient.
Okay.
Last one.
How about this?
This, this Mark, go ahead.
This blows me away and it's interesting.
So this is interesting.
So we all have got to be familiar with the GDPR.
I did weeks worth of work reworking the various websites to be officially compliant with GDPR.
You know, like we weren't doing any creepy stuff to like, oh, now we've got to start, stop
our tracking or anything like that.
But like, there's certain things about you need to record the opt-in explicitly and be able
to associate a record like that kind of stuff.
Right.
So some of us did a bunch of work to make our code GDPR compliant.
Others, not so much.
But the news here is that Denmark has ruled that Google Analytics is illegal.
I mean, like, okay.
And illegal in the sense that the Google Analytics violates the GDPR and basically can't be used.
I believe France and two other countries whose name I'm forgetting.
I've also decided that as well.
And yeah, more or less, they, a significant number of European countries are deciding that
Google Analytics just can't be used if you are going to be following the GDPR, which I think
most companies in the West, at least, need to follow.
Yeah.
So I'm glad.
I mean, my early days of web stuff, I was using Google Analytics.
Of course, a lot of people do.
Yeah.
And it's free.
They give you all this information free.
Why not?
Why are they giving?
Oh, it's not.
Wait a minute.
Wait a second.
They're using you and your website to help collect data on everybody that uses your website.
Yeah.
It seems like such a good trade-off.
But yeah, I mean, you're basically giving like every single action on your website, giving
that information about your users, every one of their actions over to Google, which seems
like a little, I could see why that would be looked down upon from a GDPR perspective, no
doubt.
Just by the way, also on that, if you look over on Python Bytes, the pay, let's see, does
it say anything?
How many, how many blockers have we got or how many creepy things do we have to worry about
over here?
Zero.
Like we don't use Google Analytics.
We don't use, yeah, that's just global stats.
But yeah, we don't use Google Analytics or any other form of client-side analytics whatsoever.
So I'm pretty happy about that actually.
But check out the video by Steve Gibson.
It's an excerpt of a different podcast, but I think it's worth covering.
It's pretty interesting.
Yeah.
It's something to watch at least.
Yeah.
Ikivu points out in the audience, how can you enforce something like that?
That is Google Analytics being not allowed.
It's embedded in so many sites everywhere.
Sometimes you don't even manage it.
You just enter an analytics ID.
Yeah.
It's honestly a serious problem.
Like, for example, on our Python Bytes website, if you go to one of the newer episodes, they
all have a nice little picture.
That picture is from the YouTube thumbnail.
Like, it literally pulls it straight from YouTube.
The first thing I tried to do, Brian, was I said, well, here's the image that YouTube uses for the poster on the video.
So I'll just put a little image where the source is youtube.com slash video poster, whatever the heck the URL is.
Even for that, Google started putting tracking cookies on all of our visitors.
Like, come on, Google.
It's just an image.
No.
Tracking cookies.
Yeah.
Or cookies, right?
So what I had to end up doing is the website on the server side looks at the URL, downloads the images, puts it in MongoDB.
And when a visitor comes, we serve it directly out of MongoDB with no cookies.
Like, it is not trivial to avoid getting that kind of stuff in there.
Because even when you try not to, it shows up a lot of times, like Icavu mentioned.
Yeah.
The way it gets enforced, somebody says, here's a big website.
They're violating the GDPR.
We're going to recommend.
I'm going to report them, basically, is what happens, I think.
Yeah.
But I think for small fish, like me or something, it's just, if a country says, don't do that, maybe I won't.
Because they might have good reasons.
Yeah.
And if you're a business, you've got to worry a lot more.
I don't think any individual will ever get in trouble for that.
But it's also, I mean, think about how much you're exposing everybody's information.
And you can't know before you go to a website whether that's going to happen.
It's already happened once you get there.
So I guess, see our previous conversation about ad blockers, NextDNS, do we hate creators?
No.
Do we hate this kind of stuff?
Yes.
Yeah.
Anyway.
Also, information is interesting.
So, but just pay attention to what you have, because you don't need Google Analytics to just
find out which pages are viewed most.
Absolutely.
Things like that.
You can use other ways.
Yep.
All right.
Well, that's a bunch of extras, but there they are.
That's so serious, though.
Do we have something funny?
We do.
Okay.
Something, I got some, this is very much, I picked this one for you, Brian.
Okay.
So this has to do with testing.
Tell me what's in this picture here.
Describe for our listeners.
I love this picture.
This is great.
So it says, all unit test passing.
And it is a completely shattered sink.
The only thing left of the sink is the faucet is still attached to some porcelain.
You can turn it on.
And it goes down the drain.
Actually, so you've already, you've even got integration tests passing.
Yeah, you do.
This is pretty, yeah.
This is pretty, not 100% coverage, but.
Yeah.
Right.
Not 100% coverage of the sink.
Yeah.
There's this sink and it's completely smashed.
There's just like, just a little tiny chunk fragment of it left.
But it's got the drain and the faucet is still pouring into it.
Unit test pass.
I love it.
Yeah.
You might even cut yourself if you tried to wash your hands in this.
But, but funny.
You might.
Well.
That's good.
Fun as always.
Thanks for being here.
Thank you.
Yeah.
See you later.
Thank you everyone for listening.
Bye.