Python Bytes - #352 Helicopter Time Comes to Python
Episode Date: September 12, 2023Topics covered in this episode: Heliclockter - Like datetime, but more timezone-aware Wagtail 5 Git log customization MiniJinja template engine Extras Joke See the full show notes for this episo...de on the website at pythonbytes.fm/352
Transcript
Discussion (0)
Hello and welcome to Python Bytes where we deliver Python news and headlines directly to earbuds.
This is episode 352 recorded September 12th, 2023. I'm Michael Kennedy.
And I'm Brian Ocken.
And this episode is sponsored by us, supported by us, support the podcast by choosing our courses,
listening to our podcasts, including the new one by Brian Python
people and the Patreon supporters and find us on foster.org Brian, me and the
show links in the show notes and also the show notes have how to attend the
live session if you want.
Yes.
Brian, what do you got to start our day here?
I, I feel like it's the start of school.
So I think, uh, I feel like a helicopter parent.
Yeah, that's right.
You got your homework done.
Was anyone mean to you?
Can I help you out, sweetie?
So the first topic is called Heliclockter.
And it is apparently a pun on helicopter parenting, maybe?
I don't know.
So like helicopter, but clock, get it it kind of a heliclock um so this was
submitted by peter nielsen i think he was involved in this but uh the idea is um is it's like it's
like date times but they're a little bit better so apparently one of the frustrations that this
group had was um with date normal date times And they looked into other things is having,
being able to just have a date time where you can just enter like the time,
but have it be like aware of what time zone it's in.
So it's the,
the big thing about this is,
is a subclass of date time with with some extra features.
So you've got a date time TZ,
which is a time zone aware date time. And then you've got a datetime TZ, which is a time zone aware datetime.
And then you've got a local one,
which ensures that the time zone is local time,
and then a UTC.
So there are some other solutions out there
that deal with just assume UTC plus zero,
but that's often not convenient.
And I guess one of the things they had
was they wanted
to be able to have daytime items as objects and then be able to sort them but have them keep like
maintain what time zone they were created in and stuff um which is kind of an interesting thing
so they they've got um uh it looks just like working with time zones so it looks pretty
pretty easy to work with if you've ever worked with time zones they do have some other cool features like um uh statically type
checkable and uh pydantic integration which is kind of neat um uh anyway the they've got a also
an article about um why they created it um time flies when you're having zones nice um so uh it's
a pretty interesting discussion going through why
they why they chose the solution they did of creating their own and uh and everything and
being able being able to use it with my pi also is kind of cool so yeah yeah neat time so shout
out to arrow and pendulum as well or some of the other well-known ones yeah yeah um even a daytime
utc they found but it it it's UTC zero.
And then they even talked about why that like how they designed it and why.
So they their first thing was just create a completely new type.
But but then they, you know, came up with some problems with that.
So they came up with subclassing.
So then they're there. These new types are types of daytime also.
So you can use other things to go with them.
So I think that's a cool solution.
I'm not usually a fan of subclassing,
but I think the subclassing in this case makes a lot of sense.
Anyway, what you got for us?
Yeah, that looks good.
I think it sounds so easy to be working with time,
but it's always so tricky.
I have something, keeping with the same color scheme here, a
new release for wagtail. And I don't believe we've talked about wagtail before. It's possible.
I I did get a chance to use our search today, you know, and just reminded how nicely that
goes. I guess we talked to at least mention it somewhere. But wagtail is a CNS, the CMS, the leading open source Python CMS
built on Django. But you don't necessarily have to know Django, it's kind of like WordPress,
in the sense that you could just go through the setup steps and run WordPress and not even worry
about the fact it's written in PHP. So wagtail is a little bit like that, but just pip install
wagtail to go get going. And it's
got some really cool features. I haven't really explored it too much. But it's got this really
cool visual designer for people to build out web pages and stuff. Isn't that cool? So you can like
hit a little plus, you get like a nice WYSIWYG, I'm going to insert a heading or insert a table or
like a image gallery with these images has a cool tree structure so you can
organize your content and because it's a Django you can extend it doing Django things which is
pretty sweet and has a bunch of you can make little snippets that you can use inside your pages
so that's pretty neat and it even has a library for managing your images. So pretty cool stuff. And the news item today is an article by Megan
Voss. Come over to the dark side with Wagtail 5. So Wagtail 5.0 is a new release here with a bunch
of cool things. So dark mode, if you want your website, which is backed by Wagtail to have dark
mode, well, dark mode is a thing. It's pretty excellent. I'm a big fan of dark mode.
It has SVG image support in addition and scalable vector graphics in addition to just JPEGs and
stuff. It has an accessibility and enhanced accessibility checker. That's pretty cool.
Like if you're creating content, and it's hard for people who have to use screen readers or
something, it can tell you that you're not doing that. Like, uh, missing paragraphs is heading. I miss using paragraphs as headings, use proper tags, incorrect heading
hierarchy, avoid skipping levels.
Oh, wow.
And you know, things like that.
Right.
Which is certainly my, my handwritten stuff.
That's only, you know, if I remember that that's how it's supposed to go.
Right.
So pretty sweet.
What's wrong with five H ones on one page?
No, I know.
I really, I really have a lot to say here, so it's all H1s.
It also has
what is the
when you, if you want to delete, like say you have
an image or something, it's in your
gallery and you're like, ah, not going to use this after
I'll hit delete. It keeps track of
if it's used in any other pages, so you don't
accidentally delete something
that's being used in some part of the site you didn't know
about that someone else created. That's pretty awesome. More snippets, more validation, and they threw
away a bunch of old code so they can work better, which, you know, may even have a blog post on
addressing technical debt. But so a few breaking changes, not too many, but yeah, check it out.
Anyway, Wagtail looks pretty awesome, right? I think I may have talked about it a long time ago,
but anyway, not the 5.0 release because that's quite recent yeah i think it's um it's pretty cool
that that's there and i do have plans to play with it at some point but i've had plans to play with
it for a while so anyway indeed uh kim out in the audience says i know several one-person technical
businesses that really like wagtail for their sites. Easy to use for technical competent users,
but doesn't require much of their time to maintain.
Yeah, that seems great.
Yeah, nice.
Over to you.
Well, I guess I go away from Python a little bit,
but we use it all the time.
So I want to talk about Git.
So I don't think I use any other revision control systems
anymore other than Git.
No CVS?
No.
No WinCVS, any of that good stuff?
Perforce?
Subversion.
Actually, I touch on Subversion once in a while.
I still have kind of good feelings towards Subversion.
The other ones make me a little queasy.
Anyway, the thing that I often wanna know
is just like the stuff that happened recently on a file or something or just on a Git repository.
RCS, Mike Felder.
Oh, Field Fiedler.
Sorry.
Nice.
RCS.
Wow.
Takes me back.
But so one of the things is the Git log.
So looking at what's happened recently.
But the Git log output is not something I like to do.
Actually, using Git log is one of the reasons
why I often pop up like a visual tool
to look at my Git repository because it's gross.
But I forgot, and I knew that you could customize it,
but I kind of forgot how to, so I haven't been.
But this, now I have because of this article.
So there's an article called Get Log Customization from Justin Joyce.
And so the default is something like that, which we're showing.
It's got a really long hash number and a bunch of information, but it's hard to find the information you need. One of the things that Justin points out
is that you can do just something really easy
by passing in one line.
Just the flag, the two dashes and one line, all one word,
will make it pretty nice, actually.
It just does a short hash,
and you can kind of see what's going on a little bit better.
But it goes a lot further.
And I'm going to hop down to this really cool customization.
One of the things is using graph.
Graph is great.
Dash dash graph so that you can see kind of it does like kind of a visual representation of the different.
What are those?
The branches and the merges.
That's it.
I always forget branches and branch or fork. And's an ascii art for the win there yeah uh ascii art but then you can do
like color and stuff so um there's there's in it the graph does color also if you have that on your
on everything but it talks about how um it also talks about how the one line is actually a, like a combination of pretty
one line and abbreviate commit, which is kind of cool. And then goes, what I really love is this
the thing that he like comes up with at the end, so that I didn't know that you could put aliases
in the get config file. So or at least I did once and I forgot about it, but this is a pretty cool long
alias. He's got LG instead of log. Uh, so save a character of typing right there. Uh, but it,
it defaults to, so it's a alias for log with a graph with 10. So default to the last 10 commits.
And then this long format thing that is kind of ugly to look at. But what you get is he talks about what it all is.
But what you get is the brand, the graph.
But you also get somebody's name highlighted of who did it.
And then also how long ago.
So was it 19 hours ago or 24 hours ago or two days, three days?
Really cool.
Exactly what I need usually when I'm looking at a
Git log. So I love it. This actually inspires me to maybe play with this as well. And I usually
use source tree. I really like source tree, but you know, sometimes you're already in the terminal
and just, you know. Yeah. And so all I did, what I did is I just like opened up my home directory,
Git config and added this alias and now i just use git
lg that's um and then i can forget all of this the other one of the neat things i'm like well
if it says by default you can put the default whatever you want for this alias but like 10
lines what if i want to see like 20 lines or 30 lines well if you say get lg even though it has
the dash 10 built into it and pass in a, like a dash 20 or dash 30,
the second one overrides it. Um, so that's clever. It works just fine. So nice. So, so thank you,
Justin Joyce for writing this up. Nice job, Justin. That's pretty awesome. All right. I saw
that David Lord was the one listed there in the example. Yeah. Let's keep, let's keep
going with that theme. Okay. So over to historically from the flask side of things. So you want
to talk about flask. I want to talk about Jinja. So Jinja is the templating language
that is the default for so many frameworks. It's not best. I don't think. Come on, Chameleon, so much better. But it doesn't
matter. If everyone's using Jinja, like that's what people are using, right? It's built into
all the frameworks, you got to jump through hoops to like use Chameleon with, say, FastAPI,
right? Like I created a library to do that kind of stuff. But this is about Jinja. And its origins
come from Flask, originally created by Armin Roeniger, no longer the maintainer, David Lord and folks over at Palettes is.
But this new project I want to give a shout out to does come from Armin and it's called Mini Jinja.
Like Jinja, but smaller.
So Mini Jinja is a powerful but minimal dependency template engine for rust that's compatible with Jinja
and Jinja too. So if you've got a rust project, and you want to have those templates, you could
use this and you'd be like, okay, Michael, well, Python podcast. So yeah, rust is popular, but
it's comparable. If you got a Python app, it's basically not 100% identical, but pretty
similar, right? The other thing, though, that's kind of interesting
is it does works with Python through as project called mini Jinja dash pi. And that allows you
use the rust runtime backed template engine on whatever thing it is that you're working with,
right flask, fast API, whatever, right. So you might want to use this
instead, when the full set of Jinja two features is not required. And you want to have the same
experience across Python or Rust. There's places where you can get a slightly better performance
sometimes than Jinja. It was created using maturing and pi 03, which is pretty cool,
like the the Rust Python bindings.
And yeah, it just shows you how to set up and whatnot.
So if you're out there doing the web things, maybe have a quick look at mini-jinja if somehow
that's relevant to you.
Continuing the rustification of Python.
Indeed.
You know it's been around for a long time, over 30 years, so surely some rust is starting
to develop.
I wouldn't have expected to come on so quickly all at once like that, but there you go.
Yeah.
Nice.
Um, that's it for all of our items, I would say.
Okay.
And, uh, I've got some extras, but I know you do too.
So maybe you go first.
Okay.
Well, I was, uh, up, we were just talking at the beginning of this, uh, uh, before we went on air that I was having some audio trouble last night, but I was getting the PyTest primary power course ready and launched last night.
So chapter six got done recording that yesterday morning and in the evening finished editing the audio.
So the first course in a series, PyTest primary power.
And so what does it cover? It covers test functions, fixtures, built-in fixtures, parameterization, markers.
And it's really the set of things I think that you have to know to be able to be using
PyTest effectively.
You could just take this first course and I think run with it for quite a long time.
So to celebrate getting it done and back to school, I know everybody's with kids.
Their kids are probably started last week or the week before. getting it done and back to school I know everybody's with kids their kids
are probably started last week or the week before it might sound like it's for
school but now the kids are out of the house you actually have time and energy
to study things like that's my house anyway yeah yeah so I'm offering a deal
for it so 49 bucks for the the first course and if you want to do the bundle
$99 and the bundle's kind of fun
because i've already had some we've got a lot of channels to get feedback i had some feedback this
last night and this morning saying hey i'm trying this on python 3.8 and it's um uh it doesn't work
so but it does now so this morning i um uh did the it was like the from future import annotations I had to do to, to make the annotations
from 3.10 be compatible to Python bat way back to Python 3.7. So I tested it on three seven this
morning, so everything should be working. So anyway, pretty excited about that.
Excellent. Yeah. Congratulations. That's a big step.
If you see something like this, you're in the right place. So thanks.
How about you?
The testing code logo and roll
the course for 49 bucks. Awesome.
Keeping with the course theme a little
bit, I have three
new courses coming out at Talk By
Thon Training. We have a new
HTMX plus Django
course, which is going to be excellent.
A new language-based course
without more detail on that and
one or two data science courses coming in quite soon.
And since it's a bunch of, bunch of things, all of them, not quite,
released yet.
I just point people at TalkBython training.talkbython.fm slash get notified.
And there, if you're not already in the mailing list, put your name and email in
here and you'll get to hear about them when,
or keep us in the podcast.
I'm sure I'll talk about it then as well.
I also just want to give a shout out to CloudFlare Turnstile.
I've been going through and classifying trucks, cars, crosswalks, stoplights.
Holy moly.
What a dreadful, unnecessary thing. So way back in three or four on October 2022, I talked about turnstile,
which is a privacy friendly, a user friendly privacy, versing and preserving alternative to
reCAPTCHA and all those things. And it just sits down here. And while we're waiting, you know how
like sometimes if you are slow filling out a form, it'll say your selection of taxis has expired and you got to do it again.
This one automatically, I saw it while I was waiting for you to talk about your new course and bundle.
That thing just did a little flicker and regenerated its validation with no user input just in the background.
So how does it know you're not a robot you know it runs
some javascript and it also i think uh you know i don't remember all the details it runs through a
bunch of other heuristics that like they know from i think from your ip address talking to
because you know cloudflare like fronts something like 25 of the internet so they can tell if you're
going to a bunch of different sites and things, and it kind of uses that background information.
I think,
I think,
but anyway,
I have not even had to find a taxi to be able to submit that.
But it's a,
it's made it so that you don't have a bunch of automated stuff coming in.
Exactly.
People used to be hammering on it,
doing all sorts of bad stuff.
Yeah.
That's not good.
Yep.
So,
uh, yeah, I'd add it for like the login page.
Um, and for the, the registration page, a bunch of bots were signing up.
I'm like, I don't understand why they're signing up because it's a free account
and you don't really get anything for free.
So I couldn't understand why they're all, but hundreds of them were signing up.
I'm like, okay, I gotta do something.
And then, uh, this is a, an improvement over recaptcha.
All right.
Pi Bay. Pi Bay is coming up October 8th. I will be there speaking about Python type
hints and how you can super power your apps. Something like five amazing ways and tools you
can use with your apps, I believe is what my topic is roughly supposed to be, but I will be there.
And, uh, people can, they happen to be in the San Francisco area or supposed to be, but I will be there and people can, they happen
to be in the San Francisco area or wanting to be there.
They can check it out.
They gave me a coupon.
It's a friend of speaker.
If you use that friend of speaker, no spaces, you get 20% off regular tickets.
So that's always fun.
Nice.
Yeah.
Always a fun trip or road trip down to San Francisco.
And let's see, following up on your doc strings,
we got some really nice follow up here, Brian, ret turnball says, with regard to the doc strings
article Brian covered last episode, the Google format allows for a raises section. Remember,
I said, Oh, it'd be awesome if you could say actually what errors could happen. Yeah,
that's really cool. And Rhett uses Google Doc string format for projects, type hints, descriptive variable names, MP docs and MK doc strings, get pretty
doctor free and VS code will pull doc strings so you can see them in the editor and copilot
practically writes a doc streams for you, which is excellent. And once I get an attribution,
john Hagen sent over something saying pretty similar, say, remember, we said, look, you
don't necessarily need to include the type in the doc string, if there's a type int. And sure enough,
you don't have to, oh, cool, you can just give it a description, which is cool. And also points out
the syntax for how you use the raises. So you say raises, and you give it a list of exception types,
and then the description of when the scenarios when that might happen so for example raises invalid factorial error if n is less than zero is the time
that that happens oh cool in that goal yeah yeah and finally John also points
out that I charm has the integration for a Google doc strings somewhere in here
yeah for Google Doc format and how to set that up.
So it'll, it'll automatically auto complete and render Google doc strings.
When you say, give me the quick help control Q and it'll like, just pop that
up as a rendered sort of thing there.
So a lot of followup on the doc strings.
Awesome.
Cool.
Yeah.
And that's all I got for my extras.
How about a joke?
What do you think?
Yeah.
Ready?
I've got your joke.
And then I want to do a dad joke also after that.
Awesome.
So this one is a lesson in optimization.
Careful what you measure, careful what you ask for, right?
So there's this picture of two tennis ball containers.
You know, those tubes that are vacuum sealed.
Yeah.
One of them is not at all optimized.
It stores only three tennis balls balls but the one to the right
says look if you cut the tennis balls in half you can you can store six tennis balls in this
container way more efficient use yeah yeah i mean your tennis game might suck but that's awesome
yeah yeah so there you have it yeah okay So over to you to close it out.
I've got a joke that I just was reminded of the other day with
added shared with my kid.
It's told dad joke.
So have you seen birds fly in a V formation before?
Sure.
Have you ever noticed that sometimes that one side is a lot longer than the other
or it's longer than the other?
Yeah. Do you know why that is?
There's more birds optimize the
amazing anyway uh it's terrible i love it i love it so perfect dad joke all right well perfect episode as well thanks for being here thank you thanks everyone for listening yeah see y'all later