Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #379: Constable on the debugging case

Return to episode page view on github
Recorded on Tuesday, Apr 16, 2024.

00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.

00:05 This is episode 379, recorded April 16th, and I am Brian Okken.

00:10 And I'm Michael Kennedy.

00:11 This week we are sponsored by us, Talk Python training courses, and also the pytest course,

00:18 and our Patreon supporters. We love everybody that supports us. We really appreciate it.

00:23 And if you'd like to connect with us, we're all on Fostadon, on Mastodon.

00:28 So it's @mkennedy, @brianocken, and @pythonbytes.

00:33 And I wanted to shout out to myself, I guess, and Michael for we're doing a newsletter now.

00:40 So if you head over to pythonbytes.fm and join the friends of the show list,

00:45 we will send you an email with all of the tidbits.

00:48 So if you happen to miss an episode, you can catch up on all the links that we share.

00:52 Michael, why don't you kick us off with our first topic?

00:58 Let's get started, huh?

01:00 So I want to talk about an article by Stephanie Mullin.

01:04 She put together this really nice article on something that I don't use very much,

01:08 Git pre-commit hooks. Do you use Git pre-commit hooks?

01:10 Not, yes, on some projects.

01:14 Yeah, and I just think there's a lot of possibility for interesting things there.

01:18 And, you know, I've considered it, but you don't want stuff that like takes a long time to run

01:24 there, so like how much value do you get? But nowadays with tools like Ruff and others that

01:29 run really quickly, it's basically you wouldn't even really notice it, right?

01:33 So it's not a lot of overhead.

01:36 So maybe it's time to reconsider Git pre-commit hooks.

01:40 And she has a really nice walkthrough here.

01:42 So I just kind of want to set out some of the motivation and kind of call attention

01:45 to this article.

01:46 People can come check it out and set up pre-commit hooks for themselves.

01:49 So why do you care about these things?

01:51 They give developers near instant feedback of code locally.

01:54 So not all, but some of the things that would run in continuous integration,

01:58 like linting checks and other types of checks run.

02:03 And when you try to do a Git commit, and if it, for some reason, there's a problem, right?

02:09 Like it won't even let you commit.

02:10 It'll say, no, can't commit.

02:11 You've got to fix the issue detected by the pre-commit hook.

02:14 So it's kind of a gate before stuff actually gets into broader source control world.

02:20 And super valuable if you're on a team, but also if you just want to make sure,

02:24 like, I kind of want to make sure I'm doing this for myself, for my own project,

02:27 or I'm working alone at a company and I still want to make sure these things happen,

02:31 then throw them in there.

02:32 That's for you.

02:32 Also, the continuous integration side of thing is pretty excellent.

02:36 So here she's using a project, I believe by Anthony Sotili called pre-commit.

02:44 And pre-commit is a Python project, but it's not only for Python things and Git and source control, it just happens to run on Python.

02:52 Like some things run on C, some things run on Rust.

02:54 This is what runs on Python.

02:56 So basically, as long as you can run Python things, you have an interpreter,

02:59 you can use pre-commit for whatever projects.

03:02 You know, if you're a React native person, you could use pre-commit for it, right?

03:05 - Yeah.

03:06 - So there's a nice example of showing how to set up a bunch of checks.

03:09 And it's super easy.

03:10 Basically, you set up pre-commit-config-.yml file or .yml.

03:15 And then you specify different things to run.

03:19 And so you can say, I want to run the hooks for check the format for the toml file,

03:23 check the format for yml files.

03:24 Make sure that every file ends with a blank line, trim out all white, trailing white space.

03:31 All those kinds, those are all pretty simple and pretty nice, right?

03:34 - Yes.

03:34 - Another one is throw in the rough pre-commit.

03:38 And then I'll just say run rough and run rough format, which will fix up the things.

03:44 And you can even pass arguments to it through these pre-commit hooks here,

03:48 which is pretty cool.

03:49 Yeah, so that's pretty much it.

03:50 Once you set up your file, you just have to run pre-commit install, which will download all the hooks that you've mentioned that you want to run,

04:00 all the checkers.

04:01 And it'll actually create virtual environments for those and install them in there.

04:05 So the first time it's a little bit slow, but then the next time it's plenty quick.

