- Podcasts
- Python Bytes
- #426 Committing to Formatted Markdown
About this episodeTopics covered in this episode: mdformat pre-commit-uv PEP 758 and 781 Serie: rich git commit graph in your terminal, like magic Extras…
- mdformat
- pre-commit-uv
- PEP 758 and 781
- Serie: rich git commit graph in your terminal, like magic
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#426 Committing to Formatted Markdown
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 426, recorded March 31st, 2021. I'm Michael Kennedy. Hi, I'm Brian Okken. And this episode is kindly brought to you by Posit Connect Cloud. Last time, Brian told you all about Posit Connect On-Prem, or your own cloud.
Also, YouTube, follow us on YouTube. There's the live link in the top that'll take you there. Please subscribe if you want to be part of the show. That happens. Usually, right now, Mod 7, every week, Monday at 10 a.m. Pacific time. Time zone changes like daylight savings, screw that up a little bit for people.
But anyway, that's when it is. We're going into summer, Brian. I don't know how consistent we're going to be, but we've been pretty good lately, right? Yeah. I think so. But we're people. We've switched if we need to. Exactly. And if you would like an artisanal, handcrafted digest of an email form, we send a bunch of information that's not even in the show notes.
Yeah. And I mentioned that that's cool to format the blocks with the code blocks within Markdown files. But I kind of wanted an auto formatter for Markdown itself. And one of our listeners, Matthias, got a hold of us and said, hey, have you guys checked out? Let's see. Have you checked out MD format?
So MD format. So I did check it out this weekend. MD format is super cool. Actually, I'm kind of in love with it. So it's just like any other order formatter. It's written in Python. I wasn't necessarily needing it to be written in Python, but it's kind of neat that it is. So you can check it out, see how it's implemented and open source.
And there is a warning that says, hey, we're going to we may change this. So if you really like the style that we're using right now, you might want to pin it, which is a good idea. So the style, one of the things that I really wanted was the underlying headings of Markdown with like you can have on this next line of you can write a heading.
then on the next line you can write like three equal signs or or or more um or three dashes and that means a heading or a subheading and i don't ever use that i use the pound uh yeah for animals use the three underscore well i used to okay please don't write me i'm joking no i often use the three lines for like the horizontal line i do too yeah i do too thank you anyway so um the so it switches it to the heading style I like. Bulleted lists, which are kind of cool. They alternate between dashes and, and asterisks because both of those work. But so like, if you have embedded lists, it'll alternate. So it looks nice. But I mean, the output is all the same anyway, but it makes it look nice. And then there's standardization for ordered lists. However, this one tricked me up i'm like i get it so what they do with order lists if if you have like one two and three um it converts them all to one uh and that seems weird and there's a reason
around it there's a reason is because it reduces the number of get of uh get diffs or you know when you when you change a version if you move things around the only thing that'll diff is the thing that you added or the thing you deleted not all the numbering changes how that's nice however it's something I like to be able it's less readable just right off the bat so there is a flag you can pass it pass it --number and it doesn't do that it just numbers them consecutively which actually also kind of nice because if you move things around instead of having to go through and retype all those numbers you can just do the empty format with number so why would he put it 1, 4, 7, 2, 3, 5 yeah well I mean you've done that I'm sure like you're moving things around and now they're wrong.
So I'm excited about that. If I was writing in plain and a completely unassisted text editor, I might write just 1.1.1. And so you have the ability to reorder it. However, if you're using any sort of tools that understand markdown, when you hit enter, it will increment that like Typora and IA writers and others.
Right. So it's going to number it automatically for you. And if you want to reorder it, then it's broken. And so this is really nice. I like it. Yeah. And then you could, of course, since it's a command line tool, there's probably a hook already written for a commit, like a pre-commit hook, but you could write your own easily or just use it or use it, put it in CI.
So, so I like, this is already enough and, and I'm, I'm going to use it right away just for this, but it doesn't stop there. You can also mark down, you can convert your code. So it will handle auto-formatting your code blocks also. And for that, it has a plugin system because it doesn't know how you want it formatted.
So there's a plugin for black and one for rough and a bunch of others that you can. So there's a web one. So you can like format your JavaScript or CSS or HTML within your. So this is pretty cool that you can have all these different plugins to convert your code blocks also. Anyway, I'm kind of in love with this.
Yeah, definitely. But see the inject. That inject, pipx inject, MD format, MD format dash GFM, I'm guessing GitHub Markdown format. What does inject do? Yes, I'm like, what is that? And so while we were talking, I did a little research. And what it does is it will add additional packages, but to the same virtual environment, the dedicated virtual environment that pipx creates for the tool.
So pipx will create a tool for MD format and then also install these other things. things now i was we talked we talked uv up so much and we're going to come back to it somewhat as well um but as far as i can tell it doesn't have such a feature you've got to create a virtual environment and then install it yeah you might be able to do a run --with and make a really long complicated thing but there's no clean so how about that pipx for the win a little bit which is not usually what we're saying i like pipx but that's not normally what we say yeah no cool All right.
So pre-commit is a project by Anthony Satili. and the idea is it's like a multi-language runner happens to be written in Python but it's not about Python per se that will run pre-commit hooks. So instead of saying, well, you want to use a pre-commit hook written in Rust, you've got to install and manage Rust and all that.
You just kind of like do it its way. You just pre-commit it, right? Yeah. So that uses pip and it has all the bonuses but also the drawbacks of using pip. So you can pipx install pre-commit and then here we are again pipx inject pre-commit dash uv and so then when you when it does it its thing to install and set up a new machine with the pre-commit hooks or updated or whatever it's going to use uv and they did a oh go back up a look for a second there's the uv version uh uv tool install pre-commit with so that's like the inject yeah i think that that would i think that would do it I think that's the way that you could probably pull that off.
But I think, you know, maybe that will do it. I thought you could only do that with run, but if you can do with in the install, then, you know, there you go. That's the uv way. Awesome. Okay, so we're learning stuff, but they're running a timed example of run one thing, and then the other says try pre-commit install hooks.
I don't know what the hooks were, but some set of hooks. install them with raw pre-commit and then pre-commit uv install hooks. And the difference here is with regular pre-commit, it took 54 seconds plus or minus eight around. With pre-commit uv, it took 41. However, that's the first time you do that on a machine that involves those dependencies, right? If you hit it again, like if pre-commit uv has to build something from source, it's going to be super cached again, right?
Yeah. So I think, though it does say 10 runs, interesting. But I think it's doing it with like an isolated environment or something like that. Anyway, if you're already using uv and you use pre-commit hooks, check it out. There's some configuration options you can pass with environment variables and so on.
So let me tell everyone about Posit and Posit Connect Cloud. So this episode is brought to you by the folks over at Posit. They're originally known for building RStudio and Shiny, and they've created a bunch of tools for the Python community. For example, Shiny for Python. I had Joe Chung on to talk about that and a whole bunch of infrastructure things for Team Python.
That's it, and it's off and running, and it'll clone your code repo, build your asset, and host it on an online URL that you can share. And best of all, it will update your app continuous delivery style. So if you push new stuff to the branch that you've told it to publish, it'll just go, ah, there's a new version of your data science thing.
And if you need fast, lightweight way to share your data science content, try Posit Connect Cloud. And as Brian told you last week, if you need these features, but you need them private, then you can try the on-prem version, Posit Connect. So if you work on a data science team where moving fast matters, you owe it to yourself and your organization to check out Posit Connect Cloud. Visit pythonbytes.fm/connect-cloud. See if it's a good fit. It's pythonbytes.fm/connect-cloud. The link is in your podcast player's show notes right at the top.
Thank you, Deposit, for supporting Python Bytes. Yes, very much. Thank you. So now I'd like to talk about a couple of PEPs. So these are pretty quick topics, but there's some changes to the PEPs. So PEP 5.7. No, I got that wrong. PEP 7.5.8 is allow, accept, and accept star expressions without parentheses.
This was accepted as of, looks like the 14th of March. and so looking through here um and i kind of uh i guess i just like i don't really think about it too much but if you if you have a try accept block and the accept can accept a lot like you shouldn't have just accept with nothing you should have accept with which types of exceptions that's right you should put pass it there try accept pass is the best way try some no i'm just kidding try pass, try, just skip the accept. anyway, so the, if normally right now, if you have several exceptions that are allowed, you put them in parentheses. Now this is just a small little language change that says you don't actually have to put the parentheses there or you won't in the future. And, I'm all for this. This is, this looks great. it seems like and slam dunk. And I'm sure that's why I got it. One of the reasons why it got accepted is that just in the future in Python 3.14 and beyond, you won't need the parentheses. That's
really it. Kind of nice. So, however, you know, so like four years from now, we can start using this if, because you'll, you know, once you stop supporting all other Pythons below 3.0, you know, for package so for package maintainers this is um this is future news for normal humans this is news for this year so anyway yes um the another PEP that is not accepted yet it's in draft form in i just want to highlight it because i think it's a good idea is PEP 781 make type check it type make type checking a built-in constant uh and this um that the idea around this is i'm I'm noticing as I'm using typing more is that occasionally I need to, like, if you're going to import something, like if I only import something just so that I can import the type, so that I can put the type of something, you know, the type of a class or a type of a return value or whatever in a function, import or a functions, you know, statement or whatever, a variable type,
I don't really need the type, the import for running. I just need it for type checking because that's to get the type so there's there's that but it does cause some uh the m but if you do that the import like um you know is running all the time anyway so but you always have to to say like you know from typing import type checking what to tell whether you're type checking or not it's just basically just saying that we that we won't have to do this anymore so instead of uh Oh, where's the actual spec?
Love it. I think we should have it. It'll be good. Oh, while I was here though, another thing I want to highlight is I was like looking around. I'm like, well, what else is there? And there's an index by category here at peps.python.org. And it's really kind of great. This is a really well put together web page about how to navigate peps.
Because there's a lot of peps, right? So I was like, well, I'm currently looking for ones that have been accepted. So you can pop down and say accepted peps. And then you can look at what the version number, what version they're coming in or which they came in and stuff. So really nicely done, easy to navigate website.
So good job. That is very nice. Anyway, so that's it for that. I wonder if that's available in a structured data way. Is there like a JSON that represents some data or something? There is an API. I don't know if it applies to that. I'm sure somebody will tell us. Yeah. Nine point ChatGPT at that table and have it do it.
Yeah, JSON metadata. Yes, indeed. All right. On my final item, Siri. Not, sorry. Anybody's phone who started? That's, I just pronounced the same. S-E-R-I-E. I guess that would be the same. So this is for people who are more terminal-like but need a better Git experience. So it's a rich Git commit graph in your terminal.
So there's a little picture here. Open the image and look at it bigger, I suppose. But basically, it gives you the entire branch tree and something that you can navigate around and interact with kind of like rich and lets you do things like search all branches over the commit log and browse through tags and all kinds of stuff.
What do you think, Brian? I love this. I mean, can you try it right away? Yes, I know. This is so cool. It looks really cool. I totally want to say it like, okay, that's cool. Now it's written in Rust, so it's not a Python thing. It is a tool for Python people. Although I feel like we have a certain kinship with Rust people.
Cross them fingers. Remember to try it in Windows Terminal. Don't do it in cmd.exe. Don't push your luck. You just ask for it. Windows Terminal? Yeah, it's like the much nicer. PowerShell? PowerShell is the thing that the shell that runs, but Windows Terminal is the app that hosts it and it has much better compatibility.
Like for example, Rich works a lot better in Windows Terminal than it does in CMD and so on. Get it from the Microsoft App Store. How am I only learning about this now? It's really nice. And you can do like dropdowns. Say run this tab in PowerShell, run this one and get back, run this one and I don't know what you call DOS, whatever that is.
I'll report back because I've spent my entire career pretending that I don't use a Windows machine at work. But yeah, anyway. Yeah, you could even, I think, open a particular tab as a Windows subsystem for Linux and Vutu type deal. So pretty cool. Nice. Okay. Tangent. Extras. We're on to our extras if you have extras.
I have no extras today. Well, you're lucky that I do. Oh, and before we jump on, Will, who I just released a Talk Python episode about high-performance algorithms, algorithms for high-performance terminal apps, and we talked a lot about this, says Windows Terminal will be the default in future Windows releases, good times for terminal users, and, in the case of Will, terminal framework builders, TUI builders.
And Brian, I used to use search so much. I've talked about Kagi and how much I love Kagi and all those things, right, a couple years ago. And I was probably doing a couple thousand searches per month in there. Yeah. I looked last month across my three computers that I use and my multiple browsers on each one and my phone and my iPad.
did 211 searches. How about that? He probably did more, but okay. Kagi keeps track like in your account because they charge you by it. Oh, okay. So I went and looked at my Kagi stats and I said, you did 211. Why is it going down? Because I'm using AI to answer so many of these questions these days. And so many with the pro ChatGPT and stuff, it's just like I could open up a bunch of tabs and do a research project myself or I could, hey, go do some deep research on this and come back to me with references to where you found the answers and summarize it. And anyway, I think it's, I just thought it was really wild. And so I am switching over to something called start page. Have you heard of start page? Yeah, I've been using it for the last couple of months. I love it. Do you like it? Yeah, it doesn't have, I'm going to sound like a, like an old guy or something. I like that. It just gives me search results and doesn't give me AI
It's basically private, like privacy preserving doesn't pass your information on along to, to Google, but it's basically the Google index. There's someplace to say, don't show the ad, Is it Appearance General? I don't know. Somewhere here. So don't show all the marketing goo. But if you go and search there, it will sort of disintermediate your Google searches, I guess.
And it lets you, it has like little visits privately, right? You know, you can say, if you do some kind of search, like, how do I get out of here? Let's go back here. If I search for like Python podcast or something, it'll let you run it in like a little VM iframe that like doesn't even let it know where you came from.
See, I'm running it with ads, and it's just not annoying to me. I'm like, I'm okay with that. Yeah, that's good. Because they're not tracking it. They're not tracking stuff. Yeah, I mostly hate the tracking and the retargeting and all that. Yeah. So, yeah. Oh, good. One of the curious things I've got about this is I wonder, so I know that Google, sort of a tangent, but I know that Google like worsened their search like recent, I don't know, several years ago so that people would have to go through more pages so they see more ads.
Yes, it's terrible. I wonder if that's the case with the, did they do that mucking about in the index so that start pages using the mucked up index or? Probably, but it doesn't have as much. of that not immediate, like not so much of the answers. So if you did a search on straight Google, you get, and here's a whole bunch of videos and here's a bunch of like Q&A stuff we found and like that's half of it and then you got the ads of which are a third of it then like way down the bottom somewhere you get a little bit of something to start and I don't see any of that stuff there.
I'm not sure. I feel like I've seen it, but anyway, since I'm not using search so much, I thought, well, let me search around and see what else I can find. And yeah, start page. It's interesting that you're using that as well. Yeah. Yes, I think it just got turned on by me. I didn't think I found it.
I think Vivaldi turned it on or something, but I don't know. Interesting. Okay. Yeah, I'm a fan. All right. Cool. Yeah, cool. One final extra. Rhett Turnbull, who's been on Talk Python to talk about building Mac apps with Python, sent us, so he knows something about building some frameworks and stuff. He says, remember, I said, Brian, you can just uv toolinstall ruff and then you just have rough and don't have to put it into your requirements file or your uv lock or wherever those things go. He says, good advice.
However, you might want to actually put it in your virtual environment. That way it becomes part of your pinned dependencies so that people who are contributing to your project use the same version of rough if they don't already have that exact version and you don't get like flip-flop of get changes because something changed about rough itself or the rules defaults or something yeah yeah i totally agree and that's one of the fun things that we have in talking about python tools and everything for everybody is that the advice for solo developers is different than the advice of people that work on teams um so yeah yeah teams even being open source teams yeah exactly Exactly. All right. Shall we make a joke? Sure. Let's see how I did today. This one, I thought of you, Brian, when I wrote this, because I thought this is all about the C developers or even the C# or C++. I'm sure there's some many other languages that have this, but C in
particular came to mind. This has to do with a genie and this software developer-like person comes along and stumbles upon the golden genie shaped little vase or whatever the heck it is and rubs it as you do, out comes the genie. He says, I will grant you three wishes. Okay. But before you can, the genie interrupts. The rules are you can't wish for death or life or make people fall in love. And you can't wish for more wishes. That's the, that's usually the escape hatch. You Can't wish for more.
Yeah, I think you're right. It has a bug because the cartoon has zero and zero should be valid for any numbering system. It should, but minus one. And then if you go to the thread a little bit further down in here, there's a lot of pretty good comments. Almost no one caught that it needs to be negative.
Like underflow, zero doesn't underflow people. But someone pointed out, the hat pointed out, you need to upgrade the 64-bit genie. There's some kind of like animated, crazier, crazy game with like lightning striking it. That's the 64-bit version. That's funny. It would just give you even more wishes if you underflowed that though.
Why would somebody do that? But I guess it comes from a time when you've got more time on your hands and. Well, no, yeah. Well, it's also like it's an oil lamp. They look different. And also it was probably brass. And now that I'm an antique dealer, we, yeah, we, yeah. Yeah, you got to polish it or something, right?
As a C person, you have to approve, except for the bug. Except for the bug. Except for the bug. They didn't test it. No, they certainly did not test it. We'll come back to that next week somehow, I'm sure. Yeah. All right. Well, thank you, Brian. Thank you. Thank you, everyone, for listening, and see you all later.
