Latest / Talk Python To Me / #408: Hatch: A Modern Python Workflow
Transcript
- 0:00In recent years, there's been a lot of experimenting with how we work with dependencies and external libraries for our Python code.
- 0:06There's pip, pip-tools, poetry, PDM, pyenv, pipenv, Hatch, and other workflows.
- 0:13We dove into this deeply back on episode 406, reimagining Python's packaging workflow with a panel.
- 0:22And this time, we're back with Ofek Lev to take a deeper look at Hatch.
- 0:26This is Talk Python To Me, episode 408, recorded March 1st, 2023.
- 0:32Welcome to Talk Python To Me, a weekly podcast on Python.
- 0:49This is your host, Michael Kennedy.
- 0:50Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython.
- 0:56Both on fosstodon.org.
- 0:58Be careful with impersonating accounts on other instances.
- 1:01There are many.
- 1:01Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:07We've started streaming most of our episodes live on YouTube.
- 1:11Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:19This episode is sponsored by Microsoft for Startups Founders Hub.
- 1:23Check them out at talkpython.fm/foundershub to get early support for your startup.
- 1:29And it's brought to you by Sentry.
- 1:31Don't let those errors go unnoticed.
- 1:33Use Sentry.
- 1:34Get started at talkpython.fm/sentry.
- 1:37OFEC, welcome to Talk Python To Me.
- 1:40Thank you.
- 1:41Good to be here.
- 1:41It's been a long time, at least a week since you've been on the show.
- 1:44Yep, just about a week.
- 1:47Welcome back.
- 1:48In that appearance, it was a big panel of many of us talking about Python packaging.
- 1:53Yeah.
- 1:54And you're the author of Hatch and Hatchling and a really interesting take on that tooling story.
- 2:01So I thought it'd be fun to go ahead and just dive into that in particular for this episode and get your thoughts on it.
- 2:07So I'm looking forward to talking about Hatch.
- 2:09Yeah, sounds fun.
- 2:10Yeah, it will be fun.
- 2:11Before we get into it, though, a lot of people maybe don't know you out there.
- 2:14What's your background?
- 2:15How did you get into programming in Python?
- 2:17Those sorts of things.
- 2:18Let us know.
- 2:19I guess originally, this was like maybe 15 years ago now, I was just automating stuff that I was doing every day.
- 2:27So for me personally, I have a condition that makes me kind of weak.
- 2:31So all I can use is like a mouse.
- 2:33Therefore, I type pretty slow.
- 2:35So I was automating like sentences, templating for like sending emails, basically like the traditional developer mindset.
- 2:45If you do anything more than once or twice, just write a script for it.
- 2:49So I had like dozens or maybe even a hundred scripts just to automate like boring stuff.
- 2:55Kind of like the book, which I've never read the book.
- 2:58Automate the boring stuff, but I imagine it's what I was doing.
- 3:01That's how I originally got into Python.
- 3:03Excellent.
- 3:03You were doing the traditional developer thing.
- 3:06Why spend 20 minutes doing something where you can spend two weeks automating it?
- 3:10Yeah.
- 3:10Just kidding.
- 3:11I mean, like, I honestly, I really think that that's a huge value.
- 3:15There's so many people out there, probably many people even listen to this podcast where they don't consider themselves developers,
- 3:23but there's like little things that could be automated that are super annoying.
- 3:28You don't look forward to it.
- 3:31Just a little bit of programming skill will let you really blaze through those things.
- 3:36Plus it also gets you further into Python where, you know, maybe one day you're releasing tools to manage everyone else's Python projects.
- 3:43Yeah, for sure.
- 3:44You don't know where it's going to go, right?
- 3:46Yeah.
- 3:46Now I work at Datadog working on agent integrations.
- 3:51So it's like being that you physically install on your server host, it ships out of the box with like almost 200 integrations,
- 3:59like connecting to databases like Postgres or monitoring like Windows APIs or hypervisors like vSphere,
- 4:09pretty much whatever our customers want to monitor.
- 4:12It's our job to like find a way to connect to it and provide useful data.
- 4:18Yeah, excellent.
- 4:19A lot of research into every product that we integrate with.
- 4:22Sometimes the documentation is kind of sparse.
- 4:26So it's lots of investigative work.
- 4:29Yeah, I can imagine.
- 4:30That sounds really fun.
- 4:32And I can see that as a follow on from the way you got started as well, right?
- 4:37Automating a bunch of tasks is not that different from kind of automating integration with 100 different apps
- 4:43and performance counters and logs and different things, right?
- 4:48Definitely.
- 4:48Cool.
- 4:49Is that part of the application performance monitoring type thing?
- 4:52Are there?
- 4:53We do that as well.
- 4:54That's not my team, but yeah.
- 4:56Okay.
- 4:56That's part of what we do.
- 4:57All right.
- 4:57Well, let's go ahead and dive in.
- 5:01Sure.
- 5:01So as I said, if people want to check it out.
- 5:02So as I said, if people want to check it out, you are on the Python packaging discussion.
- 5:07And over there was a broad conversation with a bunch of core developers and other interested
- 5:13folks building tools like Hatch and so on about where are we with packaging?
- 5:19Because a little while ago, I remember packaging mostly felt like pip and set of tools, maybe
- 5:27just just util, something like that.
- 5:29And then it kind of got unlocked the separation of like the build back ends and stuff.
- 5:35And then many people started creating things.
- 5:37We had pip, ENV.
- 5:38We have poetry.
- 5:40We have PDM.
- 5:41There's a bunch of different ones and Hatch is amongst them, right?
- 5:45Yeah.
- 5:45Let's set the stage by just talking about, first of all, what do we mean when we're talking
- 5:50about Python packaging?
- 5:51And I'll ask you for you, right?
- 5:54Like it might mean something different for me than it might mean for you.
- 5:58And it might be different for someone else as well.
- 6:00But let's just start with, you know, when we talk packaging, is that getting libraries
- 6:04to devs?
- 6:05Is that developers deploying their apps to servers?
- 6:08Or is that me sending an executable end product to a desktop?
- 6:13Like, what does it mean?
- 6:15Yeah.
- 6:15That's a good question.
- 6:16I would say all of those are packaging.
- 6:19Historically, though, we've mostly put our efforts toward the first one, which is basically
- 6:25like a developer making a library and making that really simple for other developers to use
- 6:32that library.
- 6:32So in the form of wheels being hosted on PyPI in particular, that's what we put our efforts
- 6:39on, which I think either way you look at it was the right choice to focus on in the
- 6:44beginning.
- 6:45Because like either way, like from either first principles or even hindsight, looking
- 6:50back, you can't build a community without packages and being able to get packages and distribute
- 6:57packages.
- 6:58So I think that was the right choice.
- 7:00And I think now we're trying to satisfy other use cases.
- 7:04Notably applications, I guess.
- 7:07Yeah.
- 7:07Yeah.
- 7:07I mean, we even have an XKCD for it, right?
- 7:10True.
- 7:11And I don't know how many people know this.
- 7:13If you're in the Python REPL, you can type import anti-gravity.
- 7:17And actually, it does something.
- 7:20So the old XKCD is there's a person flying and the person on the ground looks at us.
- 7:25How are you flying?
- 7:26Python just learned it last night.
- 7:29Everything's so simple.
- 7:30Hello world is just print.
- 7:32Hello world.
- 7:32The person on the ground says, I don't know.
- 7:34Dynamics typing white space.
- 7:36Come on, join us.
- 7:38Programming's fun again.
- 7:39Okay.
- 7:39But how are you flying?
- 7:40I just typed import anti-gravity.
- 7:42Right.
- 7:43And it's a great joke.
- 7:45But honestly, that is one of those superpowers of Python.
- 7:49Is that how many things do we have right now?
- 7:52How many packages?
- 7:52436,000 packages.
- 7:55Like insane.
- 7:57It's just insane.
- 7:58Yeah.
- 7:58No, it's a massive community and really all kinds of domains from doing, you know,
- 8:04as we talked about automating scripts, you know, different tasks to doing like
- 8:09computing for, whether, you know, biomedical stuff, you know, even embedded devices now
- 8:17with like, micro Python, stuff like that.
- 8:20So it's, yeah.
- 8:21Users of Python do everything pretty much.
- 8:24Yeah.
- 8:25I think in the near term, we're going to be talking about front end web as well with
- 8:30PyScript and PyScript showed the possibilities, but I recently had a show on PyScript intersection
- 8:39with micro Python.
- 8:40And that starts to be like, well, here's a couple hundred K download.
- 8:44And now you've got Python in the front end.
- 8:46What do you think about it now?
- 8:47But of course that has its own packaging and distribution story that we're going to have
- 8:52to think about as well.
- 8:53Like, well, kind of like node modules.
- 8:55Now, what do you do with packages that got to run on the front end?
- 8:57This is getting weird.
- 8:58That kind of goes to, you know, talking about like how hard it is to do packaging when you
- 9:04have, you know, dozens of use cases that we have to satisfy.
- 9:08And with us being mostly just volunteers in our free time trying to do everything.
- 9:14So, yeah.
- 9:14Yeah.
- 9:15It's fun and also challenging.
- 9:17Yeah.
- 9:18Yeah.
- 9:18Absolutely.
- 9:18Another area, another thing we could consider could be Conda, right?
- 9:23Actually, I got that pulled over here.
- 9:25Could be Conda, right?
- 9:26This is a completely different take on pip and Wheels.
- 9:30Yeah.
- 9:30Conda is pretty cool.
- 9:31I think Conda, if I have my history right, it came about because there really was no packaging
- 9:37story.
- 9:38Yeah.
- 9:38Some time ago.
- 9:40So, Conda, I think was made by Peter Yang, if I remember correctly.
- 9:44And he has a whole company now around it supporting Conda.
- 9:48And yeah, it just makes it easy to install, very complex stuff.
- 9:53So, if your package depends on, yeah, you can put in Fortran and Rust and all kinds of stuff
- 10:00and it just magically builds it and you can install it pretty easily.
- 10:05Yeah.
- 10:06It's pretty impressive.
- 10:07It is pretty impressive.
- 10:08And, you know, with Wheels now, it's closer, what we do with Pip.
- 10:12It used to be setup.py would run and whatever it needed to do, it would do.
- 10:17But often that would require, well, compile this.
- 10:19Usually it was C back then, but for the scientific libraries, it says, well, compile this thing
- 10:26with Fortran and then compile this thing with Scala.
- 10:29You're like, I have neither of those things set up as dev tools on my environment.
- 10:33I'm a science student.
- 10:35What am I doing here?
- 10:36Right.
- 10:37And so, that was the angle they were solving.
- 10:39And I think pip and Conda are coming a little bit closer together.
- 10:42I think they're not necessarily converging, but they're more similar now than they used to be.
- 10:47Yeah, definitely.
- 10:47That is true.
- 10:48And yeah, there was talk.
- 10:50I don't know how many people are aware, but the Python forums has a subsection on discourse
- 10:56for packaging.
- 10:57So, yeah, right now there's actually talks from people at Conda trying to decide how we
- 11:03can kind of provide a more unified experience.
- 11:07Oh, that's interesting.
- 11:08Because right now, Conda has their own repo for all their packages.
- 11:12And PyPI is its own thing outside of Conda.
- 11:17So, yeah, there's talk about possibly making that interoperable.
- 11:23Oh, yeah.
- 11:23Okay.
- 11:23That'd be really interesting.
- 11:24Let's see.
- 11:25There was a question out here from Copa.
- 11:28It says, we're in this realm.
- 11:30Like, what do you think about Docker as a way of shipping things?
- 11:33You know, a lot of times we'll get checkout, git clone some code on a server, maybe some production
- 11:40branch, and then go through these steps, right?
- 11:43Pip install requirements or a hatch run type of initialization, or you just get that done
- 11:50in a Docker container and you just hand that out.
- 11:52What are your thoughts on Docker as part of this?
- 11:54Yeah, Docker definitely has its use cases.
- 11:57Like, I guess in lieu of the block file, you could kind of use Docker as a reproducible,
- 12:03you know, environment.
- 12:05But I still think there's a place for a way to actually build applications and, you know,
- 12:11outside of Docker, outside of containers in a reproducible fashion.
- 12:15I think that's still necessary.
- 12:17I do as well.
- 12:18And so Docker really, it addresses some of the types of packaging that we discussed really,
- 12:25really well.
- 12:26For example, I need to get my running code onto a server, but Docker is less good.
- 12:32It's not completely irrelevant, but it's less good at giving a developer a library, right?
- 12:37If people that make HTTPX and the people that make FastAPI, they're not going to build a
- 12:44combo Docker, right?
- 12:46There's still a place where you've just got to get the things.
- 12:49And that's like a base level closer to where a hatch might be working.
- 12:52And also Docker is not fantastic at sending to an end user.
- 12:56If I want to build an app that a non-technical, non-developer person can use, Docker is the
- 13:02opposite of what they want.
- 13:03You know what I mean?
- 13:04Yeah, true.
- 13:04Yeah.
- 13:05I will say there's another use case, which is like, if your machine is like messed up somehow
- 13:11and some library package isn't working.
- 13:14I've had this happen with my coworkers on their Macs.
- 13:18It is nice to be able to just go into a container and start fresh.
- 13:22So I've had that happen a few times.
- 13:24It is isolated in quite a good way.
- 13:26And that's pretty excellent.
- 13:28So on that packaging panel that we were on, there was a really interesting focus for a little
- 13:36bit talking about, well, what is responsible for what?
- 13:41So right now, for example, I might use pip as a way to add tools to Python, to a Python project,
- 13:49but I'll have to already have Python there.
- 13:52And in other communities, and even a little bit like Honda in this as well, there's tools
- 13:58that will say, what you do is use a tool kind of like pip, but it gets you the runtime.
- 14:03It would get you a version of Python you asked for plus the libraries.
- 14:07You know, I think RustUp was one of the things that was brought up there, right?
- 14:14So for people who don't know RustUp, it's an installer for basically setting up a Rust environment
- 14:21for doing Rust.
- 14:22So pip up, Python up, I don't know.
- 14:25I don't know what we would call it.
- 14:26But do you want to just, you know, maybe give your thoughts on that?
- 14:29Because I think you had some comments on that, like inside out, outside in, where, if you
- 14:34could start fresh, where were the tools?
- 14:36How would that work?
- 14:37Yeah, I think if we were to start fresh, I think the way Rust does it is like now the
- 14:41gold standard.
- 14:42It's probably the best way to do it, which is how, as you mentioned, Conda, a similar thing,
- 14:49where you have a tool that you download.
- 14:51And that one tool is in charge of managing the various Python or programming language versions.
- 14:59So if I were to start fresh, you would have a tool like catch that you would download, you
- 15:05know, as an MSI or EXE or some kind of installer similar to RustUp.
- 15:10And then that tool would manage the various Python versions and environments and packaging.
- 15:17So for RustUp, when you download this, it gives you RustUp, which manages Rust.
- 15:23But then it gives you Cargo, which is a separate command.
- 15:27And that's their package manager.
- 15:29But in both cases, they live outside of the Python.
- 15:32Interesting.
- 15:32Yeah.
- 15:32Cargo is to Rust as pip is to Python, right?
- 15:35That kind of thing.
- 15:36Hey, folks, let's pause for an ad.
- 15:40Remember last time I had this advertisement for Microsoft for startups?
- 15:43Well, I asked the AI to have some fun with it just to show you how powerful what they have
- 15:48on offer really is.
- 15:50Here we go.
- 15:50Me.
- 15:52Can you rephrase that Microsoft Founders Hub ad as a hipster?
- 15:55AI.
- 15:56Sure.
- 15:57Here's a rephrased version of the ad in hipster style.
- 16:00Yo, Talk Python fam.
- 16:02This segment is brought to you by the sickest program out there for startup founders, Microsoft
- 16:06for startups Founders Hub.
- 16:08If you're a boss running a startup, you're going to want to listen up because this is the
- 16:12deal of a lifetime.
- 16:13Microsoft for Founders Hub is your ticket to scaling efficiently and preserving your runway
- 16:17all the while keeping your cool factor intact.
- 16:20With over six figures worth of benefits, this program is seriously next level.
- 16:24You'll get $150,000 in Azure credits, the richest cloud credit offering on the market,
- 16:29access to the OpenAI APIs in the new Azure OpenAI service, where you can infuse some serious
- 16:35generative AI into your apps, and a one-on-one technical advisory from the Microsoft squad, who
- 16:41will help you with your tech stack and architectural plans.
- 16:44This program is open all, whether you're just starting or you're already killing it.
- 16:47And the best part, there's no funding requirement.
- 16:50All it takes is five minutes to apply, and you'll be reaping the benefits in no time.
- 16:54Check it out and sign up for Microsoft for Startup Founders Hub at talkpython.fm slash
- 16:58foundershub.
- 16:59Peace out and keep listening.
- 17:01Thank you, Hipster Michael.
- 17:02And thank you, Microsoft for Startups Founders Hub, for sponsoring the show.
- 17:08I think that's pretty helpful because one of the problems is, well, you need to pip install this
- 17:13thing.
- 17:13Oh, do you have the wrong version of Python?
- 17:15Well, you got to, you know, there's a lot of steps back, and there's no immediately obvious
- 17:20command other than completely from scratch install a new Python.
- 17:24Yeah.
- 17:25There's the tools that manage that, right?
- 17:26Like, PyEnv can work, although I've had trouble with it.
- 17:30Yeah, I've had issues with that.
- 17:31Yeah, I think it would be less error-prone in this hypothetical way, where the tool doesn't
- 17:37mess with your shell in a global manner.
- 17:41It just has its own paths to Python and just does everything by itself.
- 17:47That's interesting, and that starts to maybe make it easier to solve the, I want to ship
- 17:52you an executable binary, is if the tool were in charge of, I create this working directory
- 17:58where part of the things I've installed is all of Python and all the packages you've asked
- 18:04me for, I can see how that pretty quickly becomes something.
- 18:07I'll bundle that up and hand it to somebody and, you know, give them an entry point.
- 18:11Definitely, I could help that situation.
- 18:13I think there's not really a standard way to build an AXE from like a Python package.
- 18:20There are a few tools, like PyOxidizer is one newer option.
- 18:25PyInstaller, CX Freeze, I think was the thing that I've used before.
- 18:30So there's a few options.
- 18:32Yeah, I've used PyToApp, and that's actually worked really well.
- 18:34I've used PyInstaller, and it's worked mostly well, except for I've had weird situations
- 18:39where on Windows it's great, but on Mac it has a dangling terminal.
- 18:44In addition to the GUI, I'm like, what are we supposed to do that?
- 18:47How do we make it go away?
- 18:48Like, you know, here's the command.
- 18:50Like, no, it's not going away.
- 18:51I don't know why.
- 18:52And if there was a more official sort of core dev organized way, that would make me super happy.
- 18:58I'm not supposed to say for official or unofficial.
- 19:01Like, my view is like, if it works, it works.
- 19:05So as long as it's satisfying, you know, all the use cases, that's what I would push for.
- 19:10So I think right now, based on what I've used personally, I think PyOxidizer would be the
- 19:16best choice for distributing standalone apps.
- 19:19Interesting.
- 19:20Okay.
- 19:20All right, cool.
- 19:21Well, let's move on and start talking about Hatch.
- 19:26So first off, why'd you build it?
- 19:29Right?
- 19:30We had Pip.
- 19:31Why do we need Hatch?
- 19:33And, you know, I don't know exactly the timeframe of when it came out.
- 19:36So maybe we had other things like poetry or, you know, why'd you go and create this?
- 19:40So Hatch, I did, it was kind of an older project back in the end of 2016 or early 2017.
- 19:48I wasn't pleased with like the tooling in Python.
- 19:53I think very similar to the author of poetry.
- 19:56That's kind of why he made poetry.
- 19:58So I wanted something that kind of matched my mental model of how development would go
- 20:05with building packages and managing environments automatically, stuff like that.
- 20:10When I made it though, there weren't very many standards for packaging.
- 20:15And everything was kind of in limbo at that point, which kind of discouraged me from continuing.
- 20:21Because then I was like, okay, in a six months or a year or two, I'm going to have to rewrite
- 20:27to follow standards.
- 20:29So I kind of just stopped development for a few years until everything was standardized.
- 20:35And then I rewrote it about a year and a half ago with this new version and new docs.
- 20:42So that's kind of the history of it.
- 20:45Yeah.
- 20:45I saw that there's a hatch.toml and a pyproject.toml and you can use either of them.
- 20:51Was your hatch.toml the original and then pyproject.toml gained traction?
- 20:56You're like, all right, well, we'll integrate with that as well.
- 20:58No, hatch.toml came with the rewrite.
- 21:01It's mostly for environments.
- 21:03Sometimes when you define lots of environments, it's very verbose.
- 21:07Like at my workplace, I saw a tox file that was like over a thousand lines.
- 21:13So putting that in pyproject wouldn't be very nice.
- 21:17So that's why I have a second file to isolate certain features.
- 21:20Yeah, that makes sense.
- 21:21Just like maybe you don't want to write your entire application in an app.py,
- 21:24but maybe have multiple files.
- 21:27Yeah, something like that.
- 21:28All right.
- 21:28Well, out in the audience, we've got some kind words.
- 21:31Like I switched to hatch and pip-tools from poetry and love it.
- 21:34That's pretty awesome.
- 21:35Yeah.
- 21:36And then probably before I'll forget, because it was right at the top of the conversation,
- 21:40Marwan asks, is there a time estimate for when a hatch might support things like lock files?
- 21:47That's a good question.
- 21:48So my goal is by PyCon to write the plugin interface for locking.
- 21:58So the first version will use pip-tools, actually.
- 22:01That would be the first plugin for lock files.
- 22:04But I won't be writing like an actual lock file spec.
- 22:08I'll just be using an existing tool.
- 22:12It's kind of blocked on Brett because he has most context and knowledge about that.
- 22:18So yeah, I'm waiting on Brett, basically.
- 22:21Got it.
- 22:21Brett Cannon.
- 22:22That being Brett Cannon.
- 22:23Yes.
- 22:24Python developer extraordinaire.
- 22:25We all know.
- 22:26Okay.
- 22:27Very cool.
- 22:28Other thing before we dive into it here.
- 22:29I see that you have some rough action going there.
- 22:33I just had Charlie on the show not too long ago to talk about rough.
- 22:37It's pretty impressive.
- 22:38When did you adopt that?
- 22:40I was an early adopter.
- 22:41I guess a few months ago now.
- 22:43Yeah.
- 22:43What's your experience?
- 22:44It's fantastic.
- 22:45It's kind of like a meme to say it now, but it's true.
- 22:48Like, it's so fast.
- 22:49It's almost like you wonder if it's doing anything.
- 22:52Like, it's...
- 22:54That was my first thought.
- 22:55When I ran it, I'm like, wait a minute.
- 22:56Maybe I didn't give it any files or something.
- 22:57Because I ran it on Talk Python training, which is like 20,000 lines of Python code.
- 23:02And it just went, bam, like that.
- 23:04And I'm like, maybe it didn't take that.
- 23:05Because that seems like that should take a moment at least somehow.
- 23:09Yeah.
- 23:10Okay.
- 23:10So you recommend it?
- 23:11Yeah.
- 23:12All around kind of one location.
- 23:13And it supports, like, so many options as well, which is nice.
- 23:19Yeah.
- 23:19Indeed.
- 23:19Cool, cool.
- 23:20All right.
- 23:21Well, let's start with a high-level overview.
- 23:24And then what I want to do is I want to walk through creating a project with this.
- 23:28And I've got questions and thoughts as I kind of experience Hatch.
- 23:32Not for the first time, but for somewhat of a newbie perspective.
- 23:36So I think we'll do that.
- 23:37But let's start with the high-level features.
- 23:40So the Hatch project is, I guess, conceptually two different projects.
- 23:44Hatch itself is the command line.
- 23:47So doing publishing and environment management, versioning, stuff like that.
- 23:53Then Hatch thing is the build system, similar to a flip or set tools.
- 24:00So that's where the build system is.
- 24:03And you can use it independently, right?
- 24:05You don't have to be doing anything with Hatch to use HatchLeen.
- 24:09Basically to replace setup.py, right?
- 24:13Yeah.
- 24:13You can replace it with the pyproject.toml.
- 24:16Yeah.
- 24:17And most people do use HatchLeen and not use Hatch.
- 24:21So yeah.
- 24:22HatchLeen is much more popular than Hatch itself.
- 24:25Okay.
- 24:26So for a config, it's a bit more simple than setup tools.
- 24:30The default logic makes more sense for new users, especially.
- 24:37It's hard to mess up packaging with HatchLeen.
- 24:41Yeah.
- 24:41Excellent.
- 24:41So I could have just some random Python project that I've put together with a PyProject.tomal
- 24:47I wrote by hand and I could just put HatchLeen in as the build subsystem to make the wheels
- 24:53and whatnot, right?
- 24:54One benefit of HatchLeen, I hatched too.
- 24:56Basically everything is a plugin.
- 24:58So you can have like a build hook that does like the mypyc, which we have.
- 25:04You can have a metadata hook where you insert like project URLs from some arbitrary location.
- 25:12Pretty much everything you can plug into and modify.
- 25:16Yeah.
- 25:16Excellent.
- 25:17All right.
- 25:18And then a robust environment management.
- 25:20Yeah.
- 25:21So for this, this you can think of as a, as talks or knocks, similar in spirit to that.
- 25:28The difference is knocks and talks kind of treat environments as applications where an environment
- 25:36is tied to a command and you run an environment.
- 25:39Whereas in Hatch, you have environments that you define.
- 25:43And then within that, you have scripts that you can run.
- 25:47So you can have a style environment that might be able to rent with one script or run the
- 25:55formatter to change the code with another script.
- 25:58An environment itself isn't actually like, like an app.
- 26:03You can run arbitrary commands.
- 26:05Right.
- 26:06Like I could run Hatch test or something like that.
- 26:10Yeah.
- 26:11And passing flags.
- 26:12Yeah.
- 26:12Okay.
- 26:13And then often people who published packages to PyPI, they've done this with Twine or some
- 26:21tool like that.
- 26:21And Hatch has that capability as well, right?
- 26:24Right.
- 26:24Yeah.
- 26:24To, yeah.
- 26:25PyPI or some private, you know, corporate owned index.
- 26:31I think those are probably going to be more popular than they used to be with all the supply
- 26:36chain silliness.
- 26:37Yeah, that's true.
- 26:38Yeah.
- 26:39Do you have any visibility into how people are using it, whether it's public or private or
- 26:43As far as Hatch?
- 26:45Yeah.
- 26:45Well, how they're using Hatch to publish, do you have any visibility whether they're
- 26:49publishing to PyPI or to some kind of private index?
- 26:52Based on the issues I have open, like future requests, most are talking about private indices,
- 26:58actually.
- 26:59Interesting.
- 26:59Yeah.
- 27:00It's probably those are the ones where the edge cases live.
- 27:02You know, the standard one place is dialed in.
- 27:05And what if mine's using Active Directory for authentication as I publish it?
- 27:10Like, it's doing what?
- 27:11Artifactory is quite popular as well.
- 27:15Yeah.
- 27:15Yeah.
- 27:15That absolutely is.
- 27:17Another thing that was interesting is you have the ability to do version management,
- 27:21as we'll see in just a minute.
- 27:22You can say, like, what version is my package?
- 27:24Increment the build or do a major version increment or put it into a release candidate mode.
- 27:30Yeah.
- 27:31And this is plugable as well.
- 27:33So there's one plugin that's popular that wraps setup tools SCM, which doesn't actually
- 27:39depend on setup tools anymore.
- 27:41It's just in name.
- 27:42It's still called that.
- 27:44So that pulls your version from Git or Mercurial or Subversion.
- 27:49And you can source the versions that way as well.
- 27:53Interesting.
- 27:53Yeah.
- 27:53I really like that.
- 27:54I think that's a neat aspect.
- 27:56And then configurable project generation with same defaults.
- 28:01Yeah.
- 28:01I don't have too many options with this yet, but you can make it a flat layout or like a source
- 28:08directory.
- 28:09There's an option to add tests, which puts more stuff in your PyProject.com.
- 28:16You can add a CLI, which has a very simple template for GitHub actions.
- 28:22And then there's a flag for your CLI that would give you a click and set up a command line for
- 28:30your package.
- 28:31I don't know how directly related this is to anything that Hatch does.
- 28:35But the usage of the PyProject.toml and then building it as a package, something you could
- 28:40install, gives you a really nice way to create a global CLI, right?
- 28:45With just the entry points in the PyProject.toml.
- 28:48Yeah.
- 28:48That's what that CLI flag does.
- 28:49Yeah.
- 28:50It's very nice.
- 28:51Okay.
- 28:51Yeah.
- 28:52Then also you say it's two to three times faster than equivalent tools.
- 28:55That's great.
- 28:56It really is just one trick.
- 28:57It's just I make the code not as readable by using lazy imports everywhere.
- 29:04I just put lazy imports and that's why it's faster, essentially.
- 29:08Yeah.
- 29:09Because there's a lot of execution paths that only use some of the imports in effect, right?
- 29:12Yeah.
- 29:13Going back to the scripts, Jonathan points out, I love the custom scripts within Hatch.
- 29:17It makes creating build pipelines way easier and moves most of the logic within the Hatch
- 29:22configure rather than spreading them around multiple files, which is, that's pretty cool.
- 29:25Yeah.
- 29:25That's what I do as well.
- 29:26Cool.
- 29:26I even use Hatch for non-Python projects just for the scripting.
- 29:31Yeah.
- 29:32Cool.
- 29:32Well, I mean, Python traditionally had been used for a lot of that, you know, called it glue
- 29:38code, right?
- 29:38A lot of, well, I really want to do these other things with these other systems and scripts,
- 29:42but let me kind of orchestrate that in Python.
- 29:44And that sounds a bit, a bit like that.
- 29:46Yeah.
- 29:47Let's do a little walkthrough, I think.
- 29:48I think that'll be fun.
- 29:49But first of all, I think this is just MKDocs, but thank you for pointing it out that your
- 29:55documentation and your website here have hotkeys.
- 29:59Yeah.
- 29:59MkDocs with the material theme, which is very nice.
- 30:03Yeah.
- 30:03So it turns out if I just press a dot, it goes to the next page.
- 30:06And if I comment, it goes to the previous page.
- 30:08And it doesn't sound like much, but actually it's really nice.
- 30:11It is really nice.
- 30:12Before we leave this front page, one other thing to note to go back to the top, just because
- 30:17I'm very happy with it.
- 30:18The logo was actually generated by Dolly, the AI.
- 30:22Okay.
- 30:22Yeah.
- 30:23Fantastic.
- 30:24Yeah.
- 30:24I generated the logo.
- 30:25And then I had a brother of a friend from work, I like actually touch it up.
- 30:30So.
- 30:30Oh, it's a really cool logo.
- 30:31I like it.
- 30:32I didn't catch on that it was made by Dolly, but now I see that.
- 30:35I've been doing a lot with mid-journey.
- 30:38And I think these AI tools are, I think they're a little bit fraught with maybe a few moral
- 30:43issues about like, well, did you really train it on stuff that you were allowed to train on?
- 30:47But putting that aside, if they exist, you know, assuming just they exist, they're really
- 30:51neat.
- 30:51And there's really amazing stuff you can do with them.
- 30:53Yeah.
- 30:54Yeah.
- 30:54Cool.
- 30:55I guess maybe a quick sidebar there is if you were a project maintainer out there and you
- 31:00don't really have a logo, drop in on Dolly or Mid Journey and spend half an hour and
- 31:06you probably will.
- 31:07But I just think there are so many people that build web apps out there that don't put
- 31:12hotkeys into them.
- 31:13And it's, it is not that hard.
- 31:15And it is such a nice experience.
- 31:17And it brings you so much closer to a native app type of experience.
- 31:20So please put, put some hotkeys out there for us.
- 31:22All right.
- 31:23So pressing dot takes to the first one.
- 31:25So installing hatch, obviously you can pip install it.
- 31:28However, you offer some interesting other areas I want to talk about.
- 31:32First of all, my favorite pipX.
- 31:35I love pipX.
- 31:36If you've got a tool that you don't directly import into your code that does stuff against
- 31:42your Python apps.
- 31:43Boy, pipX is almost always a good choice.
- 31:46What do you think?
- 31:47Oh yeah.
- 31:47PipX is awesome.
- 31:48Yeah.
- 31:49Yeah.
- 31:49It just allows you to, you know, provide isolated apps for command line apps.
- 31:55Yeah.
- 31:55It manages everything and you don't even have to think about it.
- 31:58So yeah.
- 31:59It just creates its own little environment.
- 32:00And you can say upgrade all my installed CLI tools.
- 32:03It's like package manager.
- 32:05If the thing that it's managing is built with Python is great.
- 32:08I had chat on the creator of pipX a while ago.
- 32:11So people, if they want to hear more about it, they can listen to that show.
- 32:13Homebrew.
- 32:14Good.
- 32:14MacPort is interesting.
- 32:17But the one that stood out to me was Mamba.
- 32:19I'm like, wait, what's Mamba?
- 32:23It's interesting.
- 32:24I hadn't heard of that, but yeah.
- 32:25Yeah.
- 32:25I don't use Konda that much, but as far as I know, there's a few different distributions
- 32:30of Konda.
- 32:31So there's Anaconda, which gives you like over a gigabyte installed, like massive scientific
- 32:39computing.
- 32:39There's Miniconda and Miniconda gives you just the bare minimum Konda CLI with like package
- 32:47management.
- 32:48And that's what most people use, I think.
- 32:50But now there's Mamba, which is like Miniconda.
- 32:53But it pulls from Konda Forge by default.
- 32:57And Konda Forge is sort of like our PyPI, where anybody can contribute their own packages.
- 33:05So I think that's the main difference.
- 33:07And yeah, it is faster and it was rewritten.
- 33:11And that's what Mamba is.
- 33:13It's a re-implementation of Konda, the Konda package manager in C++, doing parallel downloading
- 33:20and other bits of that, which is interesting.
- 33:23Cool.
- 33:24Well, I don't use either all that much, but it's still kind of cool to see there.
- 33:29So you could Mamba install Hatch if that was your workflow as well, right?
- 33:33Okay.
- 33:34So installing it pretty easy.
- 33:36If you were to do it, if somebody gave you a blank machine and said, set this up to use
- 33:40Hatch, what would you do?
- 33:42For now, I would do PIPX.
- 33:44Okay.
- 33:45In the future, like we talked about in the beginning, I plan to have like an actual executable that
- 33:51does the work, like Python does.
- 33:53But until then, then probably PIPX.
- 33:56Okay.
- 33:56So maybe then it would be Homebrew and Winget and apps, things like the higher level OS ones.
- 34:03Okay.
- 34:03This portion of Talk Python To Me is brought to you by Sentry.
- 34:08Is your Python application fast?
- 34:11Or does it sometimes suffer from slowdowns and unexpected latency?
- 34:15Does this usually only happen in production?
- 34:18It's really tough to track down the problems at that point, isn't it?
- 34:21If you've looked at APM, application performance monitoring products before, they may have felt
- 34:26out of place for software teams.
- 34:28Many of them are more focused on legacy problems made for ops and infrastructure teams to keep
- 34:33their infrastructure and services up and running.
- 34:36Sentry has just launched their new APM service.
- 34:40And Sentry's approach to application monitoring is focused on being actionable, affordable, and
- 34:45actually built for developers.
- 34:47Whether it's a slow running query or latent payment endpoint that's at risk of timing out
- 34:51and causing sales to tank, Sentry removes the complexity and does the analysis for you,
- 34:57surfacing the most critical performance issues so you can address them immediately.
- 35:01Most legacy APM tools focus on an ingest-everything approach, resulting in high storage costs,
- 35:07noisy environments, and an enormous amount of telemetry data most developers will never need
- 35:12to analyze.
- 35:13Sentry has taken a different approach, building the most affordable APM solution in the market.
- 35:19They've removed the noise and extracted the maximum value out of your performance data while passing
- 35:23the savings directly onto you, especially for Talk Python listeners who use the code Talk Python.
- 35:29So get started at talkpython.fm/sentry and be sure to use their code Talk Python all lowercase
- 35:36so you let them know that you heard about them from us.
- 35:39My thanks to Sentry for keeping this podcast going strong.
- 35:43All right, so the way we get started is we just say Hatch New.
- 35:50And I thought one of the things I don't normally do here on the podcast, but I think it might be fun,
- 35:54is just to kind of go through these steps here to see what it's like to get a sense,
- 36:00because then I can ask questions.
- 36:02So I'll say Hatch New Calci.
- 36:05I'll call my little app Calci.
- 36:06And tell us about what we get when we run that.
- 36:08Sure.
- 36:09So it makes your package as you named it with About.py and Init.py.
- 36:16The Init.py obviously makes it, turns that directory into a Python package.
- 36:21The About.py stores the version by default.
- 36:25And that's where it reads it by default.
- 36:28It gives you, oh yeah, go ahead.
- 36:30Well, I was just going to say, one of the things I can type now is Hatch version.
- 36:33And it gives me, basically pulls out the version of About.py, right?
- 36:38Yeah, and you can, if you do the same command again, but pass in R like minor,
- 36:44then you can bump it as well.
- 36:46Yeah, so the old version is what it says, is 001.
- 36:49The new version is 010.
- 36:51Could I say build and get 11?
- 36:53Something like that?
- 36:54No, what would I type to change the last one?
- 36:56RC.
- 36:56You should do RC.
- 36:57Okay.
- 36:58It's documented the allowed arguments as well.
- 37:01Got it, yeah, sure.
- 37:01So yeah, then it also gives you a test directory that doesn't have any predefined tests,
- 37:07but you can add tests to it.
- 37:09And then the most important part is the PyProject.tomla,
- 37:13which has your metadata and your other config.
- 37:17So it's got the build system set to be Hatchling.
- 37:20And then it's got all the project settings, like who is the author?
- 37:23What are the requirements?
- 37:25And all that stuff, right?
- 37:26And from the author, it would have gotten that from Git.
- 37:29The default comes from Git.
- 37:31So that's why it has the right stuff for you.
- 37:33And then down here is testing.
- 37:36So some coverage stuff and environments.
- 37:40When I typed Hatchinew, could I have made it ask me those questions, like who are you and stuff?
- 37:44There is an interactive mode, yeah.
- 37:46Okay, yeah.
- 37:47Yeah, so you also, as part of this PyProject.tomla, you create some of these commands.
- 37:54These are the scripts you were talking about a little bit, right?
- 37:56Like you've got the test and other options you can run.
- 37:59This default example down there has environment, which is just default, which is a little bit special.
- 38:06It just means you don't have to add a prefix on the command line.
- 38:09And so there's two scripts by default.
- 38:11A cove.
- 38:13So you could do like a hatch run cove, and it would run pytest with coverage.
- 38:18And then another command is no cove.
- 38:21Yeah.
- 38:21And I can do hatch test, hatch run test.
- 38:24Is that a thing as well?
- 38:25There is no test command.
- 38:26You could do pytest.
- 38:28So if you do hatch run pytest, it could, yeah.
- 38:31Yeah, excellent.
- 38:32That's really cool.
- 38:32Yeah, so it basically creates the structure for you.
- 38:36And the workflow that we just discussed would be if I've got a folder and I want to start from absolute scratch.
- 38:43I want to create the entire directory structure through hatch.
- 38:48But there's also a way I can go to an existing one and kind of convert it to hatch or upgrade it to hatch, right?
- 38:55Me and other contributors have done it so much that most of the edge cases are gone.
- 39:01So it can take pretty much any setup.py and turn it into hatch pyproject.tomalot.
- 39:09It's pretty good now.
- 39:11Okay.
- 39:11And because it doesn't actually need hatch the CLI, the environment tool to do that, to run and build,
- 39:20you could just use that to get your pyproject.tomalot and use hatchling as a build engine, right?
- 39:27But still just keep going.
- 39:28Yeah, exactly.
- 39:29Okay.
- 39:29So people are sitting out there like, I really should be using pyproject.tomal, but, you know, inertia, I don't really want to do it.
- 39:36Like, hatch new init might do it, right?
- 39:39Yeah, yeah.
- 39:40That's an option.
- 39:41Before you time out, if you do which Python, maybe I can just illustrate.
- 39:46And if you do hatch run which Python 3, it will show you that it's actually in a managed virtual environment.
- 39:53Okay.
- 39:55So it's created a virtual environment over in, at least for me, library application support, hatch environments, and so on, so on, based on the project name.
- 40:03And then it has some big long deal on the end?
- 40:05It's just a hat, yeah.
- 40:06It's just a checksum.
- 40:08Okay.
- 40:08What is that a checksum based on?
- 40:10The reason I ask is, what do I change to make this no longer work?
- 40:16So I do that because it's possible that somewhere else on your machine, you might have another project, maybe a fork of calci with the same name.
- 40:25So I have to have a hash.
- 40:26Likely.
- 40:26It's a very popular library, so it's likely.
- 40:29That's why I do that, yeah.
- 40:31I see.
- 40:31Okay.
- 40:31That's like a hash of the path to where the project is or something.
- 40:35Okay.
- 40:35Yep.
- 40:35A lot of projects, a lot of management tools work this way.
- 40:38Conda works this way, for example, where there's some other place where the virtual environments live.
- 40:44Is there a way, another workflow that's pretty common is to have the virtual environment in a VNV folder at the root of the project.
- 40:51Is there a way when I create my project to say, I want a local ENV?
- 40:56Not at project creation time, but there is a way in either hatch config or in pyproject.tomo.
- 41:04They're able to change that.
- 41:05Yeah.
- 41:06Which is documented on the site.
- 41:08Yeah.
- 41:08The hatch config is one of the things I would do.
- 41:13There's a lot of cool CLI tools where you can ask it to show me the details of whatever it is.
- 41:18So what would I put, say, into the config to say, create my VNV locally and call it what?
- 41:27Is it this DERS VNV?
- 41:28Yeah, DERS and ENV.
- 41:30Yeah.
- 41:30What would I put in there?
- 41:32You would have a subtable for virtual and then have the path be just .vend, basically.
- 41:40Right.
- 41:40Okay.
- 41:41So like a .slash, whatever you want to call it locally.
- 41:43Yeah.
- 41:44Is this, I guess I could do hatch find config or config find, I guess?
- 41:50Config find.
- 41:51Config find.
- 41:51Yeah.
- 41:52Right.
- 41:52And that will, so this is a global, like, how do my projects get started using hatch for my machine, not a per project deal, right?
- 42:00Yeah.
- 42:00That's cool.
- 42:01So kind of like git config.
- 42:03Once I set up my machine, if I say, well, I like my virtual environments like this, then I'll be okay.
- 42:09Right?
- 42:09Yeah.
- 42:10It makes it easier to distribute tooling.
- 42:12Like for, if you're managing like some corporate environment where you're using hatch for everything, then it's nice to have a config that you can modify.
- 42:22Just as a machine level, then every project will do the same.
- 42:27Just as a team to say, look, we always want tests.
- 42:30We always want this other thing that we call it that we always want this default library.
- 42:34Sorry.
- 42:35We want this default license, right?
- 42:37We don't want MIT.
- 42:39We want, you know, corp.inc or whatever license that we use.
- 42:43So quick question from ZL out there that I think is relevant.
- 42:46Is this useful for application development, not libraries?
- 42:50Say if I'm building like a Flask app or a FastAPI app, like would, would this be relevant?
- 42:55Yeah.
- 42:55So especially with the environment management, that's kind of what applications will use anyway.
- 43:00The missing feature, of course, like the other person asked is the lock files.
- 43:06For any app you're going to want to be able to reproducibly build the app.
- 43:11So right now there's not a way built in other than using an environment with like pip-tools or something.
- 43:18So I'm going to add that plugin interface soon.
- 43:21Interesting.
- 43:22Does pip-tools work with piproject.toml?
- 43:24It does now.
- 43:24Yeah, it does.
- 43:25Yeah.
- 43:26I've only used it with requirements.in and then generate the requirements.txt of it.
- 43:30Yeah.
- 43:31They added that last summer, I think.
- 43:33I'm so behind the times on this.
- 43:34You know, these workflows, I'm sort of joking, but also not.
- 43:38These workflows, you kind of get into like, well, here's how I build these apps.
- 43:41Here's how I manage my requirements.
- 43:43And then you just tunnel, I think a lot of people just go, okay, well, that's working
- 43:47for me.
- 43:47I'm doing that.
- 43:48You know?
- 43:48Yeah, me too.
- 43:49Me too.
- 43:49Yeah.
- 43:50Yeah.
- 43:50Yeah.
- 43:50And then, so if I want to, like, so for example, when I asked which Python, it said the one from
- 43:58Homebrew you've installed, silly.
- 43:59Of course, that's your global Python.
- 44:01If I want to activate a virtual environment, if I want to get into like this application
- 44:06mode, I would do hatch shell, right?
- 44:09Yes.
- 44:09Uh-huh.
- 44:10And because I have an awesome, oh my posh, you can see my prompt here's now taking on
- 44:14the calci 3.11.2 environment as part of my prompt.
- 44:18So.
- 44:18That's very cool.
- 44:19Yeah.
- 44:19That's the one.
- 44:20So it's working.
- 44:21Now, if I ask just straight up, which Python is that virtual environment one, right?
- 44:25Yeah.
- 44:26And I can do pip list and so on, but there's also ways, I think I recall, in hatch to like
- 44:32show me my dependencies and get a list of.
- 44:34Yeah.
- 44:34Hatch, dep, show.
- 44:36Dep, show.
- 44:37Yeah.
- 44:37Is it show dep?
- 44:38Table.
- 44:38Ah, table.
- 44:39It's just a few options.
- 44:40Yeah.
- 44:40Okay.
- 44:41That's your environment.
- 44:42I only have right now two dependencies, pytest and pytest cov.
- 44:45Yeah.
- 44:46Interesting.
- 44:46Or I could do requirements.
- 44:49Yep.
- 44:49And I would split out the.
- 44:50The same, but it's not as a table, right?
- 44:52Just plain text.
- 44:53Yeah.
- 44:53Just like requirements.txt.
- 44:54Got it.
- 44:55Okay.
- 44:56Yeah.
- 44:56Excellent.
- 44:57What do you recommend?
- 44:58So there's the hatch run commands, which we'll use the environment, or you can just go into
- 45:02the shell and run it.
- 45:03Or if I'm sneaky and I put my virtual environment in there, I might have something that automatically
- 45:11detects that environment and picks it up.
- 45:13So for example, PyCharm might go, you know what?
- 45:16I see a VE and V folder.
- 45:17We'll use that and, and just grab it and not care about hatch directly.
- 45:22Right.
- 45:23That's actually one of the reasons I was asking about putting it locally is it's kind
- 45:27of a hassle to find that thing and tell your editor, go find it over here.
- 45:31Whereas it automatically finds the top level of project variant, you know?
- 45:37Yeah.
- 45:37So you can do, as we talked about, sitting in the current directory, like a .vnv.
- 45:43And yeah, PyCharm VS Code, they'll pick it up because it is just a virtual environment at
- 45:49the end of the day.
- 45:50Nothing too special.
- 45:51So yeah, it will work out of the box.
- 45:54Yeah.
- 45:54And Colette's out there in the audience has got us covered.
- 45:56pip-tools command is pip tool, pip compile, rebuild, output file, such and such, pyproject.txt
- 46:02from pyproject.toml.
- 46:04Yeah.
- 46:05Cool.
- 46:05Nice.
- 46:06Yeah.
- 46:06And variations on that, I suspect.
- 46:08So one thing that I was thinking about this that I expected hatch to do, and maybe it does
- 46:14and maybe it doesn't, I just don't know, is suppose I want to use requests for calci.
- 46:19Like calci can't run locally.
- 46:21It needs its calculator API service that it's going to connect to.
- 46:25So it needs a request or HTTPX or something.
- 46:27Yeah.
- 46:28Is there a way with hatch to say, I have a new requirement, set that up, put it in the pyproject.toml, install it.
- 46:33That's going to come with the lock file plugin.
- 46:36I figured it wouldn't make sense to add those commands until I knew how locking would work.
- 46:43Because adding and removing always hits the locking logic.
- 46:48And since there wasn't locking, it didn't make sense to me to add those commands.
- 46:53All right.
- 46:54Yeah.
- 46:54That makes sense.
- 46:54It's going to come soon.
- 46:55So right now, you would just modify your pyproject.toml until those are added.
- 47:00And then I think there's a way where hatch looked at your pyproject.toml and said, okay, you're
- 47:05going to need these dependencies, right, when you run it.
- 47:09In what sense?
- 47:10I thought it installed the dependencies that were in the pyproject.toml.
- 47:13Even if it won't edit it, like if I put something in there and I try to run it, it'll say, oh,
- 47:17you need this.
- 47:18Yeah.
- 47:18It'll sync automatically.
- 47:19What command do I use to do that one?
- 47:21Either a run command or the shell command.
- 47:25I see.
- 47:25Oh, even the shell will do it, huh?
- 47:27Do you hatch run pip list, for example?
- 47:30Yeah.
- 47:30Okay.
- 47:30Now in pyproject.toml, add requests maybe to.
- 47:35Yeah.
- 47:36All right.
- 47:36Now I have requests and friends of requests.
- 47:38Yeah.
- 47:39Yeah.
- 47:39Yeah.
- 47:39Okay.
- 47:40That's pretty cool.
- 47:41Nice.
- 47:42And then I'm looking forward to the lock stuff because I absolutely love pip-tools.
- 47:46I think it is a glorious way.
- 47:49I used, for a while, I used PendaBot at GitHub and it drives me crazy.
- 47:54It's like so noisy.
- 47:55I'll get like 30 PRs a week.
- 47:58I'm like, you know, could you just package this up?
- 48:01And so now I just start periodically.
- 48:04I just go, okay, I'm going to use pip-tools and just ask like, how has the world changed?
- 48:07And then update my stuff in a more sane way.
- 48:10It was a bit noisy for us too at work.
- 48:12So we had like a custom dependency update logic as well.
- 48:17I think there is an open page request for a dependent bot to chunk the updates, but I
- 48:22don't know if it has happened yet.
- 48:24Yeah.
- 48:24I think I've seen one of those for a couple of years and there was like a hundred plus
- 48:28one.
- 48:28Me too.
- 48:28Me too.
- 48:29Like I got to review these things.
- 48:31You know what I mean?
- 48:32And I don't know if it's there.
- 48:34It's not there on my projects.
- 48:35It's still.
- 48:36Yeah.
- 48:36I'll get 20.
- 48:37I'll do a pip compile update and I'll push that and I'll get like 20 messages.
- 48:42These are no longer required.
- 48:43I'm like, okay, thanks.
- 48:44Could you just batch them?
- 48:47Yeah.
- 48:47Anyway.
- 48:47Yeah.
- 48:48Okay.
- 48:48So calci is coming along here.
- 48:50Let's just imagine that it does good stuff.
- 48:51I haven't even written any code for it, but it depends upon requests.
- 48:55So that's a start.
- 48:55The next step going kind of forking on the various possible definitions of what packaging
- 49:01is.
- 49:01A next step for this thing might be, I want to put it onto PyPI or create a wheel I can share.
- 49:06So hatch also supports that, right?
- 49:08Yeah.
- 49:08So first you have to create the artifacts.
- 49:12So you would do hatch build and that would build Metafault, both the source distribution
- 49:17and the wheel.
- 49:19Okay.
- 49:19Now in your current directory, just like the other tools, there's going to be a dist,
- 49:24D-I-S-T that now has those.
- 49:27And if you run a hatch publish, that would put it on PyPI by default.
- 49:33And it would prompt you for your username.
- 49:37I'm not entering that.
- 49:38I don't want to own calci on PyPI.
- 49:41No, just kidding.
- 49:41But yeah, I don't think I have it configured, so it wouldn't really do anything.
- 49:44But it would.
- 49:45It would go and put it on PyPI, right?
- 49:47Yeah.
- 49:47Potentially.
- 49:48Yeah.
- 49:48That's pretty straightforward.
- 49:49You also point out in the docs that cibuildwheel and things like TOX, you could be
- 49:58the build, just hatchling could be the build system for that, right?
- 50:01Hatch does a lot.
- 50:02So you can use parts.
- 50:04Say you wanted to only use environment management to replace like TOX and NOX, you could do that.
- 50:11If you wanted to only use hatchling with like cibuildwheel or other tools, you could do
- 50:17that.
- 50:17If you wanted to only use the version management, you could do that.
- 50:21It's kind of choose whatever you want.
- 50:24Yeah.
- 50:24You're not locked in.
- 50:25Yeah.
- 50:26So the last thing I could do is publish, but I'm not really going to go.
- 50:29Yeah.
- 50:30There's also a way to set in the config file.
- 50:33You said that if I set into the config file under the publish index, disable true, where
- 50:39you can make it confirm rather than just straight up publishing it, right?
- 50:42Yeah.
- 50:43That was a feature request.
- 50:44Yep.
- 50:45So yeah, cool.
- 50:45Another thing that is always, I've always stumbled on when I do this, at least with Twine is I'll
- 50:53have some project.
- 50:54I've done this.
- 50:55I published a version later.
- 50:56I'll come back to it.
- 50:57I'll make some changes.
- 50:58I'll increment the version.
- 50:59I used to have to do that manually, but now I can just do a hatch version and then something
- 51:05like, I could build one again.
- 51:07Minor.
- 51:08There you go.
- 51:09There we go.
- 51:10It'll automatically change it.
- 51:12And that changes the code, which is great.
- 51:13So now if I do a hatch build, which is really nice, it'll create a new one.
- 51:18But if I look in my project, I've got the old one and the new one.
- 51:22And you can't republish the old one, I don't think.
- 51:24So what happens if I just say publish now and I've already got 0.1.0 out there?
- 51:29Yeah.
- 51:29So you can do hatch build dash C for a clean and it should clean it first.
- 51:35Okay.
- 51:36That's cool.
- 51:36Because then I can just say hatch publish and not worry about conflicts.
- 51:40Anything that exists already on PyPI, it will ignore us.
- 51:44It'll put a warning, but it won't fail the command.
- 51:47I think Twine by default does fail.
- 51:50I think it does as well.
- 51:52So I do the inverse because that was frustrating to me too.
- 51:55So I do the opposite.
- 51:57Yeah.
- 51:58Perfect.
- 51:59I love it.
- 51:59Okay.
- 52:00Yeah.
- 52:01That's a really cool aspect.
- 52:02And so, yeah, that was, I guess, walking through that.
- 52:07I think it was neat to just kind of explore it together.
- 52:09So thanks for talking me through that.
- 52:11Yeah.
- 52:12The past month I've been pretty busy at work, but I'm going to pick up development again next
- 52:17week for hatch.
- 52:18There's a bunch of open feature requests.
- 52:21I have to crank out.
- 52:23Yeah.
- 52:23This is a pretty popular project on GitHub with 3.7,000 stars.
- 52:27So I suspect there's some user feedback.
- 52:29Yeah.
- 52:30And so it's the main next features are the lock file plugin mechanism.
- 52:37And also people are asking about workspaces, which is basically like kind of like editable
- 52:44and stuff, but more built in and fundamental.
- 52:47So I'm going to add that especially useful for monorepos.
- 52:51Oh, right.
- 52:52Okay.
- 52:53Because you don't necessarily want to hatch build all of Google or whatever, right?
- 52:58Right.
- 52:59Right, right.
- 53:01So a workspace is like a view into the monorepo that I said, I know there's like 500 projects
- 53:06here and they all have their things, but I want the web app and the data layer.
- 53:11That's it.
- 53:12Something like that.
- 53:13Right.
- 53:13Exactly.
- 53:14Yeah.
- 53:14Okay.
- 53:14That sounds useful.
- 53:16Yeah.
- 53:16And I'm modeling it after cargo workspaces in Rust.
- 53:20I worked with that recently and I think they have pretty good config and like a model of
- 53:26how local development works.
- 53:28Okay.
- 53:29Yeah.
- 53:29That sounds really great.
- 53:30Yeah.
- 53:30I do my preview of what hatch will look like at basically cargo workspaces.
- 53:35Nice.
- 53:37Jonathan out there says, that sounds like music to his ears.
- 53:41Definitely waiting on the workspaces feature for our monorepo work.
- 53:44Nice.
- 53:45And then also Ryan is asking you, any chance there could be a package build target?
- 53:50I'm using PECs via TOCs currently.
- 53:54Yes, that's possible.
- 53:55One thing that's great about plugins is I don't have to do every feature.
- 54:00Anybody can do that.
- 54:02So we do have, if you go to the docs and go to the top, plugins.
- 54:07Plugins, where are you?
- 54:08You're home.
- 54:09Yeah.
- 54:09Plugins.
- 54:10Builder.
- 54:11Builder.
- 54:11Yeah.
- 54:11And then reference.
- 54:12Yep.
- 54:13And then, yeah.
- 54:14So known third party.
- 54:15So here's some examples of third party builder plugins.
- 54:19So the build command that you ran, it has an option to output a target.
- 54:25Okay.
- 54:26Named target.
- 54:26Other than wheel and sdst.
- 54:29So you can write an arbitrary builder and build those targets.
- 54:34So yeah.
- 54:34Okay.
- 54:35It's probably not super hard to do, I'm guessing, to just like basically bundle up the commands
- 54:40to build the PECs.
- 54:41Yeah.
- 54:41And just implement the interface and that's all I gotta do.
- 54:44Yeah.
- 54:44Excellent.
- 54:44Good to hear.
- 54:45I vote for the lock file management, the dependency management.
- 54:50I'm excited to hear that that's coming.
- 54:52Yep.
- 54:53That's coming next.
- 54:53Are you thinking of building on something like pip-tools or doing your own?
- 54:58I wouldn't feel confident doing my own without feedback from like other folks that have been in this for longer.
- 55:06Like Brett Cannon.
- 55:08I think he wrote the first lock file PEP attempt last year.
- 55:12For various reasons, it kind of got rejected.
- 55:15But I think his next attempt will happen.
- 55:18I just don't know when.
- 55:19Excellent.
- 55:20There's also a suggestion, a Cython builder would be cool.
- 55:23Maybe a mypyc.
- 55:25I don't know.
- 55:26There's a lot of options.
- 55:26That one exists actually.
- 55:27Oh, the mypyc one does?
- 55:29Okay.
- 55:29I do remember seeing.
- 55:30Yeah.
- 55:30If you go back to the plugins.
- 55:32I know the docs are a lot.
- 55:34Sorry.
- 55:34Back one.
- 55:35Build hook.
- 55:36Okay.
- 55:37And then reference.
- 55:38And it's listed under a third party.
- 55:40Hatch mypyc.
- 55:41I maintain that one actually.
- 55:43Okay.
- 55:43Nice.
- 55:44Actually, Black builds with that now.
- 55:47Nice.
- 55:47What about the Jupyter builder?
- 55:50What does that do?
- 55:51So recently, Jupyter switched their entire extension ecosystem to Hatchlang actually.
- 55:59So now the standard way to do Jupyter stuff is with Hatchlang.
- 56:04And that's the plugin that everything happens with.
- 56:07Nice.
- 56:07Okay.
- 56:07Cool.
- 56:08Probably makes you feel good to see major projects like that using your tools.
- 56:12I'm happy with people who are finding a value in it.
- 56:15And every time someone says, oh, it's so easy to use, it makes me happy.
- 56:20Yeah.
- 56:21Indeed.
- 56:21I like stuff that I can do a lot, but it's very simple.
- 56:24That's my purpose.
- 56:26Yeah.
- 56:26I think I might play with the config, the global config, to see how close I can make it match
- 56:31my current workflow and make it kind of coexist what I'm doing.
- 56:34So that'd be fun.
- 56:35Awesome.
- 56:36All right.
- 56:37Well, I think we're about out of time.
- 56:40Anything else you want to throw out there while we're talking about your project?
- 56:43If anybody wants to contribute, there's lots of open issues.
- 56:48I have had lots of really nice contributors.
- 56:51They almost finished adding type hinting everywhere.
- 56:56In the beginning, I had zero type hinting.
- 56:58And then a bunch of contributors helped out with that.
- 57:01And that was almost fully my pie.
- 57:03So.
- 57:04Cool.
- 57:05Yeah.
- 57:05I saw you had 40 contributors.
- 57:07So that's really cool.
- 57:07Yeah.
- 57:08Maybe one other quick comment that I'd like to ask you about here is I see the domain this
- 57:14is on is hatch.pypa as in Python Packaging Authority dot IO.
- 57:18Mm-hmm.
- 57:19How'd it end up on pypa dot IO versus, you know, hatch dot dev or whatever?
- 57:25This is just the standard domain for all the packages.
- 57:28So if you type in pip rather than hatch and get rid of the latest part, it'll go right
- 57:35to the pip docs.
- 57:35Right, right, right.
- 57:36Well, I was thinking more about like how did it become sort of official?
- 57:40I announced hatch 1.0, like the rewrite that happened last year sometime.
- 57:46And then the same day, maybe the next day, I forget who, but somebody in the discord was
- 57:52asking if I wanted to join the pipa.
- 57:55And I was like, well, sure, that makes sense.
- 57:58So then there was a vote on the mailing list and it was unanimous that they agreed.
- 58:03And then after I think seven or 10 days, then we transferred the repo and it was hosted
- 58:10on the new domain.
- 58:12Oh, yeah.
- 58:12And it's also under the GitHub organization of pypa.
- 58:14That's right.
- 58:15Yeah.
- 58:15Excellent.
- 58:16All right.
- 58:17Well, really nice project.
- 58:18Congrats on all the uptake and.
- 58:21Thanks.
- 58:21Yeah.
- 58:22It looks like people are enjoying it.
- 58:23So two quick questions before you get out of here.
- 58:26I didn't get to ask you this on the panel one because one, we were over time and two,
- 58:30there was a bunch of people in order just another 10 minute debate.
- 58:33Yeah.
- 58:33First of all, notable pypi package, something that you've come across.
- 58:36Oh, this is super cool.
- 58:37People should know about package X.
- 58:39Anything come to mind?
- 58:40I guess it's a bit cliche because right now it's actually pretty popular, but I would
- 58:45still evangelize textual.
- 58:47Textual is like a new application for booting T-UIs, which is like textual user interfaces.
- 58:56I've actually been doing a project at work that uses this and it's very nice.
- 59:02It's pretty awesome.
- 59:03It's kind of nuts what this thing does.
- 59:05Yeah.
- 59:06This is like the higher order UI framework built on Rich by Wilma Guggen and team.
- 59:11You get like fly out docking panels and scrolling within.
- 59:17It's crazy.
- 59:17Yeah.
- 59:17It's kind of like if the web could be in a terminal.
- 59:21Something like that.
- 59:23It's true.
- 59:24I plan to actually use this for a hatch when I have time.
- 59:27On the interactive creation of a new project, on the left-hand side, you would have inputs,
- 59:36and then it would render the pyproject.tama on the right-hand side and markdown.
- 59:41Oh, that's super cool.
- 59:41In a few months.
- 59:42Yeah.
- 59:43Fun.
- 59:43And then if you're going to work on hatch, what editor are you using these days?
- 59:48I price time for large projects.
- 59:51When I'm doing like one-off scripts, then VS Code.
- 59:55Mm-hmm.
- 59:56Okay.
- 59:56Cool.
- 59:57All right.
- 59:57This may be a question I got to start asking people.
- 59:59I don't know.
- 1:00:00PyCharm and all the JetBrains IDs, I believe, are starting to promote what they call the new UI,
- 1:00:07which I think is much more like VS Code.
- 1:00:10Are you the old school style or are you the new UI style?
- 1:00:15I've not seen that yet, actually.
- 1:00:17There's a gear in the upper right.
- 1:00:18If you click on it, it'll say new UI.
- 1:00:20To me, I'm old school.
- 1:00:21I love the old one.
- 1:00:22I mean, I'm using PyCharm, not VS Code for a reason.
- 1:00:25So I don't want it to look more like VS Code for my style, right?
- 1:00:29But I know other people prefer the opposite.
- 1:00:30I wouldn't mind using VS Code.
- 1:00:32There's one missing feature that is like a blocker where I just won't use VS Code full time,
- 1:00:38which is it can't yet do vertical tabs.
- 1:00:41There's an open feature for years.
- 1:00:44And I guess technically, there's some kind of challenge to implementing that.
- 1:00:49So right now, if you have like 100 tabs, it doesn't look very nice.
- 1:00:53It's all horizontal.
- 1:00:54It's just a bunch of Xs.
- 1:00:55Yeah.
- 1:00:57I can't select them.
- 1:00:58I just close them.
- 1:00:59Yeah.
- 1:00:59Yeah, I got it.
- 1:01:00Okay.
- 1:01:00Very cool.
- 1:01:01All right.
- 1:01:02Well, congrats with Hatch.
- 1:01:04And thanks for coming on the show.
- 1:01:06Yeah, thank you very much.
- 1:01:07Nice talking to you.
- 1:01:08Yeah, you too.
- 1:01:09Bye-bye.
- 1:01:09All right.
- 1:01:09Bye-bye.
- 1:01:11This has been another episode of Talk Python To Me.
- 1:01:14Thank you to our sponsors.
- 1:01:16Be sure to check out what they're offering.
- 1:01:17It really helps support the show.
- 1:01:19Don't miss out on the opportunity to level up your startup game with Microsoft for Startups
- 1:01:23Founders Hub.
- 1:01:23Get over six figures in benefits, including Azure credits and access to OpenAI's APIs.
- 1:01:28Apply now at talkpython.fm/founders hub.
- 1:01:31Take some stress out of your life.
- 1:01:34Get notified immediately about errors and performance issues in your web or mobile applications with
- 1:01:39Sentry.
- 1:01:40Just visit talkpython.fm/sentry and get started for free.
- 1:01:44And be sure to use the promo code talkpython, all one word.
- 1:01:48Want to level up your Python?
- 1:01:49We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:01:54Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:01:59And best of all, there's not a subscription in sight.
- 1:02:01Check it out for yourself at training.talkpython.fm.
- 1:02:04Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:02:09We should be right at the top.
- 1:02:10You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:02:15and the direct RSS feed at /rss on talkpython.fm.
- 1:02:20We're live streaming most of our recordings these days.
- 1:02:23If you want to be part of the show and have your comments featured on the air, be sure to
- 1:02:27subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:02:31This is your host, Michael Kennedy.
- 1:02:33Thanks so much for listening.
- 1:02:34I really appreciate it.
- 1:02:35Now get out there and write some Python code.
- 1:02:37We'll see you next time.