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

#379: Constable on the debugging case

Published Tue, Apr 16, 2024, recorded Tue, Apr 16, 2024
Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by us! Support our work through:

Connect with the hosts

Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too.

Finally, if you want an artisanal, hand-crafted digest of every week of

the show notes in email form? Add your name and email to our friends of the show list, we'll never share it.

Michael #1: How to Set Up Pre-Commit Hooks A step-by-step guide to installing and configuring pre-commit hooks on your project.

  • by Stefanie Molin
  • Pre-commit hooks are code checks that run as part of the “pre-commit” stage of the git commit process.
  • If any of these checks fail, git aborts the commit
  • Sometimes, we need to bypass the hooks temporarily. For these instances, we can pass the --no-verify option when we run git commit

Brian #2: difftastic

  • Found this a couple years ago, but really using it a lot now.
  • Excellent structurally diff tool that compares code based on syntax, not line by line.

Michael #3: Quarto

  • via Mathias Johansson
  • An open-source scientific and technical publishing system
  • Transforming a notebook into a pdf / HTML / MS Word / ePub with minimal effort, or even all formats at once.
  • Author using Jupyter notebooks or with plain text markdown in your favorite editor.
  • Write using Pandoc markdown, including equations, citations, crossrefs, figure panels, callouts, advanced layout, and more.

Brian #4: constable

  • “inserts print statements directly into the AST at runtime “
  • “If you find yourself aimlessly adding print statements while debugging your code, this is for you. !”
  • Add decorators like @constable.trace('a', 'b') to functions and you’ll get nice output showing when and how a and b changed.
  • see also icecream for another fun debugging with print project.

Extras

Brian:

Michael:

Joke: Hugo SciFi Award

Episode Transcript

Collapse transcript

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

00:04 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. So it's at mkennedy,

00:30 at Brian Okken and at Python Bytes. And I wanted to shout out to myself, I guess, and Michael for

00:36 we're doing a newsletter now. So if you head over to pythonbytes.fm and join the friends of the show

00:45 list, we will send you an email with all of the tidbits. So if you happen to miss an episode,

00:50 you can catch up on all the links that we share. So Michael, why don't you kick us off with our first

00:57 topic? Let's get started, huh? So I want to talk about an article by Stephanie Molin. She put together

01:05 this really nice article on something that I don't use very much, Git Precommit Hooks. Do you use Git

01:10 Precommit Hooks? Not, yes, on some projects. Yeah. And I just think there's a lot of possibility for

01:17 interesting things there. And, you know, I've considered it, but you don't want stuff that like

01:23 takes a long time to run there. So like how much value do you get? But nowadays with tools like

01:28 Ruff and others that run really quickly, it's basically you wouldn't even really notice it,

01:33 right? So it's not a lot of overhead. So maybe it's time to reconsider Git Precommit Hooks. And

01:40 she has a really nice walkthrough here. So I just kind of want to set out some of the motivation and

01:44 kind of call attention to this article. People can come check it out and set up Precommit Hooks for

01:49 themselves. So why do you care about these things? They give developers near instant feedback of code

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

02:00 checks and other types of checks run. And when you try to do a Git commit, and if it, for some reason,

02:07 there's a problem, right? Like it won't even let you commit. It'll say, no, it can't commit.

02:11 But you've got to fix the issue detected by the precommit hook. So it's kind of a gate

02:16 before stuff actually gets into broader source control world. And, you know, super valuable if

02:22 you're on a team, but also if you just want to make sure like, I kind of want to make sure I'm doing

02:25 this for myself for my own project, or I'm working alone at a company, and I still want to make sure

02:30 these things happen, then throw them in there. That's for you. Also, the continuous integration side of

02:35 thing is pretty excellent. So here, she's using a project, I believe by Anthony Sotili,

02:42 called precommit. And precommit is a Python project, but it's not only for Python things and Git and

02:50 source control. It just happens to run on Python, like some things run on C, some things run on Rust.

02:54 That's what runs on Python. So basically, as long as you can run Python things, you have an interpreter,

02:59 you can use precommit for whatever projects, you know, if you're a React native person, you could

03:04 use precommit for it, right? Yeah. So there's a nice example of showing how to set up a bunch of checks.

03:09 And it's super easy. Basically, you set up pre-commit-config-yaml file or .yaml. And then you

03:16 specify different things to run. And so you can say, I want to run the hooks forward, check the format for

03:22 the toml file, check the format for yaml files, make sure that every file ends with a blank line,

03:28 trim out all white, trailing white space, all those kinds. Those are all pretty simple and pretty nice,

03:34 right? Yes. Another one is throw in the rough precommit. And then I'll just say, run rough and run rough

03:41 format, which will fix up the things. And you can even pass arguments, do it through these precommit