04:08 And finally, if for some reason you're like, you know what, I know it keeps complaining,

04:12 but this time I just need it to commit for whatever reason, you can use down here, find it.

04:18 You can specify git commit --no verify.

04:22 That'll just say it's going in.

04:24 I don't care it's going in if you need to kind of override it.

04:28 So yeah, it's pretty straightforward, really nice write up.

04:30 And people can check that out if the idea appeals.

04:33 - Actually, this is a great timing for this because I have used it in years past,

04:39 and there's times where I've added like a whole bunch of stuff.

04:41 And it kind of slows down my process.

04:45 But with the recent rustification of a lot of our tools, like with rough and stuff,

04:50 things are pretty zippy now.

04:53 So I don't think it'll slow down things that much.

04:55 - Yeah, I doubt you'd really even notice it, you know?

04:58 - Yeah, depending on what kind of tools you have.

05:00 - When it fails, you'll notice.

05:02 - Yeah, and I do like the shout out.

05:05 There's a couple of things I love about this.

05:06 I like the shout out to the no verify, because there's times where you're just running off to vacation

05:11 and you have to commit your stuff no matter what.

05:13 Get that in there, especially if it's on a developer branch or something.

05:19 - Yeah, that's a good point if it's not on the main branch, but you're like, you know what, I'm just going to put it here

05:23 because I want to get it over to my laptop and I'm leaving.

05:26 - Yeah, I need it saved.

05:27 The other thing is running down some of the rough settings.

05:32 So I love some of the configuration that she's included with how to configure rough.

05:39 Because rough is awesome by default, but there's some cool configuration you can do,

05:43 like setting the quote style to single and stuff like that.

05:47 So neat.

05:48 - Indeed. Very, very neat.

05:50 Yeah, Stephanie's doing a bunch of cool stuff, so people should check out broadly what she's up to.

05:55 But this article is really nice.

05:56 - Yeah.

05:56 - All right, over to you, Brian.

05:57 - Well, I want to talk about something I talked about two years ago.

06:01 So I was researching this Difftastic, and I'm like, I'm really loving this tool.

06:07 I got to cover it, and I apparently covered it two years ago, but I haven't started using it until just recently.

06:15 So Difftastic is a tool, and I think it's written in Rust.

06:21 I'm not sure actually, but it's a super fast diff tool, and it does coloring,

06:27 but there's a lot of stuff I love about it.

06:29 The reasons why I'm using it a lot.

06:31 The colors are great, by the way.

06:33 Awesome, nice red, green, different colors.

06:36 But what I really love is that it's a diff tool that's not a line-by-line,

06:43 character-by-character diff.

06:44 It understands your syntax, and it only changes things that really change.

06:48 So if you happen to add a new line in there or something, it's not going to show you that diff.

06:53 It's going to do just real changes to your code, which is super helpful.

06:58 I hate it when you have to turn off.

07:02 By default, it doesn't show you that.

07:04 So I don't like to see if I messed up some spacing and somebody fixed that.

07:10 That's not a real diff.

07:11 I don't need to see that.

07:12 So having syntax-based is great.

07:15 What I really love is what I'm going to highlight here is there's instructions.

07:20 It tells you how to do it, and I can't remember where the link is.

07:24 But I'm going to show it right here.

07:26 In the manual for Difftastic, it shows you how to set this up for diff.

07:33 So you can-- for git diff.

07:34 So if you're using it with git and you want to just try it out, it shows you how to just set your git external diff,

07:43 and then you can try it out.

07:44 What I really love is the real winner is doing a log.

07:48 So showing what you've done on the file recently is great with the git log.

07:54 But if you do that with the external diff of Difftastic, it's a fantastic experience,

07:59 especially if you've got a large screen, which I do right now.

08:03 And it just makes things-- working with git so much easier.

08:07 So definitely, if you haven't tried Difftastic yet, try it.

08:10 And try the-- so it shows you how to do it just like one-offs for git.

08:15 But also, it shows you how to set up your git config so that you can use it all the time.

08:21 So this is fantastic.

08:23 Yeah, very excellent.

08:24 Are you starting to use it?

08:25 I'm using it every day now.

