Python Bytes - #379 Constable on the debugging case
Episode Date: April 16, 2024Topics covered in this episode: How to Set Up Pre-Commit Hooks A step-by-step guide to installing and configuring pre-commit hooks on your project. difftastic Quarto constable Extras Joke See th...e full show notes for this episode on the website at pythonbytes.fm/379
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 379, recorded April 16th, and I am Brian Ocken.
And I am Michael Kennedy.
This week we are sponsored by us, TalkPython training courses, and also the PyTest course, and our Patreon supporters.
We love everybody that supports us. We really appreciate it.
And if you'd like to connect with us, we're all on Fostadon, on Mastodon.
So it's at mkennedy, at Brian Ocken, and at Python Bytes.
And I wanted to shout out to myself, I guess, and Michael for we're doing a newsletter now.
So if you head over to pythonbytes.fm and join the friends of the show list,
we will send you an email with all of the tidbits. So if you happen to miss an episode,
you can catch up on all the links that we share. So Michael, why don't you kick us off with our
first topic? Let's get started, huh? So I want to talk about an article by Stephanie Mullen.
She put together this really nice article on something that I don't use very much, Git
pre-commit hooks.
Do you use Git pre-commit hooks?
Not, I guess, on some projects.
Yeah.
And I just think there's a lot of possibility for interesting things there.
And, you know, I've considered it, but you don't want stuff that like takes a long time
to run there.
So like how much value do you get?
But nowadays with tools like Ruff and others that run really quickly, it's basically you
wouldn't even really notice it, right?
So it's not a lot of overhead.
So maybe it's time to reconsider, get pre-commit hooks.
And she has a really nice walkthrough here.
So I just kind of want to set out some of the motivation and kind of call attention to this article.
People can come check it out
and set up pre-commit hooks for themselves.
So why do you care about these things?
They give developers near instant feedback of code locally.
So not all, but some of the things
that would run in continuous integration,
like linting checks and other types of checks run.
And when you try to do a git commit, and if for some reason,
there's a problem, right? Like it won't even let you commit, it'll say no, can't commit,
you got to fix the issue detected by the pre commit hook. So it's kind of a gate before stuff
actually gets into broader source control world. And, you know, super valuable if 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 this for myself for my own project or i'm working alone
at a company and i still want to make sure these things happen then throw them in there that's for
you also um the continuous integration side of thing is pretty excellent so here she's using
a project i believe by anthony sotili called pre-commit. And Precommit is a Python project,
but it's not only for Python things
and Git and source control.
It just happens to run on Python.
Like some things run on C, some things run on Rust.
This one runs on Python.
So basically, as long as you can run Python things,
you have an interpreter,
you can use Precommit for whatever projects.
If you're a React native person,
you could use Precommit for it, right? Yeah. So there's a nice example of showing how to set up a bunch of checks
and it's super easy basically you set up pre-commit-config-yaml file or dot yaml and
then you specify different things to run and so you can say i want to run the hooks for check the
format for the toml file check the format for y yamo files make sure that every file ends with a blank line trim out all white trailing white space all those
kind of those are all pretty simple and pretty nice right yes another one is throw in the rough
pre-commit and then i'll just say run rough and run rough format which will fix up the things
and you can even pass arguments
through these pre-commit hooks here,
which is pretty cool.
Yeah, so that's pretty much it.
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 wanna run, all the checkers.
And it'll actually create virtual environments
for those and install them in there. So the first time it's a little bit slow, but then the next time it's plenty quick.
And finally, if for some reason you're like, you know what, I know it keeps complaining,
but this time I just need it to commit because for whatever reason you can use down here,
find it. You can specify get commit dash dash, no verify. And that'll just say it's going in.
I don't care. It's going in
if you need to kind of override it. So yeah, it's pretty straightforward, really nice write up,
and people can check that out if the idea appeals. This is a great timing for this because
I have used it in years past and there's times where I've added like a whole bunch of stuff and
it kind of slows down my process but with the recent
rustification of a lot of um a lot of our tools like with uh rough and stuff um things are pretty
zippy now so i don't think it'll slow down things that much yeah i doubt you'd really even notice it
you know yeah for depending on what kind of when it fails you'll notice yeah and i do like the uh
the shout out there's a couple things i, and I do like the shout out.
There's a couple things I love about this.
I like the shout out to the no verify because there's times where you're just running off to vacation and you have to commit your stuff no matter what.
Get that in there, especially if it's on a developer branch or something.
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 because I want to get it over to my laptop and I'm leaving.
Yeah.
I need it saved.
The other thing is running down some of the rough settings.
So I love some of the configuration that she's included with how to configure rough.
Because rough is awesome by default, but there's some cool configuration you can do like setting um
setting the quote style to single and stuff like that so neat indeed very very neat yeah stephanie's
doing a bunch of cool stuff so people should check out broadly what she's up to but this article is
really nice yeah all right over to you brian uh well i want to talk about something i talked about
two years ago so um i was researching this diphtastic. And I'm like, I'm really loving this
did this tool, I got to cover it. And I apparently covered it two years ago, but I didn't. I haven't
started using it until just recently. So diphtastic is a tool and I, I think it's written in Rust.
I'm not sure actually. But it's a super fast diff tool and it does
coloring, but there's a lot of stuff I love about it. The reasons why I'm using it a lot.
The colors are great, by the way. Awesome, nice red, green, different colors. But what I really
love is that it's a diff tool that's not a line by line, character by character diff, it's, it understands your
syntax, and it only changes things that really change. So if you happen to add a new line in
there or something, it's not going to show you that diff, it's going to do just real changes
to your code, which is super helpful. I hate it when when you have to like turn off, by default,
it doesn't show you that. i i don't like to see
if somebody if i messed up some spacing and somebody fixed that that's not a real diff i
don't need to see that um so having syntax based is great what i really love is what i've um i'm
going to highlight here is there's there's instructions um oh it tells you how to do it and
i can't remember where the link is but but I'm going to show it right here.
In the manual for DiffTastic, it shows you how to set this up for Diff, or for GitDiff.
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, and then you can try it out.
What I really love is the real winner is doing a
log. So showing what you've done on the file recently is great
with the get log. But if you do that with the external diff of
diphtastic, it's a fantastic experience, especially if you've
got a large screen, which I do right now. And it just makes things working with Git so much easier.
So definitely, if you haven't tried DivTastic yet, try it.
And try the – so it shows you how to do it just like one-offs for Git.
But also it shows you how to set up your Git config
so that you can use it all the time.
So this is fantastic.
Yeah, very excellent.
Are you starting to use it?
I'm using it every day now.
It's just part of my workflow.
So yeah.
I see.
Mike out in the audience says,
Difftastic is indeed in Rust.
Yeah, it's one of those super fast.
I love.
I'm going to have to start learning Rust, I guess, maybe.
Or I just love other people writing Rust for me
so that I can write my Python even faster.
It's kind of like when you use Jupyter Notebooks.
You don't have to learn TypeScript and JavaScript
and all those things.
You can just use them.
I appreciate that someone else took one for the team.
Yeah.
Yeah.
So, awesome.
All right.
Actually, speaking exactly of that kind of stuff,
the next thing I wanted to give a shout out to here,
the next topic is Corto. Have you heard of Corto?
I don't believe so.
Yeah. So Corto is pretty cool. It lives solidly in the,
I want to publish stuff for various reasons,
maybe because I want a blog or a website or I want to write an ebook or I just
want to create a webpage that shows my research or
visualizations for my company or something like that. So basically it's an open source scientific
and technical publishing system based on Jupyter notebooks. And a lot of people have been talking
about this and recommending this lately. So I thought I'd give it a look. And so the idea is
you write in Jupyter notebooks
with plain text or Markdown or whatever you want to use. And then you create the dynamic elements
in Python, R, Julia, or observable. Observable has always been an adjective. I didn't know it was a
noun, but okay. Yeah, I may have to check that out later. But basically, most relevant point is you can write your stuff in Python.
And then you can create production quality articles, dashboards, websites, blogs, and even EPUB books.
So HTML, PDF, even Word, EPUB, and so on, which is pretty awesome.
And then it comes out of the Posit folks.
You can connect it to P connect if you want but then you can write in
hand dock markdown as well and get like fancy math equation type things you know like integral from
zero to infinity of that to that and right it looks you know proper like you would see in
calculus class not weird ascii representations to it so yeah it looks it looks pretty awesome
has ability to like show or hide the code.
You go to their website, you can see there's a little example of here's a notebook, and
then here's actually a publication of it, which I think is pretty cool.
What do you think, Brian?
I think this is excellent.
I definitely want to try this out.
I've been itching to write more long form, and doing something like this would be great.
I think it would, especially if you use Python to sort of express what you're working on or what you're doing, right?
Yeah.
It'd be super, super cool.
Yeah, and Pandoc.
It's cool they're using Pandoc Markdown.
I mean, Markdown's amazing, but the Pandoc's flavors of Markdown, there's a bunch of cool extensions.
So it's pretty neat.
Yeah. of cool extensions so that's pretty neat yeah also final thing you compare apparently can embed
things like jupiter widgets html with it widgets and others to let people sort of interact with
the page as well which is also cool yeah neat yeah all right so if this is your world check it out
definitely okay next um i want to talk about uhable. So this is a simple debugging tool.
Looks like it's fairly new. Look at that. Wow. Initial commit four days ago.
If you find yourself aimlessly adding print statements while debugging your code,
this might be for you so this is
actually pretty neat i like it see throw like in the example you throw a decorator at constable.trace
and then you can throw in which variables you want to trace and it just like it shows you some
cool output of like what happens while you're while you're running um and that you can walk through
and it does the changes to your uh which line changed your variable and what did it change it
to and all that sort of stuff and it's kind of each line that changes right it it prints out like
as the variables change at any step it'll say here's what the new values are which is cool
but it kind of describes it which is. It'll say like this equation ran.
So now it's a new, this statement ran.
So here's the value, this statement ran.
So now here's the value.
It's really good.
Yeah, it's fairly verbose,
but and with a lot of spacing in here,
but I think that's good is,
because you're probably going to like throw it
on just a couple of functions
to when you're debugging at the time
and then pull it out later.
Don't put it in production.
I was wondering this too.
So I forgot the name of the other tool that
was kind of like this.
And Mike Fielder says, I wonder how Constable compares
to ice cream.
And I think I would take this as Mike is volunteering
to do a write up of comparing Constable and ice cream.
MIKE HENRY- Definitely. Thanks, Mike. MIKE HENRY- Thanks, Mike. I would take this as Mike is volunteering to do a write-up of comparing Constable and ice cream.
Definitely. Thanks, Mike.
Sounds, thanks, Mike. Yeah. Let us know when that's written up and we'll take a look.
No, I think, I think probably a lot of this is just a probably feel like,
how's it feel to you if it fits your workflow or not? So this, this looks fun.
So yeah, this looks very fun and both are new to me so it's worth checking out
okay and if Mike doesn't want to do it
maybe I'll take a look at comparing constable
excellent you could write it in Cordo
yeah
so
apparently Mike didn't
was surprised at
the volunteering
anyway
so yeah constable for debugging print statements it's easier than print statements volunteering. Anyway.
So, yeah, Constable for debugging print statements.
It's easier than print statements.
Yeah, nice. Cool.
I'm going to work it into my world, I think.
It looks good.
What do you got for us next?
Extra, extra stuff.
I have only one extra thing.
Oh, we're done with our topics already?
I believe so.
Time flies when you're having fun, you know, and your time flies.
All right.
So, at least I'm done.
I've got nothing else.
How's that?
So, two pieces of news here.
They're both the same piece of news.
So, Python 3.12.3 final is out, which comes with 1, 2, 3, 4 security updates.
They don't sound like any sort of big deal so uh wouldn't like run run and patch it now or anything but there are some things
that sit under security so that's always worth thinking about but there's also quite a few
changes under built-in under library i mean just gauging by the scrolling, I would say there's probably 50 or 60 changes.
That's a big change for a.3,.2 to.3.
Yeah.
Yeah.
And why not?
Why not upgrade?
Absolutely.
And just the other piece of news is that Python Bytes and all the other things are already running on 3.12.3.
Just bump a number, kick off the Docker update, and boom.
Sweet.
Yeah, very nice to have that set up in place.
Extras for you?
Just one that I was excited to cover, but then like, okay,
so I'll just talk about it.
It's a couple of, you appear to be offline.
It's a couple weeks old, but pointers are going to be added to the
standard library with pep for what before yeah what uh apparently uh guida says uh you know why
the hell not uh why not add pointers this will endure it this will also introduce uh pointer
literals size of operators and memory errors um actually i was perusing reddit in python and noticed this and i'm like what's
going on and then i noticed the date was 15 days ago that would have been april fools uh april 1st
so rough i actually got off rough snagged on this this is sort of funny though this is funny
it even has the c syntax like ampers, to grab the pointer of a variable,
a star to dereference the pointer.
It's all sorts of stuff.
Yeah, malloc.
Malloc, why not?
Why not?
New size of operator.
The irony is everything in Python is a pointer.
You just can't directly address them, right?
You can't work with them that way.
There's no pass reference,
you know, the ampersand operator in C
where you could change the value of the pointer within somewhere else.
I love this example.
Spam equals star of none.
That will seg fault, core dump.
Good luck, kiddo.
Fine.
This is good.
I enjoyed it.
All right. Comments are like, nice one. I believed it. I believed it. I enjoy it. So yeah, all right. People comments are like nice when I believed
it. I believed it. I believed it for a second except for you know, anyway, but there is
a infamous pointers dot pi. So is that a real thing? You can know, bringing the hell of
pointers to pipe from from pointers import underscore that's funny anyway uh all right so uh this is this is involved
involved this is in depth that wasn't just a reddit post it's got like a whole github
repo yeah example there's like a ton of code here what are they doing
uh this is awesome why does this exist anyway lays out in the audience says i would have believed it
too one of the features is seg faults um always a good time always a good time yeah all right so um
that was funny but do you have anything else funny for us i do and it's very much in the same vein
although i don't think it's the same date. I think it's just more random.
So check this out.
Henik from the Python community, who we speak about often, is here holding this award that
is a Hugo, you know, Hugo, the not the static site generator, but the the awards for.
Sounds like a sci-fi award or something.
Yeah, for best sci-fi, best science fiction.
So here's the thing. Very happy to accept a sci-fi yeah science fiction so here's the the thing
very happy to accept a hugo award for my science fiction short story the day python packaging made
everyone happy good right hannock that is that is excellent nice someday and science fiction is
is a good angle here right because science fiction is the sort
of stuff that's not real now but you can imagine maybe but probably not at some point in the future
like the year 3000 we'll all be fine yeah well i well i don't believe anything until i get my
hover skateboard i know so anyway we're just gonna be all it's gonna be about is
people crashing and falling over backwards on youtube on the hover skateboard once we all get
them what yeah just like the ones with wheels now but now when you hover you it'll even more tippy
still fine i'm trying to figure out how you turn on something that hovers um i know but anyway
all right all right well thanks this was was fun. Pretty quick episode, but...
Oh, Mike says,
Hover Skateboard uses pointers and seg faults.
Yeah.
And then we can get Devin and AI to create seg faults for us.
Yeah, that'd be awesome.
Not my fault.
I didn't take down production.
Devin did.
I wonder if the segue is written in C. I wonder if segues have seg faults. I yeah that'd be awesome not my fault i didn't take down production devin did i wonder if the segue is written in c i wonder if segways have seg faults i bet they do yeah
it would be fitting uh all right well uh thanks everybody for showing up if you want to um uh and
if you're listening and you want to join the fun of talking with us while we're doing a podcast um
head over to pythonbytes.fm and you
can see what the schedule is for the next live episode so indeed thanks man thank you bye