03:47 hooks here, which is pretty cool. Yeah. So, you know, that's pretty much it. Once you set up your file, you just

03:53 have to run precommit install, which will, you know, download all the hooks that you've mentioned

03:59 that you want to run, all the checkers. And it'll actually create virtual environments for those and

04:04 install them in there. So the first time it's a little bit slow, but then the next time it's

04:07 plenty quick. 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 because for whatever reason you can use down here,

04:18 find it, you can specify get commit --no verify. And 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. So yeah, it's pretty straightforward,

04:29 really nice write up and people can check that out. If the idea appeals.

04:33 This is a great timing for this because I have used it in years past and there's times where I've

04:40 added like a whole bunch of stuff and it kind of slows down my process. But with the recent

04:46 rustification of a lot of a lot of our tools, like with rough and stuff, things are pretty zippy

04:53 now. So I don't think it'll slow down things that much. Yeah. I doubt you really even notice it,

04:58 you know? Yeah. For depending on what kind of tools you can do. When it fails, you'll notice.

05:02 Yeah. And I do like the, the shout out. There's a couple of things I love about this. I like the

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

05:11 and you have to commit your stuff no matter what, get that in there. Especially if it's on a,

05:16 like a brand developer branch or something. Yeah. That's a good point. If it's not on the main

05:21 branch, but you're like, you know what? I'm just going to put it here because I want to get it over

05:24 to my laptop and I'm leaving. Yeah. I need it saved. The other thing is running down some of the,

05:31 the rough settings. So I love, I love some of the configuration that she's included with,

05:35 with like how to configure rough. Cause rough, rough is awesome by default, but there's some cool

05:42 configuration you can do like setting, setting the quote style to single and stuff like that. So neat.

05:49 Very, very neat. Yeah. Stephanie's doing a bunch of cool stuff. So people should check out broadly

05:54 what she's up to, but this article is really nice. Yeah. Over to you, Ryan.

05:57 Well, I want to talk about something I talked about two years ago. So I was researching this

06:03 Diftastic and I'm like, I'm, I'm really loving this, this tool. I got to cover it. And I apparently

06:09 covered it two years ago, but I didn't, I haven't started using it until just recently. So

06:15 Diftastic is a tool and I, I think it's written in Rust. I'm not sure actually, but it's a super fast

06:24 Dift tool and it's, it does coloring, but there's a lot of stuff I love about it. The reasons why I'm

06:30 using it a lot. The colors are great, by the way. Awesome. Nice red, green, different colors.

06:36 But what I really love is that it's not, it's a Dift tool. That's not a line by line character by

06:43 character Dift. It's, it understands your syntax and it only changes things that really change. So if you

06:49 happen to add a new line in there or something, it's not going to show you that Dift. It's going to do

06:55 just real changes to your code, which is super helpful. I hate it when, when you have to like

07:01 turn off by default, it doesn't show you that. So I, I don't like to see if somebody, if I messed up

07:08 some spacing and somebody fixed that, that's not a real Dift. I don't need to see that. So having

07:13 syntax based is great. What I really love is what I've I'm going to highlight here is there's,

07:19 there's instructions. Oh, it tells you how to do it. And I can't remember where the link is,

07:24 but it, it, I'm going to show it right here. The, the, in the manual for a get tastic or Diftastic,

07:30 it shows you how to set this up for diff. So you can forget diff. So if you're using with get,

07:36 and you, you know, you want to just try it out, it shows you how to just set your get external diff,

07:42 and then you can try it out. What I really love is the real winner is doing a log. So

07:49 showing what you've done on the file recently is great with the get log. But if you do that with

07:55 the external diff of Diftastic, it's a fantastic experience, especially if you've got a large screen,

08:02 which I do right now. And it just makes things working with get so much easier. So definitely,

08:07 if you haven't tried Diftastic yet, try it and try, try the, so it shows you how to do it just

08:13 like one-offs for get, but it also, it shows you how to set up your get configs so that you can use it

08:20 all the time. So this is fantastic. Yeah. Very excellent. Are you starting to use it?

08:25 I'm using it every day now. It's just part of my workflow. So yeah.

08:30 Mike Fieler out in the audience says, Diftastic is indeed in Rust.

08:36 Yeah. It's, it's one of those, it's super fast. I love, I'm going to have to start learning Rust,

08:41 I guess, maybe, but, or, or just, I just love other people writing Rust for me so that I can,

08:46 I can write my Python even faster.

08:48 So it's like, it's kind of like when you use Jupyter notebooks, you don't have to learn TypeScript

08:52 and JavaScript and all those things. You can just use them and appreciate that someone else took one

08:57 for the team. Yeah. Yeah. Yeah. So awesome.

09:01 All right. Actually speaking exactly of that kind of stuff, the next thing I wanted to give a shout