08:27 It's just part of my workflow.

08:29 So yeah.

08:30 Mike Feehler out in the audience says, "Difftastic is indeed in Rust." Yeah, it's one of those-- it's super fast.

08:38 I love-- I'm going to have to start learning Rust, I guess, maybe.

08:42 But-- or just-- I just love other people writing Rust for me so that I can write my Python even

08:48 faster.

08:48 It's like-- it's kind of like when you use Jupyter Notebooks.

08:51 You don't have to learn TypeScript and JavaScript and all those things.

08:54 You can just--

08:55 That's true.

08:55 --use them and appreciate that someone else took one for the team.

08:58 Yeah, yeah.

08:59 Yeah, so awesome.

09:01 All right, actually, speaking exactly of that kind of stuff, the next thing I wanted to

09:05 give a shout out to here, the next topic, is Quarto.

09:08 Have you heard of Quarto?

09:09 I don't believe so.

09:11 Yeah, so Quarto is pretty cool.

09:13 It lives solidly in the-- I want to publish stuff for various reasons, maybe because I

09:18 want a blog or a website or I want to write an e-book or I just want to create a web page

09:24 that shows my research or visualizations for my company or something like that.

09:29 So basically, it's an open source scientific and technical publishing system based on Jupyter

09:36 Notebooks.

09:37 And a lot of people have been talking about this and recommending this lately.

09:40 So I thought I'd give it a look.

09:43 So the idea is you write in Jupyter Notebooks with plain text or markdown or whatever you

09:49 want to use.

09:49 And then you create the dynamic elements in Python, R, Julia, or Observable.

09:54 Observable has always been an adjective.

09:56 I didn't know it was a noun, but OK.

09:57 Yeah, I may have to check that out later.

10:01 But basically, most relevant point is you can write your stuff in Python.

10:05 And then you can create production quality articles, dashboards, websites, blogs, and

10:12 even EPUB books.

10:14 So HTML, PDF, even Word, EPUB, and so on, which is pretty awesome.

10:18 And then it comes out of the Posit folks.

10:21 You can connect it to Posit Connect if you want.

10:23 But then you can write in HandDoc markdown as well and get fancy math equation type things,

10:31 you know, like integral from 0 to infinity of that to that.

10:34 And it looks proper, like you would see in calculus class, not weird ASCII representations

10:41 to it.

10:41 So yeah, it looks pretty awesome.

10:44 It has the ability to show or hide the code.

10:46 You go to their website, you can see there's a little example of here's a notebook and

10:50 then here's actually publication of it, which I think it's pretty cool.

10:54 What do you think, Brian?

10:55 I think this is excellent.

10:56 I definitely want to try this out.

10:58 I've been itching to write more long form.

11:01 And doing something like this would be great.

11:04 I think it would, especially if you use Python to sort of express what you're working on

11:09 or what you're doing, right?

11:10 It would be super, super cool.

11:11 Yeah, and Pandoc, it's cool they're using Pandoc markdown.

11:14 Because I mean, markdown is amazing, but the Pandoc's flavors of markdown, there's a bunch

11:20 of cool extensions.

11:21 So it's pretty neat.

11:23 Yeah.

11:23 Also, final thing, you apparently can embed things like Jupyter widgets, HTML widgets

11:30 and others to let people sort of interact with the page as well, which is also cool.

11:34 Yeah, neat.

11:36 Yeah.

11:37 All right.

11:37 So if this is your world, check it out.

11:38 Definitely.

11:41 Okay, next, I want to talk about Constable.

11:46 So this is a simple debugging tool.

11:49 Looks like it's fairly new.

11:51 Look at that.

11:52 So--

11:53 Wow.

11:54 Initial commit four days ago.

11:56 If you find yourself aimlessly adding print statements while debugging your code, this

12:04 might be for you.

12:05 So this is actually pretty neat.

12:07 I like it.

12:08 So you throw like in the example, you throw a decorator at constable.trace, and then you

12:15 can throw in which variables you want to trace.

12:17 And it just like, it shows you some cool output of like what happens while you're running.

12:23 And you can walk through and it does the changes to your-- which line changed your variable

12:30 and what did it change it to and all that sort of stuff.

12:33 And it's kind of--

