- Podcasts
- Python Bytes
- #277 It's a Python package showdown!
About this episodeTopics covered in this episode: March Package Madness nbpreview strenum Code Review Guidelines for Data Science Teams Extras Joke See the…
See the full show notes for this episode on the website at pythonbytes.fm/277
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#277 It's a Python package showdown!
Thank you very much. Well, so, Michael, it's March. It is March. It's like March Madness, right? Yeah. So Chris May sent in this thing that says, hey, Python Bytes people, here's a fun thing to cover. For March Madness, but for Python. And for those of you who are not college basketball fans and follow it carefully, March Madness is basically the playoffs for the college basketball.
And it's single elimination. You start with 16, I think. And then every team plays another one. Then it's down to eight, then down to four, and so on. So that's the idea, but for Python. Oh. And check it here. We have round one. I guess it starts with 32 and then 16 and so on. So we've got these different rounds.
So if you go here, what you see is this tournament bracket. And the first ones were like NumPy versus Redis. And NumPy won. And then pytest versus LXML, Parser. And pytest won that one handily. And then NumPy and pytest had to face off. And as Thomas said, surprisingly, NumPy pretty badly beat up on pytest.
Brian, are you okay with this? How are you feeling? I didn't get to vote, so I'm not sure how this was done. Yeah. This is going to be the start of a long blood feud between the NumPy community and pytest. Well, and the other part of this story I'm telling, the other side of the bracket was Psykit-learn versus Beautiful Soup.
And Beautiful Soup, oh my gosh, I think it was a buzzer beater. It came in at the last second, and it's like 52% to 48%, Beautiful Soup won. And so now this week, we're in the Elite Eight. And so you can come and vote. I'm going to vote. Like my metric here is sort of how useful and how impactful is this thing?
Ooh. Ooh, I do like me some Docker. I'm going with Pandas. And then Wheel versus Request. I'm going to go with Request. I know Wheel is important under the covers, but I don't see it, so I don't want to think about it. So Request, top of mind. I use that all the time. So here you can see I voted, and everyone else who would like to can just click the link in the show notes, and you can vote too.
And these are basically open for a week, and then the elimination happens, and it moves on. So we're going to see what happens in the final four. Coming real soon, actually. Okay, we're going to have to highlight this earlier in the month next year so that people can vote. You want to create some voting blocks like in the reality TV shows.
It's just sort of, you know, people just enjoy this for what it is. Yeah, bragging rights and whatnot. So we'll send out a tweet or something about it. You can get in there and check this out. Definitely. Yeah. How about you, Brian? What's your next one? I'd like to talk about NB Preview, which actually I thought we covered, but I couldn't find it anywhere.
Oh, yeah. But it's so you say NB Preview, and then you can give it some options, but then a notebook file name, and it will, it just previews your notebook in ASCII, which is awesome. But it's not just ASCII. It's rich. So we've got colors and nice colors and tables and stuff. There's actually quite a few features that I want to run down.
I don't know if you do that or not, but you might want to pipe output. So by default, you get these nice colors, but if you pipe it to an output, you can pipe it to grep or something and you can grep for things. So this is kind of great. I don't know if you've ever tried to grep for something in a notebook, but there's a lot of junk around it.
There's a lot of formatting stuff that, and if that's not really what you're looking for, it's not helpful. So be having this tool to strip that out. It's pretty nice. Oh yeah. That's really nice. I love the ability to just pull this up and view them. And given that it's based on rich, like it has formatting for all the cells.
So a lot of cool stuff that you would expect, like code highlighting and stuff. But the thing that like really stood out to me is what does it do with images like graphs and stuff? And the images are kind of amazing. They're like these, by default, these block things, which not that clear to use for utilities, but it kind of shows you what it's going to do.
So you can click on HTML that's in there. That's kind of neat. The thing that I really like that is the simple part, though, is to be able to strip stuff and pipe it to grip and things like that. So this is handy. Nice. Thomas, what do you think? Oh, this is great. I don't really use notebooks all that much, to be honest with you.
Yeah, got it. All right. Well, your topic is up next. Tell us about it. Well, funnily enough, this is very traditional programming. What I bring for you for your delectation is PyFakeFS, which I think is a sadly relatively unknown open source library. And I'd like to give them some props and recognition because I think it's amazing.
And it's made a huge difference to me and my own code and the Piper project. So hopefully this helps out some other people. Now, what it is, is a fake file system. So in a nutshell, it intercepts all calls from Python to the actual file system. So if you think of the open function, the built-in open, that is, or shutil or pathlib, all of those that might have real-world side effects in terms of the disk, the fake file system will intercept these.
And this is completely transparent. And which is to say that your functional code doesn't need to know about this. So the patching happens without you needing to inject something or without you needing to go and alter your actual code to take countenance of the system. Now, what's great about this is the moment you start talking about testing a file system, you're almost by definition in integration testing or functional testing terrain.
Like it's not a unit test anymore, which comes with its own disadvantages. So if you do want a unit test, then let's consider a simplistic example, right? If you want to, if your code under test writes an output file. So first of all, you need to patch out that if you're in your unit testing framework with something like mock open.
But secondly, you probably have a pathlib in there somewhere where you're either creating the parent directories for the path to check that they exist before you try and write to that location. So now we already have two things we have to patch out. And then on top of that, you might be doing it in a loop.
You might be writing more than one file and the testing becomes very clumsy very quickly. Whereas once you use the PyFaEFS library, you can just write as normal, validate against that file system using the standard Python inputs. And what you end up with is, and once the test finishes, it all just goes out of scope and you don't even need to bother cleaning it up.
So if you are using pytest, which you should, you can just add the FS fixture to your unit test. And now everything in your unit test will be going to the fake file system rather than the real underlying fake file system. That's pretty cool. Yeah. And the helper functions allows you, like you were hinting at, Mike, you can specify encodings, you can write in binary.
It's super useful. Something else that I use quite a lot is the ability to switch between Linux, Mac, and Windows file systems, which again, for Piper is such a boon to be able to test the cross-platform compatibility. Oh, interesting. So if it asks for like the representation from a pathlib thing, it'll do SQL and backslash instead of forward slash.
Yeah, exactly right. So all of these things are, you know, I'm relatively conservative when it comes to pulling in new libraries because I'm, especially if the library feels heavy and I feel I can do it just using standard lib functionality. And also with some libraries, I'm a little bit worried that they might stop being maintained or something like that.
Check it out on GitHub. Check it. Check out the documentation too. It's well documented and it's super useful. And I was looking at the Toxinny. It looks like it's tested to be compatible with PyPy also, which is kind of nice. Yeah. Yeah, absolutely. Especially for what I'm doing in Piper, where wrangling configuration files is a lot of the functionality as a task runner.
You're forever reading JSON, writing out YAML, converting between formats, converting between encodings, swapping out values inside configuration files, merging configuration files. And I'm now able to test all of this stuff without having to write integration tests for each and every permutation, which has been such a boon.
This actually does way more than I thought it did. I'm going to check this out. This is neat. Yeah. There's a lot of cool stuff there. Absolutely. Chris and Alvaro both think pretty neat out there. They're digging it. Yeah. And I see the comment there. It is like temp path with the difference that it's not actually writing to the desk itself, of course.
And what's also a little bit difficult when you're using the temp directory and the temp file modules is depending on how you're testing, it doesn't always help you very much. Because the thing that might be generating the file might be the code under test. So you're effectively going to have to intercept that and create a temp file to attach to it.
And then the temp file will clean itself up. But that starts interrupting the flow of the functional code so much that I start questioning whether it's even a useful unit test anymore. Yeah, absolutely. Well, very, very cool. So, Brian, before we move on, let me tell you about our sponsor, all right?
All right. This episode of Python Bytes is brought to you by Microsoft for Startups Founders Hub. Starting a business is hard. By some estimates, over 90% of startups will go out of business in just their first year. With that in mind, Microsoft for Startups set out to understand what startups need to be successful and to create a digital platform to help them overcome those challenges.
Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be investor-backed or third-party validated to participate. Founders Hub is truly open to all. So what do you get if you join them? You speed up your development with free access to GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.
You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation, fundraising, management and coaching, sales and marketing, as well as specific technical stress points. You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
Make your idea a reality today with the critical support you'll get from Founders Hub. To join the program, just visit pythonbytes.fm/foundershub. All one word. No links in your show notes. Thank you to Microsoft for supporting the show. Awesome. Thank you, Microsoft. Now, let me tell you about something that sounds incredibly simple, but as you kind of unwind it, you're like, wait, it does that too?
A little while ago. So enums have been in Python for a while. Pretty much prehistory now that those are no longer supported. And with enums, you can write cool code that says this class, its fields are enumerations. And then you can say, you know, enum type dot enum value. And you can use that instead of magic words.
So, for example, you might have HTTP method or something like that. Or let's say HTTP status. Start with that one because that's like a built-in type thing you could do easily. You could have a 200, a 201, a 400, a 500, a 404, those kinds of things. So, you could have like HTTP statuses dot and then those types with those numbers, right?
But there's a couple of challenges to working with those. Their natural representation is a number, not a string. And I know you can derive from enum and then also derive from string. But like I said, more stuff happening than just that. So, this sternum allows you to create enums like that and use the enum auto, enum.auto field.
So, I can say, here's an HTTP method with like verbs is really probably what it should be. So, you can have a get, you can have a head and a post and a put. And you just say auto, auto, auto, auto. But the actual representation is that the get is a string get. And the like put one or post is, you know, put or post.
For example, one of the things that's nice is because this thing basically has the value string, where you're using it, you can actually use it where a string would be accepted. So, here if you're doing a request to a URL and you've got to say method equals, here you can say method equals HTTP method dot head or whatever from the enum and it directly passes just the string head to the method.
So, it's a really nice way to like gather up string values that are like part of a group, right? Like HTTP verbs or something like that. Wow. So, that's pretty neat. Okay. The side question is I don't really use auto much. Is auto used anywhere else or is auto just an enum? It comes out of the enum module.
Okay. So, it's part of this. So, it's part of the enum thing. All right. And one of the things I really like about this that is super tricky with enums is databases. So, for example, imagine we had like get head and post. So, we just had auto, but it was an integer based one. So, it was like one, two, three.
And we store it in the database, right? As a one or two or three and then you parse it back. Fine. But then somebody adds another auto thing in there and they don't put it at the end. They're like, oh, this one starts with a D. So, it goes after delete. Yeah. Well, all the stuff after that one is now off by one in the database, right?
Like, so this, if it goes into the database, it goes in as a string and it'll parse back as the string. It also has cool stuff like lowercase sternum and uppercase string enum. So, you can derive from that instead. And then no matter how you define your field, you get a lowercase string version or an uppercase string version.
Okay. And there's other cases as well. There's pascal case, snake case, kebab case, macro case, and camel case. Woo! Go crazy on them, people. And you can have the same code, but then like the string representation varies. So, that's pretty awesome. I think I'm going to go with kebab case just because that's fun to say.
And as people pointed out that it's not that different from what people have been considering for CPython. I'm pretty sure I'd heard about it as well in being in there, but the fact that it's not there, maybe it'll be there, maybe not. We'll see. It's interesting. But this has a lot of cool features.
And if you're not using 3.11 or want to depend upon it, you know, this is a small little project. Yeah. It's nice. Cool. Yeah. Thomas, what do you think? This is great. I especially like how it's smart enough to autocast so that when you use the enum, it will end up translating to a string when you're actually hitting the database or your underlying API.
Quite cool. All right. Ryan, over to you. I'd like to review your code a little bit. No. I don't know. I was trying to do a transition thing. But so Tim Hopper wrote this article, which I absolutely love. And it's called the Code Review Guidelines for Data Science Teams. And I just recommend everybody go read it.
It's short. It's good. But one of the things I really like that he highlighted is before he got into the code review or the code review guidelines, he started with, why are we doing a code review? What is a code review for? And this is something I think that is important just to talk with whoever, whatever team is going on and talking, maybe even sticking it in a participation guideline in a project, open source project even, is that it's not just so that we can look at the code or check it to merge it.
So his reasons for a code review are first code correctness. And that's what we think about is making sure the code's correct. But also code familiarity. Familiarity. So you might be the expert on a project and everybody else is only kind of new on it. You still should have code reviews for your code changes so that everybody else can watch also and get familiar with the changes going on.
And they're also not a reason to push off responsibility. So as long as your code's getting reviewed, it doesn't have to be correct, right? Because somebody will catch any problems. It's a bad thing to do in a code review. So make sure your code's correct. It's all cleaned up as soon as you, what you think is it's ready and then submit it, but then also be nice.
And a lot of these are just, they're just around being a kind human to the person on the other end. So that's really kind of what it's about. So I saw a mention in the summer that I really liked, which is, I mean, by nature, a code review is sort of nitpicky, right? You're paying attention to flaws, but it's nice to compliment.
Also, like if there's something nifty or cool or cute, acknowledge compliment, call attention to it. Oh, that's a, that's a good point. And I really liked that. I also think, so one of the things that you don't want to do in a code review is like one of the guidelines is, is we're not looking for perfection.
We're just, it's gotta, you know, that isn't one of the things we're looking for, but so what happens if you notice something and you're like, it's a little weird. It does it. I'd like to say something about it, but I don't know how to say that. His comment is to, to have, if you've got a minor thing that you want to comment on, go ahead and sort of tag it.
He recommends tagging it with knit in it or a nitpick or something. Just to be clear that I'm, I don't know if I like the word knit, but to be clear, Hey, I noticed this. Maybe we want to change this in the future. Somehow indicate to the person that they don't need to fix this before the PR gets merged.
Yeah. I like it. This is really handy. I love the idea of having as much as possible, have the automation, make the complaints. And like Thomas said, have the people give the compliments and the sort of interesting discussion. Right. But like if black can just take care of the formatting, like you shouldn't have to debate a formatting.
So wait a little bit. So don't, don't like review a code review right away. Especially not if the CI hasn't finished, let the CI finish and let the person creating it fix anything before you jump in. I also, that peeve of mine, don't comment on it right away. I might, one of the things I do frequently is I'll create a, a PR, especially for in a work setting, I'll create a PR and then I, there's some complicated things.
So I plan on going through and writing some comments around some of the complicated bits. Like why did I do certain things? And, so if you see a PR right away, especially from me, wait 10 minutes or so before commenting on it. Cause I might, I might've answered your question before you get a chance to ask it.
Bash it with Python. So partly inspired on the continuation of last week's discussion, you had about running sub processes from Python. And, Itamar Turner-Trowing wrote an article this week called, please, please emphasis mine. Stop writing shell scripts. Now this, as you might imagine, raised a bit of questions on the usual places like Reddit and Twitter, but if nothing else, controversy aside, the article is a very good and succinct summary of the most common gotchas and problems with bash, which we can almost all summarize as that error handling is strange.
If you're used to other programming languages, like bash is a kingdom unto its own when it comes to programming languages. So he also gives a great recommendation for if you really, really have to write in bash, uh, what you might want to do. And that would be to use the unofficial bash strict mode, which basically involves setting that bit of boilerplate on top of your bash.
Now he goes on to talk about the typical reasons we hear of why we should be using bash of which the top one is, well, it's the most common. And you're guaranteed to have an SSH runtime, at least on any given machine that you're going to be using. But the point is not really because when we're doing code automation, almost by definition, the programming language or coding in its runtime is on the server.
You don't have to set up a compiler or any of that kind of business. I say the same thing about Golang. I mean, by definition, when you're compiling Go, the Go compiler is right there. You might as well be writing a Go script or whichever your programming language is. I mean, maybe if you're starting to talk about like C or C++, there's maybe a different argument that we can have there.
It's just because it's not better because it's hard, right? We have better tools available. We have tools that behave more responsibly. And something that I think is very important in line with what you've been talking about, Brian, about building teams is very often your automation activities start becoming this specialized zone that only two or three people on the team can even look at because they're the bash gurus.
And everyone else is too afraid to touch it. Whereas if you keep your automation activities within the language you're coding in, suddenly everyone on the team can start carrying their weight, right? Yeah, I kind of relate to this a lot. I've been on projects where we've had a lot of our automation in bash and others that have been other languages.
Right now, it was one of those things, especially if you're not looking on a Windows environment, bash isn't there all automatically. And a lot of the team members might not be familiar with it. So the thing that I don't know if he addresses this, the thing that I was thinking about was we all know Python if we're programming Python.
But we might not all know the automation parts of it, the way to do like file manipulation or. Right. I say util and that kind of stuff. Stuff that we might be familiar with with bash because we, if we're using it all the time on the command line, I already know how to do it. But I might not know how to do that sort of stuff in Python because I'm not using Python like that.
But anyway, well, my response to that would be that whatever the thing is that you don't know how to do in Python, your chances of running into trouble with bash are, to my mind, a lot higher than they are with Python. Or at least when things misbehave in Python, your control of flow is better so that you probably will have a, especially as the scripts start getting bigger, you will have better control over where the issues might be.
Or you would be better able to isolate those areas that you're not exactly sure of. I saw someone in chat last week raise the specter of make files that call shell scripts that call make files. And I mean, this is not uncommon. I'm sure we've all seen these things. And I'm actually very interested in the psychology around this because we're all coders, right?
I assume we're here because we enjoy automating things. We enjoy solving problems. We probably, you know, have a certain problem solving sort of mindset that got us into this to begin with. Yet, it seems like we spend so much time automating our customers' business processes that we forget to automate our own coding processes.
Or when we do, we deallocate the priority. We de-budget it. We end up focusing on all sorts of other things other than this essential housekeeping. Yeah. Or treat it like a throwaway code instead of code that needs to be carefully factored. Exactly right. And I would argue it's a bit like housekeeping.
You know, no one likes doing it. But if you don't want to live in a big star, you've got to do it. You know, instead. Yeah. Well, also, to be honest, I was there once of like, I don't know how to do this automation stuff in Python. But it bugged me that I didn't know how. So I'm like, okay, well, what do I need to learn?
It's so handy for the automation process. There is another psychological thing, which I find, or I think psychological thing, that I find quite curious here, which is this dealing with complex shell scripts almost becomes this like technocratic rite of passage. Where when you couple that with imposter syndrome, you know, it's very easy to be intimidated by the bash bros when they do these really clever one-liner bashisms that you can't make head or tail off.
I think it's sort of the tech equivalent of, you know, back in my day, like we didn't have X, you know, like whatever X is, shoes or toilet paper or like whatever. Just because something used to be difficult doesn't mean it needs to be difficult forevermore, right? Yeah. Like the extra difficulty doesn't make it better.
Yeah, absolutely. I have some real-time feedback and also a comment for you. Alvaro says there's a VS Code plugin called Shellshock, if he's remembering it correctly. Tells me when I'm doing something wrong or it might blow up. There's also a plugin for PyCharm. So if you're going to do it, you know, have those things for sure.
Yeah, funnily enough, we've got immediate feedback to that, which is the author of the original article mentions Shellshock, which is effectively, like the commentator mentioned, a linter for Bash. But the article also mentions that it doesn't actually catch all things either. So like all linterers, it can very easily lull you into a false sense of security, while it's not really necessarily addressing the underlying problems.
And I almost feel like I don't even need to say this because anyone who's ever tried to debug a long Bash script should know this. They're tricky. They fail in mysterious places, and it's very hard to figure out why and how. Yeah, but I do like this article pointing out how, if you have to, to set up those flags to make it, you know, fail quicker.
Yeah. Because that helps a lot. So that's nice. Yeah. Yeah, for sure. And also, just to give the author massive amounts of credit, this isn't clickbait. He didn't position this as never, ever use Bash. In fact, he explicitly says that, okay, if you're doing something super simplistic, like the typical sort of things that goes into a get hook, a pre-commit hook, where you're just running a command or two, then yeah, sure.
Of course, shell script's fine. But I would say as soon as you're running loops, as soon as you're doing conditional branching, as soon as you're worried about retries, as soon as you're doing... Oh, yeah, definitely. Switch to Python. Absolutely. Yeah. Yeah. And then another quick question, just a quick follow-up.
So do we have any extras? Michael, do you have any extras? You know I got extras, right? I also, first, real quick follow-up, a real-time follow-up from Henry Scheiner in the audience, that pep663 was the PEP around string enum. Oh, okay. And he's not sure if removing the support for that PEP means removing string enum from the standard lib or not, though.
Doesn't do all the other stuff like the casing and the various other things that that cool package I talked about does. So maybe that package is, no matter what, relevant still or inspiration for the next one or whatever, right? In terms of extras, I do have some extras. Let me see what order I wanted to cover them in.
Go check it out. No, it's not true anymore. No, okay. Just if you're curious, supposedly it's moved to April 1st, but it's April Fool's Day, so I'm not sure if it's really going to happen or not. Maybe it's a long con where the joke is being set up for in advance. Yeah, exactly. Oh, we're actually never doing this.
They're axing the developer tools team too, which is just tragic. Exactly. Cut the developer tools team. They cut the threat team, the team that looks for like a tactic. It's like, I don't know. It's starting to make me a little nervous. So I'm trying out Vivaldi. I've been doing that for like a month or so, and I'm enjoying that.
And then like also DuckDuckGo. I've been using that for a while and I tried that a while ago. It just, I didn't feel like you switched. To me now, there's just like almost no difference in the quality compared to Google these days. Where it used to be, I'd try and like, I might have to go to Google for that.
Like, you know, several times a day. No, I don't really. If I get stuck here, usually I try to go to Google and get it and I get still stuck. So just got to deal with it. So that's it for all my items. I'm just down to telling a joke. Thomas, you got anything extra you want to share throughout the area of the world?
Thank you. If you do want to check it out, support open source software. Do the usual share, like, subscribe, all the rest of it. You can check it out on GitHub. It is the Piper Task Corner, P-Y-P-Y-R. And incidentally, if you don't want to run Bash scripts, then a Task Corner might be a good way of not doing so.
Yeah. I was thinking about your project while you were talking about this. I don't want to shill too horribly. So I try to keep that to the end. That's our job. We only shill. We basically just shill cool stuff all week. That's our podcast. Ryan, how about you? Got anything extra you want to shout out there?
I've got some stuff, but there's nothing I can share right now. So, yeah. All right. Well, we'll be waiting. How about we share a joke then and wrap it up? Sounds good. So I feel like this is a missed opportunity because we had Ian on last week and he was all about cybersecurity and using notebooks to track threats and stuff.
You need good cable management. This is exactly why. There's a lot of cables. They should put like orange tags on the ones that are important to pull or something. Yeah. Exactly. This is the sort of criticism that I would have expected. Actually, the entire thing has a power switch just to power off the whole thing.
You don't want to lose data. I mean, come on. No, just kidding. Also, where's the axe? How do you break the glass? Exactly. Oh, or just open the door handle. Very, not very thought through. It reminds me a little bit of that. In case fire, git commit, git push, run. I mean, you know, also we're talking about IT people who generally probably aren't, you know, that much into the pushing regime.
So, you know. Or lifting axes. You know, that might be a strain. Sorry. I'm going to get hate mail for that. Oh, we are. Yes, indeed. Well, I thought it was fun, Brian. So, well, thanks everybody for having a fun episode again. Thank you, Thomas, for showing up. Thanks, Michael. And thank you, everybody in the chat for showing up.