09:05 out to here, the next topic is Quarto. Have you heard of Quarto? I don't believe so.

09:10 Yeah. So Quarto is pretty cool. It lives solidly in the, I want to publish stuff for various reasons,

09:18 maybe because I want a blog or a website or I want to write an ebook, or I just want to create a webpage

09:24 that shows my, my research or visualizations for my company or something like that. So basically it's

09:31 an open source scientific and technical publishing system based on Jupyter notebooks. And a lot of people

09:38 have been talking about this and recommending this lately. So I thought I'd give it a look. And so the

09:43 idea is you write in Jupyter notebooks with plain text or markdown or whatever you want to use.

09:49 And then you create the dynamic elements in Python, R, Julia, or observable. The role has always been an

09:55 adjective. I didn't know it was a noun, but okay. Yeah. I may have to check that out later, but

10:01 basically most relevant point is you write, you can write your stuff in Python and then you can create

10:07 production quality articles, dashboards, websites, blogs, and even EPUB books. So HTML, PDF, even Word,

10:16 EPUB and so on, which is pretty awesome. And then it's, it comes out of the Posit books. You can connect

10:22 it to Posit Connect if you want, but then you can write in hand doc markdown as well and get like

10:28 fancy math equation type things, you know, like integral from zero to infinity of that, to that. And

10:34 right. It looks proper, like you would see in calculus class, not weird ASCII representations to

10:41 it. So yeah, it looks, it looks pretty awesome. It has ability to like show or hide the code. You can

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

10:50 actually publication of it, which I don't know. I think it's, it's pretty cool. What do you think,

10:55 Brian? I think this is excellent. I definitely want to try this out. I've been itching to write more

11:00 long form and doing, doing something like this would be great. I think it would, especially if

11:06 you use Python to sort of express what you're working on or what you're doing, right? Yeah.

11:11 Super, super cool. Yeah. And pan doc, it's cool. They're using pan doc markdown because,

11:15 I mean, markdown is amazing, but the pan docs flavors of markdown, there's a bunch of cool

11:20 extensions. So that's pretty neat. Yeah. Also final thing you compare, apparently can embed things like

11:27 Jupyter widgets, HTML, widgets and others to let people sort of interact with the page as well,

11:33 which is also cool. Yeah. Neat. Yeah. All right. So this is your world. Check it out.

11:39 Definitely. Okay. Next, I want to talk about Constable. So this is a simple,

11:48 a simple debugging tool. Looks like it's fairly new. Look at that. So Constable.

11:55 Commit four days ago. If you find yourself aimlessly adding print statements while debugging

12:02 your code, this, this might be for you. So this is actually pretty neat. Oh, I like it.

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

12:15 throw in which variables you want to trace. And it just like, it shows you some cool output of like

12:21 what happens while you're, while you're running. And the, you can walk through and it does the

12:26 changes to your, which line changed your variable and what did it change it to and all that sort of

12:32 stuff. And it's kind of a. Each line that changes, right? It, it prints out like as the variables

12:38 change at any step, it'll say, here's what the new values are, which is cool, but it kind of describes

12:43 it, which is awesome. It'll say like this equation ran. So now it's a new, this statement ran. So

12:47 here's the value of this statement ran. So now here's the value. It's, it's really good.

12:51 Yeah. It's, it's fairly verbose, but, and with, with a lot of spacing in here, but I think that's

12:57 good is because you're, you're probably going to like throw it on just a couple of functions to

13:01 when you're debugging at the time and then pull it out.

13:03 Is it production?

13:04 Don't put it in production. I was wondering this too. So I forgot the name of the, the, the other tool

13:10 that was kind of like this. And Mike Felder or Fiedler says, I wonder how constable compares to

13:16 ice cream. And I think, I think I would take this as Mike is volunteering to do a write-up of comparing

13:23 constable and ice cream.

13:25 Definitely. Thanks, Mike.

13:26 Sounds. Thanks, Mike. Yeah. Let us know when that's written up and we'll take a look.

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

13:38 if it fits your workflow or not? So this, this looks fun. So yeah, this looks very fun and both are new

13:44 to me. So it's, it's worth checking out. Okay. And if Mike doesn't want to do it, maybe I'll take a

13:49 look at comparing constable. Excellent. You could write it in quarter. Yeah. Yeah. So apparently Mike

13:57 didn't, didn't, was surprised at, you know, the volunteering. So anyway, so yeah, constable for

14:07 debugging print statements or it's easier than print statements. Yeah. Nice. Cool. I'm going to work

14:12 it into my, my world. I think it looks good. What do you got for us next? Extra, extra stuff. It's all,

14:20 I have only one extra thing. Oh, we're done with our topics already? I'm blue. So we are flies when you