12:34 each line that changes, Brian, it prints out like as the variables change at any step,

12:39 it'll say here's what the new values are, which is cool.

12:42 But it kind of describes it, which is awesome.

12:43 It'll say like this equation ran, so now it's a new-- this statement ran, so here's the

12:48 value.

12:48 This statement ran, so now here's the value.

12:50 It's really good.

12:52 Yeah, it's fairly verbose, but-- and with a lot of spacing in here.

12:56 But I think that's good, because you're probably going to like throw it on just a couple of

13:00 functions to when you're debugging at the time and then pull it out later.

13:03 You said production.

13:04 Don't put it in production.

13:06 I was wondering this too.

13:08 So I forgot the name of the other tool that was kind of like this.

13:11 And Mike Felder, or Fiedler, says, I wonder how Constable compares to ice cream.

13:17 And I think I would take this as Mike is volunteering to do a write-up of comparing Constable and

13:24 ice cream.

13:25 Definitely.

13:25 Thanks, Mike.

13:26 Sounds-- thanks, Mike.

13:27 Yeah, let us know when that's written up and we'll take a look.

13:30 No, I think probably a lot of this is just probably feel, like how does it feel to you

13:38 if it fits your workflow or not.

13:40 So this looks fun.

13:43 Yeah, this looks very fun.

13:44 And both are new to me, so it's worth checking out.

13:47 OK.

13:47 And if Mike doesn't want to do it, maybe I'll take a look at comparing Constable.

13:50 Excellent.

13:51 You could write it in Cordo.

13:52 Yeah.

13:52 Yeah.

13:54 So apparently Mike didn't-- was surprised at-- no?

14:00 You know, the volunteering.

14:02 So anyway, so yeah, Constable for debugging print statements.

14:08 Or it's easier than print statements.

14:10 Yeah, nice.

14:11 Cool.

14:12 I'm going to work it into my world, I think.

14:14 It looks good.

14:15 What do you got for us next?

14:17 Extra, extra stuff.

14:19 It's all-- I have only one extra thing.

14:22 Oh, we're done with our topics already?

14:23 I believe so.

14:24 Yeah, we are.

14:24 Time flies when you're having fun, you know, and you're--

14:26 Yeah.

14:27 Time flies.

14:27 All right.

14:28 So at least I've done-- I've got nothing else.

14:30 How's that?

14:31 So two pieces of news here.

14:35 They're all-- they're both the same piece of news.

14:37 So Python 3.12.3 final is out, which comes with 1, 2, 3, 4 security updates.

14:45 They don't sound like any sort of big deal, so I wouldn't like run and patch it now or

14:53 anything, but there are some things listed under security, so that's always worth thinking

14:57 about, but there's also quite a few changes under built-in, under library.

15:00 I mean, just gauging by the scrolling, I would say there's probably 50 or 60 changes.

15:06 That's a big change for a .3, .2 to .3.

15:09 Yeah, yeah.

15:09 And why not?

15:11 Why not upgrade?

15:13 So absolutely.

15:15 And I would-- just the other piece of news is that Python bytes and all the other things

15:20 are already running on 3.12.3, just bump a number, kick off the Docker update, and boom.

15:28 Sweet.

15:28 We're updated.

15:29 Yeah, very nice to have that set up in place.

15:31 Extras for you?

15:32 Just one that I was excited to cover, but then like-- okay, so I'll just talk about it.

15:38 It's a couple-- oh, you appear to be offline.

15:41 It's a couple weeks old, but pointers are going to be added to the standard library

15:47 with pep4.

15:48 What?

15:49 Yeah.

15:49 What?

15:50 Apparently, Guida says, why the hell not?

15:54 Why not add pointers?

15:55 This will also introduce pointer literals, size of operators, and memory errors.

16:00 Actually, I was perusing Reddit in Python and noticed this, and I'm like, what's going on?

16:08 And then I noticed the date.

16:09 It was 15 days ago.

16:10 That would have been April Fool's, April 1st.

16:13 So--

16:13 Rough.

16:14 I actually got--

16:15 Rough, rough.

16:15 --snagged on this.

16:18 This is sort of funny, though.

16:19 This is funny.