14:25 have fun, you know, and you're cool. I flies. All right. So at least I'm done. I've got nothing

14:30 else. How's that? So two pieces of news here. They're all, they're both the same piece of news.

14:37 So Python 312.3 final is out, which comes with one, two, three, four security updates. They don't sound

14:46 like any sort of big deal. So, wouldn't like run, run and patch it now or anything, but there are

14:54 some things that sit under security. So that's always worth thinking about, but there's also quite a few

14:58 changes under built-in under library. I mean, just gauging by the scrolling, I would say there's probably 50 or 60

15:06 changes. That's a big change for a dot three dot tutor dot three. Yeah. Yeah. and why not?

15:11 Why not upgrade? So absolutely. And I would, just the other piece of news is that Python bytes and

15:19 all the other, other things are already running on a 312.3, just bump a number, kick off the, the Docker

15:27 update and boom. Yeah. Very nice to have that, that set up in place. Extras for you. just one that I

15:34 like was excited to cover, but then like, okay, so I'll just, I'll just talk about it. It's a couple

15:39 of, you appear to be offline. it's a couple weeks old, but pointers are going to be added

15:46 to the standard library with PEP for what? Yeah. What? apparently, Guida says, you know,

15:53 why the hell not? why not add pointers? This will induce, it, this will also introduce,

15:58 pointer literals size of operators and memory errors. actually I was perusing Reddit in

16:05 Python and noticed this and I'm like, what's going on. And then I noticed the date was 15

16:10 days ago. That would have been April fools. April 1st. So rough. I actually got off,

16:15 rough.

16:16 snagged on this. This is sort of funny though.

16:19 This is funny. I even has the C syntax, like ampersand to grab the pointer of a variable,

16:26 a star to dereference the pointer. It's all sorts of stuff.

16:28 Yeah. Malik.

16:29 Malik. Why not?

16:30 Why not?

16:31 New size of operator.

16:34 the irony is everything in Python as a pointer. You just can't directly address them. Right.

16:39 You can't, you can't work with them that way. no pass by rep. There's no pat like pass

16:44 reference, you know, the, the ampersand operator and C where like you could change the value of

16:49 the pointer, like within somewhere else. And so what, I love this example, spam equals star

16:54 of none. that's that will seg fault core dump. Good luck kiddo.

17:01 But this is good. I enjoy it. So yeah. All right.

17:05 People comments are like nice when I believed it. I believed it.

17:08 I believed it for a second except for, you know, anyway, but there is a infamous pointers.py.

17:14 So is that a real thing you can know bringing the hell of pointers to Python

17:19 from pointers and poor underscore.

17:22 That's funny. Anyway. all right. So, this is, this is the ball, right? Involved. This is,

17:31 in-depth that wasn't just a Reddit post. It's got like a whole GitHub repo.

17:35 Yeah. Example. There's like a ton of code here. What are they doing?

17:38 this is awesome. Why does this exist? Anyway.

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

17:47 one of the features is seg faults.

17:51 always a good time. Always a good time. Yeah. All right. So, that was funny,

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

17:59 I do. And it's very much in the same vein, although I don't think it's the same date.

18:04 I think it's just more random. So check this out.

18:06 Hennick from the Python community who we speak about often is here holding this award.

18:13 That is a Hugo, you know, Hugo, the, not the static site generator, but the,

18:17 the awards for, It's like a sci-fi award or something.

18:21 Yeah. For best sci-fi science fiction. 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 work, Hennick.

18:38 That is, that is excellent.

18:40 Someday.

18:42 And the science fiction is, is a good angle here. Right.

18:46 Because science fiction is the sort of stuff that's not real now, but you can imagine maybe, but probably not.

18:52 At some point in the future, like the year 3000.

18:55 Well, I'll be fine.

18:56 Yeah. Well, I, well, I don't believe anything until I get my hover skateboard.

19:01 I know.

19:02 So we're just going to be, 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 Well, yeah.

19:10 Just like the ones with wheels now, but now when you hover, you'll even more tippy.

19:15 Still fine.

19:15 I'm trying to figure out how you turn on something that hovers.

19:18 I know.

19:19 But anyway, all right.

19:21 All right.

19:22 Well, thanks.

19:22 This was fun.

19:23 A pretty quick episode, but, Oh, Mike says, hover skateboard uses pointers,

19:31 and seg faults.

19:32 Yeah.

19:34 so, and then we can get like, we can get Devin and, AI to create, seg faults for us.

19:41 Yeah.

19:41 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, and if you're listening and you want to join the fun of talking with us while we're doing a podcast,

20:03 head over to python by set FM and you can see what the schedule is for the next live episode.

20:09 Indeed.

20:10 Thanks, Ryan.


Want to go deeper? Check our projects