16:21 It even has the C syntax, like ampersand to grab the pointer of a variable, a star to

16:26 dereference the pointer.

16:27 It's all sorts of stuff.

16:28 Yeah, malloc, memory malloc.

16:30 Malloc, why not?

16:30 Why not?

16:31 New size of operator.

16:33 The irony is everything in Python has a pointer.

16:36 You just can't directly address them, right?

16:39 You can't work with them that way.

16:41 Oh, yeah.

16:42 No pass by-- there's no pass reference.

16:45 The ampersand operator in C, where you could change the value of the pointer within somewhere

16:51 else and stuff.

16:52 I love this example.

16:53 Spam equals star of none.

16:55 That will segfault core dump.

16:58 Good luck, kiddo.

16:59 This is good.

17:03 I enjoy it.

17:04 All right.

17:05 People comments are like, nice one.

17:06 I believed it.

17:07 I believed it.

17:08 I believed it for a second, except for--

17:10 Anyway.

17:12 But there is an infamous pointers.py.

17:14 So is that a real thing?

17:16 You can-- no.

17:17 Bringing the hell of pointers to Python.

17:19 From pointers import underscore.

17:22 That's funny.

17:25 Anyway.

17:26 All right.

17:27 So--

17:28 This is involved, right?

17:30 Involved.

17:31 This is in depth.

17:32 That wasn't just a Reddit post.

17:33 It's got a whole GitHub repo.

17:35 Yeah.

17:36 Example.

17:36 There's a ton of code here.

17:37 What are they doing?

17:38 This is awesome.

17:42 Why does this exist?

17:44 Anyway.

17:44 Lays out in the audience says, I would have believed it too.

17:47 One of the features is segfaults.

17:50 Always a good time.

17:53 Always a good time.

17:54 Yeah.

17:54 All right.

17:55 So that was funny.

17:57 But do you have anything else funny for us?

17:59 I do.

18:00 And it's very much in the same vein.

18:02 Although I don't think it's the same date.

18:04 I think it's just more random.

18:05 So check this out.

18:06 Henik from the Python community, who we speak about often, is here.

18:11 Holding this award that is a Hugo.

18:14 Hugo, not the static site generator, but the awards for--

18:18 So like a sci-fi award or something?

18:21 Yeah.

18:21 For best sci-fi.

18:22 Best science fiction.

18:24 So here's the thing.

18:25 Very happy to accept a Hugo award for my science fiction short story.

18:29 The day Python packaging made everyone happy.

18:32 Good one Henik.

18:37 That is excellent.

18:40 Nice.

18:41 Someday.

18:42 And science fiction is a good angle here, right?

18:46 Because science fiction is the sort of stuff that's not real now.

18:49 But you can imagine maybe, but probably not at some point in the future.

18:54 Like the year 3000 will all be fine.

18:56 Yeah.

18:58 I don't believe anything until I get my hover skateboard.

19:01 I know.

19:02 All it's going to be about is people crashing and falling over backwards on YouTube

19:07 on the hover skateboard once we all get them.

19:09 Yeah.

19:11 So like the ones with wheels now, but now when you hover, it'll be even more tippy.

19:15 Still trying to figure out how you turn on something that hovers.

19:18 I know.

19:19 Anyway.

19:20 All right.

19:21 Well, thanks.

19:22 This was fun.

19:23 Pretty quick episode, but--

19:25 Oh, Mike says hover skateboard uses pointers and seg faults.

19:32 Yeah.

19:34 So and then we can get like--

19:36 we can get Devin and our AI to create seg faults for us.

19:41 Yeah, that'd be awesome.

19:42 Not my fault.

19:43 I didn't take down production.

19:44 Devin did.

19:45 I wonder if the segue is written in C.

19:47 I wonder if segways have seg faults.

19:49 I bet they do.

19:50 Yeah.

19:50 It would be fitting.

19:52 All right.

19:54 Well, thanks, everybody, for showing up.

19:56 If you want to--

19:57 and if you're listening and you want to join the fun of talking with us while we're doing

20:03 a podcast, head over to pythonbytes.fm, and you can see what the schedule is for the next

20:08 live episode.

20:09 Indeed.

20:10 Thanks, Brian.

20:11 Thank you.

Back to show page