Latest / Talk Python To Me / #387: Build All the Things with Pants Build System
Transcript
- 0:00You have a larger growing Python code base? If you struggle to run builds, tests, linting,
- 0:05and other quality checks regularly or quickly, you'll want to hear what Benji Weinberger has
- 0:10to say. He's here to introduce Pants Build to us. Pants is a fast, scalable, user-friendly build
- 0:17system for code bases of all sizes. It's currently focused on Python, Go, Java, Scala, Kotlin,
- 0:23Shell, and Docker with more languages to come. So you can see on that project that even has
- 0:27multiple languages at play. This is Talk Python To Me, episode 388, recorded October 6th, 2022.
- 0:35Welcome to Talk Python To Me, a weekly podcast on Python. This is your host, Michael Kennedy.
- 0:53Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past
- 0:57episodes at talkpython.fm and follow the show on Twitter via at Talk Python. We've started
- 1:03streaming most of our episodes live on YouTube. Subscribe to our YouTube channel over at talkpython.fm
- 1:09slash YouTube to get notified about upcoming shows and be part of that episode.
- 1:13This episode is brought to you by the Local Maximum Podcast over at localmaxradio.com
- 1:20and Microsoft for Startups, Founders Hub. Get support for your startup at talkpython.fm
- 1:25slash founders hub. Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:31Do you need a great automatic speech to text API? Get human level accuracy in just a few lines of code.
- 1:36Visit talkpython.fm/assembly AI. Benji, welcome to Talk Python To Me.
- 1:42Thank you. It's great to be here.
- 1:43It's great to have you here. I'm quite excited to talk about pants and build and bringing a little bit more structure and automation to the developer workflow using this tool that you all built.
- 1:55Very happy to talk about that. Something I've been very passionate about for a long time.
- 2:00Yeah, you've been working on this quite a long time, as we will see. But before we get into all the details there, let's start with your story.
- 2:06How do you get into programming and Python?
- 2:07I love this question because I've been a software developer for 25 years or so. So I've been around for a while.
- 2:15You and me both, almost the same duration there.
- 2:17So, you know, we've seen some stuff. But I first got into computers when I was about 10 years old.
- 2:21And my uncle, who is a big gadget nut, bought a very, very early home computer. This was in the UK. So it was the Sinclair ZX80, if anyone's familiar with that.
- 2:321K of RAM, you know, 8-bit machine. It was, I had just never seen anything like it. And I was instantly smitten by it and got really into it then.
- 2:43And at some point, got my own home computer and at some point realized, oh, this is sort of a thing I want to do for the rest of my life.
- 2:50Now, granted, at that time, I also thought I would play with Legos for the rest of my life.
- 2:54So it's not like I'm always right about that. But in this case, I absolutely was.
- 2:57It's pretty awesome that we get to do that, right?
- 3:00You know, it's like, oh, this is such a neat little project. And I would just do this for fun.
- 3:04But if people pay me, I get to build even more ambitious things.
- 3:08And a lot of times those are just the thoughts and dreams of kids who don't know better, right?
- 3:13Just wait till you get in the real world. But as programmers, that's not true. Like we get to do it all the time.
- 3:18It's absolutely unbelievable that your childhood hobby can become your grown up profession if you have the right hobby.
- 3:23Yeah, exactly. It's important to pick good hobbies, kids.
- 3:26If you're out there listening and you haven't picked a hobby yet and you're not there, yeah, pick a good hobby.
- 3:30Yeah.
- 3:30You talked about the 1K of RAM and the retro thing. I just started working on this project last night.
- 3:38No, two days ago using CircuitPython. And for, what is that thing? $17, I got an ESP32 feather.
- 3:45Whoa.
- 3:46Little microchip. It has a Wi-Fi built in. It's got like a temperature sensor and all these things.
- 3:52And all you need to make it go is just plug in a USB-C. That thing is like a 240 megahertz.
- 3:58Two megs of RAM, four megs of storage, which is not much at all. But like it fits like it has two thirds of your hand.
- 4:08And it's unimaginably powerful compared to what the types of computers you're talking about, right?
- 4:12Oh, that, as I said, 1K of RAM. It had the Zilog Z80 was the processor, which I believe was clocked at about four megahertz or something.
- 4:22It was, yeah. I mean, and at the time, you know, when you're a child, a million sounds like a lot.
- 4:28So I'm sort of, what do you mean megahertz? Like I can't count to a million.
- 4:30Yeah, that's unbelievable. That's right. And here we are, well, well past the early Pentiums for $14 or $17.
- 4:37Anyway, it's just, it's really interesting to think about the different types of computers that we have to work with and where we all start.
- 4:45The other thing that I always find interesting is thinking back to early 90s, late 80s, those computers and their interfaces were so basic.
- 4:54And yet the possibility that at least I experienced when I worked with them, it seemed so great and so amazing that even stuff today doesn't come close to where you're like, I see where this is going.
- 5:03It's going to be incredible.
- 5:05There's definitely a joy. I mean, when you use the word basic, I'm assuming in lowercase, but the interface to many of them was literally the language basic all uppercase.
- 5:12Or you could just write machine code directly. And those were your only two options essentially.
- 5:18And so you were either, you know, 10 print your name, 20 go to 10, or you were messing around with registers.
- 5:27And once you learned how to do that, it was such a joy.
- 5:32You're essentially, you're melding with the hardware in some way.
- 5:35And it's, yeah, today, obviously, mostly for good, we are 19 layers removed from the hardware.
- 5:42And if you're going to be removed from the hardware, Python's a good way to do it.
- 5:45But yeah, definitely some joy has been lost and replaced with other joys.
- 5:50It's a new kind of joy.
- 5:51Now I pip install something in three lines.
- 5:53I have like a cluster of servers at my command.
- 5:55It's a different kind of joy than working with registers.
- 5:58All right, well, let's get into the main topic.
- 6:01Let's talk about pants, this project that you all have created.
- 6:04Its role, as we started, stated briefly at the beginning, is really about helping orchestrate common tasks that we have to do to build and run and prepare software.
- 6:15And it's only getting more and more complex.
- 6:17I guess Python grows up, as you sort of put it, as we were chatting before I hit record.
- 6:21As Python grows up, as it's being used on larger projects, as it's being used across larger teams, the expectations of what it means to have a piece of software and run it is changing and evolving, right?
- 6:35So maybe we could just start by talking about some of the pain points of large software, scaling software, Python in particular.
- 6:42Sure. An important piece of background here that I'm sure all the listeners will be familiar with is what has happened to Python in the last 10 to 15 years.
- 6:50I mean, I started programming in Python about 20 years ago on Python 2.2.
- 6:55It was sort of fancy bash at that point, right?
- 6:58It was just the language, the little bit of glue you used around the edges of your real code, which was written in C or whatever.
- 7:05And fast forward to today, and if you look at the process of particularly over the last 10 years, Python is this absolutely critical language that has grown up incredibly and is now being used to build large systems.
- 7:17It's being used as the language of choice for data science.
- 7:20It's being used as the language of choice for DevOps.
- 7:22It is absolutely crucial language that large, growing, scalable code bases are increasingly being built out of.
- 7:31And that's presumably everyone listening is a fan of Python as I am.
- 7:34And so there are good reasons why this is the case.
- 7:37But we're still a little behind the curve on the tooling that you need to grow a Python code base.
- 7:44The standalone Python tooling, and there are so many great tools in that toolkit, they're pretty single use.
- 7:52And they tend to be designed to assume that you have a small, single use, sort of standalone binary that's the only thing that your code base contains.
- 8:04But now increasingly, you have these large, growing code bases, sometimes referred to as monorepos, where you have a lot of Python code, possibly code in other languages as well.
- 8:15You're trying to share code across a bunch of different projects and a bunch of different binaries.
- 8:20You have a lot of, you may be deploying out of a single code base.
- 8:23You want to deploy many microservices.
- 8:25You want to deploy AWS Lambdas.
- 8:28You want to deploy many different Docker images.
- 8:31You have this complexity that you need to manage.
- 8:34And so with other languages, there have been tools around to help you deal with this problem.
- 8:41Python and for more contemporary languages, many of the solutions tend to come standard with that language's tool chain, such as, you know, Go just comes with a Swiss Army knife and Rust comes with a Swiss Army knife.
- 8:57Python does not, for better or worse, come with a Swiss Army knife.
- 9:00It comes with, you know, there are many, many blades out there.
- 9:03And particularly in its focus on Python is designed to help you grow and scale that Python code base so that all of the steps you need to take to go from authoring some code to having it be validated, tested, checked, you know, have passed all its quality control checks and be ready to be deployed or used in production.
- 9:25Rather than you manually having to figure out, well, which tools do I need to invoke in which order?
- 9:32How do I need to ensure that they are consistent?
- 9:33How do I need to ensure that they are consistent?
- 9:33How do I do the least amount of work in the least amount of time that is necessary to assure those quality checks?
- 9:41That is all a very automatable problem.
- 9:44And that's essentially what Pants is.
- 9:46It can look at your code base.
- 9:47It can look at changes to your code base and say, oh, you want to run tests?
- 9:51Here's the actual work that needs to happen.
- 9:53And here are the tools that need to be invoked.
- 9:54Sure.
- 9:55So maybe you want to run pytest.
- 9:57And as we'll learn, Pants has some great ways to speed up things like executing tests.
- 10:04Some of that's parallelism.
- 10:05Some of that's going, you know what?
- 10:07We already did that work.
- 10:08Nothing's changed.
- 10:08Carry on.
- 10:09Exactly.
- 10:10Pants is essentially the layer between either you as a developer working on your laptop or
- 10:15your CI environment and the underlying tools of which, you know, there are so many.
- 10:22And Pants, I think, supports well over 20 Python tools.
- 10:25And it's fairly easy to add more.
- 10:28So, for example, test being a very important example.
- 10:31You can say, hey, Pants, test, you know, run all the tests on everything that is affected
- 10:35by my current set of changes.
- 10:37The system can look at your code, look at the dependencies, perform all this analysis and
- 10:42say, well, that means I actually need to invoke pytest on these underlying tests.
- 10:47And if that means I need to first install pytest in a hermetic environment, I will do that.
- 10:52Pants also runs everything in these hermetic sandboxes, which means they are neither consume
- 10:59nor create side effects, which means all of this work can be cached at a very fine-grained
- 11:05level.
- 11:05You can cache the result of an individual test, apply concurrency at the level of an individual
- 11:10test.
- 11:10And so if you have eight cores on your machine, you can run eight tests at the same time and
- 11:16you only need to run the ones that have not, whose inputs have changed because everything
- 11:20else is cached potentially.
- 11:22Yeah.
- 11:22Yeah.
- 11:23So that's the test example.
- 11:25Then you could look at another really important quality control check is linting and formatting.
- 11:30There are, I don't know, eight or 10 different linters and formatters for Python and Pants can
- 11:35orchestrate them all in the right order.
- 11:37It understands the distinction between linters, which don't modify your source code so they can
- 11:42all run concurrently, and formatters which do modify your code so they have to run sequentially.
- 11:49So it's a lot of, it's this layer between you that allows you to not worry about which tools
- 11:53do I need?
- 11:53How do I install them?
- 11:55How do I isolate them?
- 11:56How do I cache their results?
- 11:57How do I reason about concurrency and what can and can't be run together?
- 12:01It just takes that away from you.
- 12:03One of the most powerful things for me personally, when I see all of this, how it brings all of
- 12:09these things together is a lot of times, well, yeah, I should probably run the linter on that,
- 12:15but it's fine.
- 12:17Maybe I should run the tests, but I didn't change that much.
- 12:21I mean, it was only a couple of lines of code.
- 12:23I don't really, you know, like there's these different steps you got to keep in mind.
- 12:27And at each level, you're like, do I need to do this?
- 12:30Or do I need to remember to do it?
- 12:32Or is it justified to disrupt what I'm thinking about?
- 12:35And if it's just, you know, pants build or pants tests, and you don't have to worry about it,
- 12:40and the system just does it all for you, you, at least personally, I am more willing to adopt
- 12:46more software engineering practices and guards on my code.
- 12:51If it doesn't feel like I have to do them, you know what I mean?
- 12:54If I don't actually have to remember like, well, I was doing five steps and that was a lot.
- 12:58Now I'm doing six and I'm really sick of these steps now, you know, if it's the same number
- 13:02of steps and it's fast enough because of the caching and parallelism, then why not adopt it?
- 13:07Exactly.
- 13:07And I think an underappreciated complication is when it's not an individual adopting it,
- 13:13but a team.
- 13:13So a team wants to assume some best practices, but now everyone on your, you want to adopt a new
- 13:18linter or a new quality control check of any kind, that's more cognitive load on behalf of,
- 13:25you know, now what do you do?
- 13:26Do you send an email to everyone on the team saying, well, now you have to run this as well.
- 13:30You can set up your existing build layer pants in this case to add, apply that new linter.
- 13:36And it just happens.
- 13:37Nobody has to change their workflow.
- 13:39What, where we want to get to is essentially, and we're in many cases, very close to this
- 13:45is you run a single command on, as a developer, you run that same single command in CI and the
- 13:52right thing just magically happens.
- 13:54And the ability to do the right thing magically depends on the ability to do dependency analysis,
- 14:00to build a fine grain workflow, to apply concurrency and caching to it.
- 14:04And as I think we'll, we'll get to maybe later, even not just concurrency and caching on your
- 14:10machine, but remote execution in a cluster and shared remote caching so that work is being
- 14:17shared.
- 14:17Not just, you know, it's not just past work that you have done, but past work that anyone
- 14:21individually or in CI has done.
- 14:24Yeah, that's fantastic.
- 14:25And if you've got a large code base, that starts to pay off.
- 14:28Yeah.
- 14:28Yeah.
- 14:28I want to talk to you about monorepos, but before we get to there, maybe you could just
- 14:33give a quick shout out about some of the language support.
- 14:37I mean, obviously we're talking about Python tools for Python code bases for Python developers
- 14:42and data scientists, but we might also live in multilingual heterogeneous environments at
- 14:48work and on our projects.
- 14:50And we might have, you know, some Kotlin for a mobile app and our Python for APIs or
- 14:55something like that.
- 14:57So yes, Pants is not a Python only tool, but it is a Python first or a Python centric tool
- 15:04in that when we, there is a long history to the project, but the current iteration of Pants,
- 15:09which we very unimaginatively called Pants V2, because we're not great at naming, it launched
- 15:16almost exactly two years ago, two years ago at the end of the month.
- 15:18And with just support for just Python.
- 15:21And since then we've added support for Go, for Java, for Scala, for Kotlin, for Shell.
- 15:27The next thing we're looking at very closely, obviously, is JavaScript and TypeScript.
- 15:32Can't ignore those.
- 15:33But one of the things that makes Pants stand out and, you know, the P in the name is no
- 15:39accident is the recognition that Python is not, is no longer this third cousin that you sort
- 15:46of put at the end of the list of languages to deal with.
- 15:48And it's sort of an afterthought.
- 15:49But really this thing is designed for Java.
- 15:51It was really part of the big driving use cases.
- 15:54But if you have many languages in your repo, or if you have no Python at all in your repo,
- 15:59Pants is still a useful tool for you.
- 16:01Because you still get the benefit of all the analysis that it does on your behalf.
- 16:05Indeed.
- 16:06And people will see that Python, Pants is written sort of top layer in Python and lower
- 16:12layer in Rust and the extensibility layers in Python.
- 16:15So there's a lot of Python first, as you say there.
- 16:18But I did want to call out, it does work on these other languages.
- 16:22So if you're trying to adopt some kind of automation that involves multiple languages, this might
- 16:27work for you.
- 16:27Yep.
- 16:28And we are always interested in people who have opinions about what the next languages
- 16:34we support should be.
- 16:35Obviously, as I said, JavaScript, TypeScript, very high on the list.
- 16:37I suspect Rust is very high on the list, partly because we use it and partly because it is a
- 16:42very up and coming and for very good reasons.
- 16:47This portion of Talk Python To Me is brought to you by the Local Maximum Podcast.
- 16:50It's an interesting and technical podcast that dives into trends in technology, stats, and more.
- 16:55But rather than tell you about it, let's hear from Max and Aaron about their show.
- 17:00We are now on with Talk Python To Me.
- 17:03Let's say hi to all the Python fans.
- 17:05Hi, Python fans.
- 17:06I'm Max Sklar.
- 17:07I have actually done a lot with Python myself.
- 17:10So I am a fan of Talk Python.
- 17:12Do you know Python, Aaron?
- 17:13I took a course years ago, but I am a little rusty.
- 17:16We are here today to talk about our podcast, The Local Maximum.
- 17:20We've been on a roll lately with a new episode every week, and I wanted to share with you what
- 17:25we've been up to.
- 17:26Here on The Local Maximum, we tackle subjects in software and technology, topics as diverse
- 17:32as the philosophy of probability to Elon Musk's next move.
- 17:36For Talk Python listeners, I want to highlight a couple of recent episodes of The Local Maximum.
- 17:40In 248, for example, I found out about an open source library that maps the world into
- 17:46hexagons.
- 17:46And some pentagons.
- 17:47I had a discussion with an author about games and puzzles and another on a novel approach
- 17:52to doing the job search well.
- 17:53We discussed the ramifications of AI-generated art.
- 17:56Have we reached peak creativity, or is this just another Local Maximum?
- 18:00All developer tools kind of come of age when they can make themselves.
- 18:12They're now fully independent where a language or a tool builds its own self with its own
- 18:18features.
- 18:19So yeah, if you could do that for Rust, then it can kind of be a part of that group.
- 18:25Yep.
- 18:25Self-hosting is a major milestone in any sort of build type project.
- 18:30Indeed.
- 18:31All right.
- 18:31Quick question from the audience.
- 18:32Mustafa out there says, how does Pants handle bulk publishing of packages where I might have
- 18:36a set of preconditions to auto-publish it?
- 18:39Intervals of all package that meet those conditions or something along those lines.
- 18:43Great question.
- 18:43So Pants, as I should mention, there are many different types of deployable that it can build.
- 18:48I mentioned like AWS Lambda or Google Cloud Functions, or we have a format that's specifically
- 18:55of interest to Python users called PEX, which stands for Python Executable.
- 18:59And it's basically a single file that contains your Python code and all of its transitive dependencies.
- 19:06So it is ready to run as long as there's an Python interpreter on the system you run it on.
- 19:11And it even knows how to find that interpreter.
- 19:13Interesting.
- 19:13PEX came from you guys.
- 19:15Yes.
- 19:16Oh, I had no idea.
- 19:17I mean, I've heard of PEX, but I didn't associate it with Pants.
- 19:20That's cool.
- 19:20Yeah.
- 19:20I mean, other systems can also build PEX, and PEX has a standalone command line tool that
- 19:25you can use to build PEXs.
- 19:26But Pants is the home base of PEX.
- 19:29But I think the question was about building and publishing Python distributions, for example,
- 19:36to PyPI, which Pants can obviously do.
- 19:40And I'm not 100% sure I'm answering the question appropriately.
- 19:43But I think one of the ways that Pants can help you here is it knows when code has changed.
- 19:50So if you're publishing a large number of packages from your repo, it can do the math of, you know,
- 19:56here are the, by tracking dependencies, it can do the math to say, based on the changes,
- 20:01since the last time this thing was published, it now has changed and needs to be republished.
- 20:07So it can give you a lot of that logic.
- 20:09When it comes to auto-publishing at intervals, I guess I would say Pants can tell you whether
- 20:15it meets the conditions based on dependency analysis, etc.
- 20:19There is no auto-publishing per se.
- 20:22Pants is a tool you have to invoke.
- 20:24So you could cron around it or something like that.
- 20:27Yeah.
- 20:28Cool.
- 20:28You mentioned monorepos.
- 20:30Now, you also mentioned sharing code.
- 20:33If I've got, say, some SQL model definitions that point at what my database looks like, well,
- 20:41my API code probably needs access to the right version of those.
- 20:46But so do my data scientists for their library that talks using SQL model to get the data into their notebooks.
- 20:53And if those things get out of sync, as we know, SQLAlchemy will go bonkers and say,
- 20:59you're missing a column here.
- 21:01Done.
- 21:01Crash, right?
- 21:03And so keeping that stuff in sync across these different projects can be challenging.
- 21:07Is that the idea behind these monorepos?
- 21:10Yes.
- 21:10That's one of the reasons why they are increasing in popularity.
- 21:16So the problem is, as your codebase grows, when your codebase is small, there are no problems.
- 21:20And as your codebase grows, you're faced with kind of two, you're faced with a decision on how to manage that.
- 21:26One is to keep breaking it up into multiple smaller repos, essentially, each one with their own build and their own practices.
- 21:33And the way you consume code across them is through publishing, through version publishing.
- 21:38Maybe you make your SQL models a data package and you publish it to an internal PyPI and everyone consumes it and they pin their
- 21:45versions just like...
- 21:46Exactly.
- 21:47So the problem with that is that there are several problems with it, but a big one is that you're inviting the famous dependency hell problem,
- 21:54which is already bad enough with third-party requirements, into your first-party code.
- 21:59So the problem is, when you make changes to a library, you have no way of knowing who is consuming you upstream from you and therefore what changes they might need.
- 22:09Now, you might say, well, not my problem because everything is supposed to be versioned,
- 22:13but that breaks as soon as anyone needs to upgrade anything because now they have this horrific upgrade problem that is happening potentially weeks or months after the changes that are breaking them have happened.
- 22:25So you're kind of pushing the problem off.
- 22:28Where a monorepo is helpful is that you get this visibility into all of the upstream dependencies.
- 22:36Essentially, if all the tests in the monorepo pass, you know that your changes have not broken your coworkers.
- 22:42You know that you can use in-repo tools like GitGrep to find or any kind of discovery tools and dependency analysis that tools like Pat's offer within the repo to find out the impact of your changes.
- 22:56And this is why monorepos are increasingly popular.
- 23:00And, you know, it's not to say that because a bunch of other companies are doing it, you should be doing it.
- 23:04But it is instructive to note that Google and Facebook and Twitter and a lot of successful companies have gone in that direction or in Google's case started out in that direction.
- 23:15Right.
- 23:16It has to be said that with monorepos or without, you need appropriate tooling.
- 23:21So at some point you have to pick your poison.
- 23:23But the reason I am biased towards monorepos, having worked at companies that have had one unified code base and companies that have had a very fragmented code base, is that the structure of your code base tends to recapitulate the cohesion and structure of your organization itself.
- 23:39And if everybody is collaborating on a single large repo within reason, you don't necessarily need to have literally one repo for the entire company, but a small number of large repos with boundaries between them that makes sense because they don't mutually depend on each other, let's say.
- 23:55Then that mutuality and that sharing of code creates more cohesion at the organizational level.
- 24:02And when you have a very fragmented code base, you tend to have a fragmented organization.
- 24:06Now your organization resembles, you know, a loose collection of warring tribes more than a single unified organization.
- 24:14So I am biased towards monorepos.
- 24:17And while you can use pants very effectively in even, you know, multiple smaller repos, I do think it supports the monorepo architecture really well.
- 24:26And the last thing I would say about this is just to really clarify, because we get a lot of questions about this.
- 24:30Monorepo is about your repo architecture, nothing to do with your deployment architecture.
- 24:35So it is not the opposite of microservices.
- 24:38For example, if you have many microservices, you probably want them to be in a single repo because they share, as you said, data models, they share code.
- 24:46And it is actually easier to deploy many microservices out of a single repo than constantly creating new teeny repos and having to go through the whole publish and consume dance every time you want to publish a microservice.
- 25:00And so publishing many microservices out of a single monolithic repo is actually a common pattern and a very effective one, in my opinion.
- 25:08Yeah, I guess if you have a monolith where the code is architectured into one giant thing, it necessarily means that you're probably just going to have it in one repo.
- 25:18But if it's microservices, there may be this temptation to have, well, we've got 10 microservices.
- 25:23So we've got 20 repos because here's each one for the service and then the shared bits got to be broken out into their own so they can be reused.
- 25:30Yes.
- 25:30Just essentially, you get a much, in a monorepo, you get a much tighter development loop because you are cutting out all of the publishing.
- 25:37Everything is consuming.
- 25:38All the inner code-based consumption is happening at head.
- 25:41So you don't have this constant publishing and consuming.
- 25:45Yeah.
- 25:45Yeah, I hadn't really thought about it that way.
- 25:47But a lot of the tools, the really good tools that we have, things like PyCharm and stuff, we can open them up and go to a function or a variable or a class and right-click and say, show me all the uses of this.
- 25:58But if there's a bunch of different consumers of your library, well, you don't really know because anybody could be grabbing something and using it.
- 26:05But if it's a monorepo and it says no usage is found, well, that means more.
- 26:09Exactly.
- 26:09The consumption metadata on published artifacts goes the wrong way, right?
- 26:15It says, the metadata that gets published with the wheel says, here is what this wheel consumes, but it has no idea who consumes it.
- 26:22And so if you want to figure that out, now you need a whole bunch of tooling.
- 26:25So why not just cut that out entirely?
- 26:28Yeah, and you get things like refactor, rename, or to cross the whole company sort of in interesting ways as well.
- 26:35Okay, cool.
- 26:36Maybe we should touch a little bit on the history of pants.
- 26:40There's, I know pants 1.0 has been around for a long time, and then there's this 2.0 version.
- 26:47You want to tell people a bit about the changes there?
- 26:49They maybe have experienced it a while ago.
- 26:52Sure thing.
- 26:52So pants, what we now refer to as pants v1, was a project that started as an internal project at Twitter,
- 26:59and it was focused primarily on Scala and how can we speed up Scala builds and make them more organized and more tractable.
- 27:07It then got open sourced out of Twitter and was used at a handful of other Scala-using companies, notably Foursquare.
- 27:15Square used it as well.
- 27:17There were a few companies of that vintage of early 2010s, Silicon Valley startups that were using Scala in a big way.
- 27:24So, in fact, v1 is basically gone at this point.
- 27:27I think there's a handful of organizations still maybe using it.
- 27:30We're desperately trying to get them onto v2.
- 27:32The pants v2 is a thing that we launched two years ago.
- 27:36There's a complete ground-up re-implementation.
- 27:40It really only shares a name with the old one and sort of project home with the old one.
- 27:47The code is entirely new.
- 27:48As you alluded to earlier, one of the big differences in the implementation is that the execution engine in v2 is written in Rust,
- 27:56and the APIs are async Python 3.
- 28:00But that is an important difference.
- 28:02But the bigger difference is the design itself is very different in that the v2 system learned a lot from our experience with v1,
- 28:11both in terms of the implementation and how to make important features like caching and concurrency just fall out of the design
- 28:21rather than be this laborious thing you have to add at every corner.
- 28:26And also, an equally important lesson was, unlike many other systems, including PANS v1,
- 28:31which came out of a single company and were really tailored for that company's use cases,
- 28:36with v2, we wanted to build something that was for everyone,
- 28:38that any organization, large or small, could use and get.
- 28:42You shouldn't have to work at Microsoft or Google or Twitter to get this quality of build experience.
- 28:48Anyone should be able to.
- 28:49And that required looking at the use cases of a lot of organizations of different languages and different sizes.
- 28:55And one thing we learned was nobody wants to write a ton of build metadata.
- 28:59If anyone's used a system like PANS v1 or Bazel or Buck or something similar,
- 29:03you start by potentially refactoring your code base to be what the system expects.
- 29:09And then you write thousands and thousands of lines of what so-called build files.
- 29:13We wanted to eliminate all of that.
- 29:16And so the system is designed to accept your code base as it is.
- 29:19And it doesn't require huge amounts of build metadata.
- 29:22It requires small amounts that it can mostly generate.
- 29:25But the important information, which is the dependencies,
- 29:28it actually infers at runtime by looking at import statements and various other tricks and heuristics
- 29:35for figuring out what your code's actual dependencies are.
- 29:38So that saves a huge amount of time and makes it a lot easier to use and a lot easier to adopt.
- 29:43So that's kind of why v2 came about.
- 29:45We wanted to build something that wasn't like,
- 29:47here's something we built for Twitter, throw it over the wall and you can use it if you want to.
- 29:51But here's a thing that was designed for you, designed for Python, designed to be easy to adopt,
- 29:56designed to be easy to use, designed to be easy to extend,
- 29:58has a robust API that is async Python 3 essentially.
- 30:03And that's where that project came from.
- 30:05Yeah, it's really interesting how it came from kind of this big tech side of things.
- 30:10But second take, it's like, well, how do we just make this for all the projects, not just the large ones?
- 30:15There's that, there was an interesting article and it's, you know, quoted in various forms a lot.
- 30:20Like, you're not Facebook, you're not Google, you're not LinkedIn.
- 30:23Speaking to most people, right?
- 30:25I mean, there are people who actually are there, but like for most people who look at these architectures
- 30:30and what's happening, they may, oh, look how they're scaling this.
- 30:33And like, yeah, but you just have a hundred users.
- 30:35You don't need to like go to that much architecture and crazy designs for, you know, what you're doing.
- 30:40And so it's, I can see how it would be a temptation to have like an overly complicated system that comes along.
- 30:48But it looks to me like this is really easy to adopt.
- 30:50It is significantly easier and we are constantly working on automating the adoption.
- 30:55There is a, one of the commands in Pants is, this is the only Pants related pun we've allowed ourselves in the system is called tailor because it quote unquote tailors your metadata.
- 31:05It essentially generates, it does inspection of your code and generates a bunch of metadata, not including dependencies.
- 31:12Those, as I mentioned, are inferred at runtime, but this is kind of a thing you run periodically because this is metadata that you may want to manually tweak.
- 31:21And so we're constantly working on making that easier and easier to adopt for real world cases.
- 31:27So just one obvious example is many repos have dependency tangles and circular dependencies and Pants v2 can handle that.
- 31:35Those other systems cannot, including Pants v1.
- 31:38And those other systems were not really designed for easy adoption because they didn't need to be, because they were only designed to be adopted once by a captive audience of all the developers at that company.
- 31:48We want this to be adopted thousands of times by thousands of organizations.
- 31:53So we want it to be much, much easier.
- 31:55This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 32:02Starting a business is hard.
- 32:04By some estimates, over 90% of startups will go out of business in just their first year.
- 32:09With that in mind, Microsoft for Startups set out to understand what startups need to be successful and to create a digital platform to help them overcome those challenges.
- 32:18Microsoft for Startups Founders Hub was born.
- 32:21Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
- 32:27The platform provides technology benefits, access to expert guidance and skilled resources, mentorship and networking connections, and much more.
- 32:36Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be investor-backed or third-party validated to participate.
- 32:46Founders Hub is truly open to all.
- 32:48So what do you get if you join them?
- 32:50You speed up your development with free access to GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.
- 32:58To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI, a global leader in AI research and development, to provide exclusive benefits and discounts.
- 33:08Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
- 33:14You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation, fundraising, management and coaching, sales and marketing, as well as specific technical stress points.
- 33:27You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
- 33:32Make your idea a reality today with the critical support you'll get from Founders Hub.
- 33:37To join the program, just visit talkpython.fm/founders hub, all one word, no links in your show notes.
- 33:43Thank you to Microsoft for supporting the show.
- 33:46You talked about some of the tools that you could use.
- 33:51Maybe we could go through that list of common tools real quickly and you could just give us your thoughts on why you think it's great and maybe why you might want to adopt it and make it part of your flow.
- 34:00Because with Pants, you don't have to add more steps, as we said.
- 34:04So some of the tools you've called out are mypy.
- 34:06I know you're a fan of Python 3 and Pype annotations.
- 34:10Tell people quick about mypy.
- 34:12So for those who aren't familiar, mypy brings a level of rigor to your Python quality control that is fantastic.
- 34:19Essentially, you add type annotations to your Python 3 code and mypy performs static type checking and is absolutely tremendous.
- 34:29You know, it is essentially a sort of compilation step for Python.
- 34:33Right.
- 34:33It's not actually generating code, but it is performing type checks that finds a wide variety of bugs and issues.
- 34:40And I would never go back to non-type checked Python.
- 34:43Interesting.
- 34:44Yeah.
- 34:44So it's like, if I were to compile it, what would happen?
- 34:47We're not actually going to, but let's go through that and give you a report, like sort of print out the warnings and errors that you would have seen in a compiled language.
- 34:54And then we'll carry on.
- 34:57You know, a common way these things are referred to in Python is type hints, which kind of implies they have no effect.
- 35:03But with mypy, it's a little bit closer, right?
- 35:06Right.
- 35:06So they have no runtime effect, it is true, but they have the type annotations.
- 35:11Well, they can if you, in certain circumstances, pants itself uses its own code type annotations at runtime in an interesting way.
- 35:21But generally, running mypy just is an extremely effective quality control check in your code.
- 35:28But getting set up with mypy can be complicated.
- 35:31And with pants, you just pants check all my code or pants check all my code that has changed since my last, you know, since my last edits.
- 35:41And it will install mypy and it will set it up and it will run it.
- 35:46First time you do that, you'll get many, many errors, I'm sure.
- 35:49I'm sure.
- 35:50I'm sure you will.
- 35:51Another one you've given a shout out to is Protobuf for protocol buffers.
- 35:56I don't know that I've spoken very much about those at all on the show.
- 35:59I mean, people know REST and JSON.
- 36:02They may have scars from SOAP and XML.
- 36:06I'm not sure how many people are doing it.
- 36:07It depends on how long they've been doing this kind of stuff.
- 36:10But what's Protobuf?
- 36:12I just had XML PTSD for a second there.
- 36:14Yeah, I'm sorry.
- 36:15I'll send a therapist your way after the show.
- 36:18So Protobuf is a really fabulous tool out of Google that generates code in many languages from a .proto file,
- 36:30which is a language neutral interface definition language.
- 36:34And that works well with gRPC, which is the Google RPC language,
- 36:39where it actually generates RPC code and stubs so that you can use protocol buffers.
- 36:47These over-the-wire protocols is referred to as protocol buffers.
- 36:51And you can just use them as this binary interchange format that is very efficient over the wire.
- 36:57So exchanging binary data, if you say, here's four bytes, that's the account.
- 37:03And then here's the length of the string is the next four bytes.
- 37:06And then doing that manually is super tricky.
- 37:10And so protocol buffers is a formalization of that.
- 37:13And then this tool would maybe write the Python code that understands a particular exchange.
- 37:18Okay.
- 37:18So PaaS knows how to do code generation in general.
- 37:21It supports many code generators, including Thrift, which is a sort of similar in spirit to Protobuf.
- 37:27But Protobuf is a very prominent one.
- 37:29And the idea is that it will generate this Python code out of, you have this very succinct interface definition,
- 37:35and it generates fairly elaborate Python code that can serialize and deserialize these messages
- 37:41and send them via RPC interfaces and send and receive them via RPC interfaces over the wire,
- 37:46where the thing on the other side of that RPC interface might not be Python at all.
- 37:50But they're all talking the same IDL.
- 37:52And yeah, protos are very efficient binary formats.
- 37:56So they use things like variable length integer encoding.
- 37:59So the same message will be significantly more compact in Protobuf as it will be in JSON.
- 38:06That said, in probably many, many cases, JSON is absolutely fine, right?
- 38:10Exactly. There's a ton of value to be like, I can point my web browser or postman or something at that and see the answer.
- 38:18Yes.
- 38:19Right? Like, that goes a long ways.
- 38:21But if you're exchanging really low latency, lots of data as fast as you can, then, you know, JSON is probably not it.
- 38:28Certainly XML with namespaces and XSLT is definitely not the right thing.
- 38:33So this sounds like a cool, more modern way to do it.
- 38:37Some other tools. We've already talked about pytest. People know what pytest is.
- 38:41Black formatting, right? Auto formatting a code.
- 38:44So is that much?
- 38:45Stop the indentation arguments.
- 38:47Yes.
- 38:47Oh my God.
- 38:48When we adopted black in the pants repo, everybody, myself included, got upset for about 10 minutes and then realized that far more important than which format is that there is format that is enforced automatically.
- 39:00I personally used to at least prefer two space indents to four space indents. Black is the reason it's called black.
- 39:06For those who don't know, is that famous, you can have any color you want as long as it's black.
- 39:10I think that was Henry Ford.
- 39:11I think so. Model T.
- 39:13So basically, it's a very opinionated formatter that just says this is what Python code should look like.
- 39:18And you know what? I embrace robot overlords in this case.
- 39:22Yeah.
- 39:23It's absolutely wonderful. I can just do pants format and it just formats all the code.
- 39:28That is the, there are no more arguments. Like the true formatting is whatever black outputs.
- 39:32And pants, again, makes it very easy to adopt black.
- 39:35It also makes it easy, I should mention, for linters, for formatters, even for mypy, pants has affordances in it to help you adopt them incrementally, which you kind of have to do.
- 39:44If you have an existing code base, you may want to adopt, you know, it takes time to, so black is very aggressive, but there are many other linters that pants can run.
- 39:53And a doc formatter and flake eight and pilot and bandit and so on.
- 39:57And I sort, and you may want to adopt them incrementally and pants has ways to help you do that.
- 40:03And certainly with mypy, because it relies on upstream.
- 40:07mypy, you kind of have to adopt independency order because it relies on upstream type annotations.
- 40:12And so there are ways to do that.
- 40:14Right. To get the most out of it, you've got to have the, we call these three functions.
- 40:18Well, those three functions have to have type information and be valid.
- 40:22And I got to start at the foundation with those.
- 40:23Bandit's interesting.
- 40:25I don't know how many people run Bandit.
- 40:27Probably people who accept user input probably should or input from the internet.
- 40:33Tell people about Bandit.
- 40:34I'm not super familiar.
- 40:35I'm no expert on Bandit, but it's just about security checks.
- 40:39So it will automatically find common security issues in your code.
- 40:43And again, Pants makes it very easy to adopt it.
- 40:46You essentially just enable the Bandit plugin.
- 40:48Pants, I should imagine, has this plugin architecture where you can opt in to whichever sort of bits of functionality you want.
- 40:55So you enable the Bandit plugin.
- 40:56And that's kind of it.
- 40:58And the next time you run Lint, it will run the Bandit checks.
- 41:01And it will yell at you about all the security issues that's found in your code.
- 41:04That's cool.
- 41:05So you have these different categories.
- 41:06Like you have a test category, a Lint category, and so on.
- 41:09And then in your configuration, you can say, when I say Lint, I mean these three things.
- 41:14Correct.
- 41:15So what you refer to as a category in the sort of Pants jargon is referred to as a goal.
- 41:20So it's basically what you type on the command line.
- 41:22You type Pants test means run test.
- 41:25Pants Lint means run all the Linters.
- 41:27But what all the Linters means depends on your configuration.
- 41:30Sure.
- 41:31That makes a lot of sense.
- 41:32Maybe one more.
- 41:33I know the list is kind of unbounded in a sense.
- 41:36But AWS Lambda or sort of functions, serverless functions in general.
- 41:42There's probably other ones.
- 41:43You could probably do Azure functions and other things as well.
- 41:46The two we support at the moment are Google Cloud Functions and AWS Lambdas.
- 41:50Yes.
- 41:50So Pants knows how to take your Python code and package it into a Lambda function that you can
- 41:56deploy to AWS or a Cloud Function you can deploy to GCP.
- 42:00The management of that kind of stuff is super picky because you might have 20 functions coming
- 42:04out of all these different pieces of code.
- 42:06Did you forget to push that to that particular function point?
- 42:09That's really hard to do to keep that straight.
- 42:11If you're using serverless, if you're using Cloud Functions, you probably have many of them.
- 42:16And a tool that can tell you which ones need to be redeployed based on changes, because it's
- 42:22very simple with Pants to say which Cloud Functions have been affected by any transitive change since
- 42:29this tag, since this deployment tag.
- 42:31And it will tell you, it'll just give you a list and you can just repackage them and redeploy
- 42:35them.
- 42:36Without having to repackage and redeploy everything every single time.
- 42:39Awesome.
- 42:40Yeah, that sounds incredibly helpful if you're using them.
- 42:42So the reason I wanted to go through that list here is like if adopting those tools and those
- 42:47features sounds interesting, the more you adopt, the more the tools like Pants can help lower
- 42:54the burden and just make that automatic, right?
- 42:56Exactly.
- 42:57It generally just takes away the pain of how do I adopt this tool?
- 43:00How do I run it?
- 43:01How do I configure it?
- 43:03How do I make sure that everyone in my team is on the same page about how to use these things?
- 43:07It just automates away all of that.
- 43:10It also supports things like you can run a Python REPL that contains all the dependencies of the bit of code you're interested in.
- 43:18It can do, because it has this fine-grained dependency analysis, it can know that even if you have like a big requirements.txt file, it knows which sub parts of that requirements.txt and their transitive dependencies are relevant to every given binary.
- 43:34So now you're not managing many different sets of requirements for each of your, let's say, Cloud Functions or each of your Docker images.
- 43:41That's all happening automatically for you.
- 43:43Nice.
- 43:43Let's talk about running these tasks and caching, performance, parallelization, and so on.
- 43:50So one thing it has here right on the pantsbuild.org page, and you've hinted at this a few times, is that it speaks Git.
- 44:00And so it has this way of understanding changes.
- 44:03Yes.
- 44:04So built into it is the ability to say, like things like when you want to run tests, you can say run all the tests.
- 44:12You can say run all the tests in this directory.
- 44:13You can say run all the tests, run this specific test.
- 44:16You can say run all the tests that have this tag, this like a tagging mechanism sort of where you can label things.
- 44:22Or you can say run all the tests that are affected by changes since this other Git state.
- 44:30So you can say, you know, as you're working on your laptop, you can say, all right, run the tests that could possibly be affected based on my changes since the main branch.
- 44:40It will internally use Git tooling to figure out what that means.
- 44:45So it'll say, OK, which files have you changed and which things are downstream from those changes.
- 44:50When you say affected by, how is that determined?
- 44:54Does that mean I saw there's some Python code that my, here's my test and my test is importing this and these import those?
- 45:00Or does it do like code coverage?
- 45:03What does it base its opinion on of what's changed?
- 45:07It based its opinions on its view of your code's dependencies.
- 45:11Now, almost all of that view comes from analysis of import statements.
- 45:16Occasionally, you may have to override those.
- 45:18So, for example, if you're using Django, we have good support for Django, but Django notoriously does a huge amount of dynamic loading based on strings in settings.py.
- 45:27Right, right, right.
- 45:28Occasionally, sometimes pants can actually look at those strings and figure it out.
- 45:31It has a mode where you can tell it that if it sees strings in a file that look like module names to assume that those are like imports.
- 45:38But sometimes that doesn't work.
- 45:39And so you can manually override the dependency inference and you can say, actually, here's a dependency that's important and you failed to infer it.
- 45:49Or the opposite, you can exclude a dependency that pants mistakenly inferred.
- 45:53But that's extremely rare.
- 45:55So it bases that on its automatic static analysis of your dependencies.
- 46:00Cool.
- 46:00So one of the things that might be important when you're running these steps is, for example, the protobuf thing.
- 46:08Right.
- 46:09Its step has an output and maybe that output is consumed by some other, maybe by the tests or maybe the tests load up the Python file that was generated by that to go talk to some binary blob and see if it understands it.
- 46:21It's really important those run in order, right?
- 46:23Yes.
- 46:23So from your dependencies plus its understanding of which jobs need which inputs, needs to consume which inputs and which jobs produce those inputs as their outputs, it constructs this very fine-grained workflow graph.
- 46:38And that is exactly where the caching and the concurrency comes from.
- 46:41So every node in this graph, and it could be thousands even, every very fine-grained node in this workflow graph knows exactly which inputs it needs.
- 46:49And the work is done in the right sequence.
- 46:53So if you have two pieces of work that neither of which depend on each other, right, in the DAG sense, they are independent, they can run concurrently, and they will.
- 47:01So presumably, if you have multiple cores on your machine, they literally will run, they could run in parallel at the same time.
- 47:06But obviously, if a little work unit needs the output of some other work unit to be its input, then it will wait for those.
- 47:14And how all that is strung together is using all of the work as described.
- 47:20As I mentioned, the API for this is Python 3, is async Python 3.
- 47:23And so you have these things called rules, which are these async coroutines.
- 47:30And the Rust engine strings together executions of these rules based on data dependencies.
- 47:36And the data dependencies use type annotations, use just regular Python 3 type annotations, to say, to describe the types of the inputs and outputs.
- 47:46And so the engine can say, ah, you, this rule needs to consume an output of this type.
- 47:52I have found a rule that produces an output of that type based on some other input that I already have.
- 47:58So I will string them together.
- 47:59And it will do that recursively until it ends up at sort of the initial data, which obviously it has.
- 48:06Right.
- 48:06We'll start here, go down this path in that order.
- 48:09Some of them, though, can be parallel, right?
- 48:11Like Bandit and PyFlake.
- 48:13Those just, mypy, all those just look at the code and say, looks good or doesn't look good.
- 48:19And here's your warning message, right?
- 48:20And so you can, does it by default or just optionally parallelize that?
- 48:25No, it will happen by default.
- 48:27It will always, I mean, you can control the amount of concurrency.
- 48:30Let's say you're running multiple things on the machine and you don't want it to consume all your cores.
- 48:34You can tune that down.
- 48:36But just normally by default, it will use as much concurrency as the graph allows.
- 48:41So every one of those small work units is candid for being executed concurrently with other ones.
- 48:49But it is also, and this is really important, a candidate for being cached.
- 48:52So many, many intermediate steps can be cached.
- 48:56In a typical iterative run when you're iterating on your laptop and you're developing and you make some changes and you run some tests and you make some changes and you run the tests again.
- 49:05So much work that normally would be repeated will not be repeated by pants because it will be, the outputs will be pulled from cache.
- 49:12Yeah, that's fantastic.
- 49:13Because every one of those nodes has its, it runs, as I said, with no side effects.
- 49:17It runs in a sandbox with no side effects and its inputs and outputs are statically defined.
- 49:23So it can be correctly cached every time.
- 49:27So you don't, you as an author of a plugin, for example, don't have to think about caching or concurrency.
- 49:32You just write to the API and caching or concurrency fall out of the design.
- 49:36That's really neat.
- 49:37And I can imagine on a large code basis, things like Bandit and mypy, all those analysis tools, they can take a while.
- 49:44And if you just change one file, and especially if you're in the monorepo business, where it's not just for your website, but there's a ton of stuff, you don't want to rerun all those things.
- 49:55So it could really get a lot faster.
- 49:56You can get a lot of speed increases that way.
- 49:59Yes.
- 49:59Yeah.
- 49:59One of the hesitations to adopt tools like this is it keeps rerunning from scratch over and over, and that makes it slow.
- 50:06The other one is while you may run it, your teammates may have a less buy-in on some of these linting, formatting, testing ideas.
- 50:18And if you just do that in CI, well, when you check it in, it works.
- 50:22Someone else gets their code.
- 50:24You merge theirs.
- 50:24You check it in again.
- 50:25And it breaks the build.
- 50:27And it can be super frustrating.
- 50:28Is there a way, like a pre-commit hook or some other mechanism to encourage these to be run by everyone?
- 50:36You certainly can have a-
- 50:37Or is that a personnel problem?
- 50:39That really depends on the organization.
- 50:41We tend to see adoption of pants at the team level.
- 50:45Usually what happens is someone who is someone at the team who is just fed up with a not great status quo drives adoption of it.
- 50:53And other team members see, there's obviously initial skepticism because there always is whenever you try to introduce new tooling.
- 51:00I'm as guilty of this as anyone.
- 51:02But then there's that aha moment of, oh, things got more rigorous and faster.
- 51:06That is a trade-off I will gladly take.
- 51:09Yeah.
- 51:09So very often if CI runs pants, and that is therefore in some sense the definition of correct quality control checks, because whether it's testing, linting, packaging, etc.
- 51:24Because you can't merge until you pass CI, there's strong incentive there for you to use the same thing that CI is doing on your laptop.
- 51:33Because if you get that to pass on your laptop, it is overwhelmingly more likely to pass in CI, which just gets you to merge faster.
- 51:40Yeah, I guess it depends a little bit on how you work as a team and source control, right?
- 51:44If everyone can just commit to main, it's much harder to have that.
- 51:49But if you've got to go through kind of a get flow, like you work on your branch and then you merge it into main when it's approved and CI passes, well, then all of a sudden, if CI is not passing, you're not merging.
- 51:58And yeah, then it trickles back until it gets fixed.
- 52:02I think this is a big part of Python, quote unquote, growing up as a language like now, again, it's not fancy shell scripts, it is a workhorse language that people are building massive businesses and systems and data science capabilities out of.
- 52:18And you need to, you know, that comes with responsibility to be rigorous about quality control.
- 52:26And essentially, you know, having really good CI, having really good iterative development practices is something that is really important for these growing repos.
- 52:35And it's why pants exists.
- 52:37It is to make that much, much easier and much, much faster than it would otherwise be.
- 52:42If you are sort of not running tests, not really running any checks, pushing directly to main, you know, because, you know, historically, Python repos were these tiny toy things that you could do that in.
- 52:53You know, you're asking for trouble sooner or later.
- 52:57So I'm asking you, how do I get this tool that applies all these, automates all of these engineering best practices?
- 53:03And you're suggesting that maybe you start by, start at the core and work your way out, right?
- 53:10Like, like just the way that you work together as a team through source control, like you formalize that a little bit, then everything else becomes easy.
- 53:16I think so.
- 53:17I mean, having CI that is the, you need some way of saying what is correct.
- 53:22You need some way of saying, if this CI is green, that means you can merge this change.
- 53:27If this CI is green, it means that you can deploy to production.
- 53:30You need some way, automated way of saying this code is good.
- 53:33Pants makes it very easy to build that ability.
- 53:38And once you have that, you never want to go back.
- 53:42There is a hurdle you have to, you know, it's less convenient than not doing any quality control, but you sort of have to.
- 53:49Well, it's less convenient up front.
- 53:51It's less convenient up front.
- 53:52It's easier to just not worry about it.
- 53:54But you.
- 53:55It is.
- 53:55But as soon as you spend the whole weekend trying to figure out why the thing doesn't work and you're supposed to release it and it turns out it was somebody else's problem and they didn't test.
- 54:03And then like, then all of a sudden that, that little bit of work up front didn't seem so big.
- 54:07Nobody goes backwards, right?
- 54:09Nobody goes in the direction of fewer quality control checks.
- 54:12There is a point in the evolution of your repo where you start adopting them and you just adopt more and more of them.
- 54:18And right.
- 54:19You don't go.
- 54:19It's a rat.
- 54:20It's a one way ratchet, basically.
- 54:21And with good reason.
- 54:22In my mind, all these conversations I've been having, I've been around like teams, I guess, maybe seated by the idea of you talking about it coming from places like Twitter and so on.
- 54:32What is the pants story for open source repos?
- 54:36Like if I was in charge of HTTPX, I'm not.
- 54:39But if I were, what does pants offer me?
- 54:41So we do, we're starting to see open source repos adopt pants now, tends to be the larger ones where things like how can I speed up tests become a question even in that regard.
- 54:53One thing that we haven't talked about really is security and sort of protecting your own software supply chain, especially if you're an open source project where you are typically part of other people's software supply chain.
- 55:05So one of the features of pants is it has very strong support for lock files where a universal lock files that are valued across platforms that lock down.
- 55:16Essentially, you generate a lock file that contains pins every single transitive dependency, including these SHA-256s of all of the wheel files.
- 55:26And pants then knows how to very efficiently build virtual environments out of the subset of those that is actually necessary in any given situation.
- 55:36So if a test only needs some small subset, it will only use those.
- 55:39The advantage being that that test gets invalidated a lot less when, because it doesn't get invalid, the results don't get invalidated if an unrelated requirement, upstream requirement changes.
- 55:51So even for smaller repos or for, you know, open source repos, apart from all the other benefits, one benefit that I think is worth looking at is lock files and just locking down your supply chain.
- 56:02It means you don't have like the left pad issue, things like that.
- 56:06You are much more robust to your build is much less impacted by changes on PyPI, by changes in the world at large.
- 56:14Yeah, in the homepage, it says it has out of the box support for multiple dependency resolvers in addition to these lock files, right?
- 56:23So is this like your own private PyPI server that you can limit what goes in there?
- 56:29What does that mean?
- 56:29Well, you can.
- 56:30I think what that was referring to was that you can have multiple of these lock files.
- 56:34So you have a large code base.
- 56:36You might have different parts of it that genuinely need conflicting dependencies.
- 56:41But you can sort of say, OK, here are like two or three lock files that you are allowed to, you know, you have to pick one for a piece of code or a piece of code can be compatible with multiple, but you have to pick one when you come to build a binary or something like that.
- 56:54So, for example, it's pretty common to have, you know, here is a lock file that is for my web application code.
- 57:00And here's a different lock file for my data science code, because there are just conflicts between them that can't be resolved.
- 57:06There may be no reason to install JupyterLab on your FastAPI server, right?
- 57:12Well, that wouldn't happen anyway, because Pants would know, even if you had a single lock file that included, say, you know, NumPy, Pants would know that nothing in your web app imports NumPy, so it wouldn't bring it in.
- 57:24This is more when you actually have multiple lock files.
- 57:27Yeah, so Pants is very good about shaving down the dependencies, both the internal and the external ones, to just what you actually need.
- 57:34But where multiple lock files comes in is when you have conflicts, when your code base is large enough that you genuinely cannot have the entire code base be in lockstep on a single set of dependencies.
- 57:45We don't encourage that.
- 57:47It's not a great way to be.
- 57:48It's better if you can have a single, consistent resolve across your entire code base, but it's not always possible.
- 57:54And this is an example of where we designed for the world as it is and not the world as we would like it to be.
- 58:00Yeah, that makes a lot of sense.
- 58:01I mean, if one of the APIs is written in Django 1 and the person who built it left and there's no reason for it to change, like, just don't touch it.
- 58:10Just leave that alone over there.
- 58:11But the other part needs to use, you know, newer libraries and sure.
- 58:15Yes, that's a great example.
- 58:17Yeah, cool.
- 58:17All right, Benji.
- 58:18I think we might be getting short on time here, but let me close this out with one final question.
- 58:25So you talked a lot about the caching and the parallelization and how, like, the dependency understanding.
- 58:33So if I want to run these tests, I can just say, run since this last get a tag or whatever, a shah or whatever it is you're going back to.
- 58:40What is your personal workflow or common workflows you see for managing that?
- 58:47Because at some point I'm like, okay, the stuff up to here is good.
- 58:50Now I want to, it's been a few days.
- 58:52I want to move forward.
- 58:54I know the older stuff is good and we're not changing it.
- 58:57Like, how do you sort of evolve this developer workflow sort of history?
- 59:01What's your workflow there?
- 59:02I rely very heavily on the Git comparison logic.
- 59:07So I should mention I do not code very much anymore because I'm now, I'm the co-founder of Toolchain, which is a company that actually provides SaaS and support and services around builds, Python and otherwise.
- 59:21And obviously that's where a lot of the pants expertise comes from.
- 59:25So we provide things like remote caching, remote execution as a service.
- 59:31So I don't code that much anymore.
- 59:33But, you know, occasionally when I do, I rely very heavily on the Git diff functionality.
- 59:39So my command lines are just basically, and one thing pants has is macros where you can create these, sorry, macros is something else.
- 59:48What I was actually referring to, but I can run like pants green.
- 59:53I can't really say, but I'm going to use my pants green.
- 59:58I can't really say, but I'm going to use my pants.
- 1:00:04I'm going to use my pants.
- 1:00:05I'm going to use my pants.
- 1:00:06I'm going to use my pants.
- 1:00:07I'm going to use my pants.
- 1:00:08I'm going to use my pants.
- 1:00:09I'm going to use my pants.
- 1:00:10I'm going to use my pants.
- 1:00:11I'm going to use my pants.
- 1:00:12I'm going to use my pants.
- 1:00:12I'm going to use my pants.
- 1:00:12I'm going to use my pants.
- 1:00:13I'm going to use my pants.
- 1:00:14I'm going to use my pants.
- 1:00:15I'm going to use my pants.
- 1:00:16I'm going to use my pants.
- 1:00:17I'm going to use my pants.
- 1:00:18I'm going to use my pants.
- 1:00:19I'm going to use my pants.
- 1:00:20I'm going to use my pants.
- 1:00:21And what you can actually do is run this in a loop.
- 1:00:24So you can have pants just sort of watch for file system.
- 1:00:27It watches your file system for changes and automatically rerun that logic every time you save.
- 1:00:32So often by the time I tab into my terminal, those checks have already run or are at least running.
- 1:00:39Yeah.
- 1:00:40Okay.
- 1:00:41That's my workflow.
- 1:00:42This command alias is a cool idea as well.
- 1:00:45I'm sure people will dig that.
- 1:00:46All right.
- 1:00:47Well, congratulations on Toolchain.
- 1:00:48Thank you.
- 1:00:49It seems like a cool thing to be working on and clearly builds on a ton of work you all have been doing.
- 1:00:54Thank you.
- 1:00:55Yeah.
- 1:00:56We basically feel both on the open source side and on the company side that you should not have to work at Google or Microsoft or Facebook to have a really fast, stable, powerful build experience.
- 1:01:06You should have that when you're a 20 person company and when you're a 200 person company and when you're a 2,000 person company.
- 1:01:11You should not have to wait to be a 100,000 person company to get that.
- 1:01:14Yeah.
- 1:01:15You should be somebody whose job it is to set up CI.
- 1:01:17I mean, their whole job, not just something they do as part of their job.
- 1:01:20Yeah, I guess that's the other side of things.
- 1:01:22I see about the developer workflow.
- 1:01:23What does it look like?
- 1:01:24It's like, let's suppose I have a GitHub and I'm using GitHub Actions as my CI.
- 1:01:30How do I get pants to work over there?
- 1:01:32So that's an interesting area that we are looking at more and more closely.
- 1:01:36And we will have some interesting announcements about that over the next few weeks.
- 1:01:40And just a heads up, this episode will probably, for people not watching the live stream, will be out probably in three or four weeks.
- 1:01:46So it might actually be real as they hear these words.
- 1:01:50We'll see.
- 1:01:51Maybe.
- 1:01:52But it is very easy to set up GitHub Actions or CircleCI or BuildKite or whatever you're using to run pants commands.
- 1:01:59And those pants commands in turn take away a lot of the or handle a lot of the concurrency and caching concerns that normally you would have to really mess with.
- 1:02:09You'd have to really drill into your CI config in order to get.
- 1:02:13So it essentially makes it much, much, much easier to configure CI because the complexity of, well, how do I get caching?
- 1:02:21How do I get concurrency?
- 1:02:23How do I speed things up?
- 1:02:24Is handled automatically by pants instead of you manually having to write tons of YAML or whatever your CI providers config is in order to get that concurrency.
- 1:02:37Here, there's a lot of heavy lifting going on where the system itself is analyzing your code and saying, oh, here are opportunities for concurrency.
- 1:02:45Here are opportunities for caching.
- 1:02:46Whereas today, with CI of all kinds, CI workflows of all kinds, either you do that yourself or you vary manually or you don't get it.
- 1:02:56Interesting.
- 1:02:57And maybe as part of the caching, you just say, like you described for the developer workflow, right?
- 1:03:01Everything other than, you know, compare that against main and now run it on that diff.
- 1:03:06Exactly.
- 1:03:07And CI is basically, you set up CI to call pants.
- 1:03:10Pants does its magic.
- 1:03:11Correct.
- 1:03:11Answers come out.
- 1:03:12So you don't have to write tons of a CI config because a lot of, so much of the reason you would have to do that is now handled by pants itself.
- 1:03:21Yeah.
- 1:03:21Awesome.
- 1:03:22All right.
- 1:03:23Well, very cool project and definitely something to be checking out.
- 1:03:28Now, before you get out of there, out of here, but final two questions.
- 1:03:31If you're going to write some code, even if you do a little bit less these days, what editor are you using?
- 1:03:35I use PyCharm.
- 1:03:36Yeah.
- 1:03:37Actually, technically I use IntelliJ with the PyCharm plugin because of just habit of, I used to write JVM code and I never lost the habit, but effectively PyCharm.
- 1:03:47Yeah.
- 1:03:48Right on.
- 1:03:48Cool.
- 1:03:48And then notable PyPI package.
- 1:03:51I really like click.
- 1:03:52We don't use it for various reasons.
- 1:03:54We need like a lot of control over the CLI, but I really like click for just cobbling together cool tools that have really good CLI interfaces.
- 1:04:02Excellent.
- 1:04:03And let me hijack the end here just for a moment.
- 1:04:05Maybe I should have asked you before to install pants.
- 1:04:09It's not pip install pants, is it?
- 1:04:11Nope.
- 1:04:11It's, so if you go to our website, pantsbuild.org, there's very simple steps for walking through it.
- 1:04:17But essentially there's a wrapper script that does things like install pants for you in a virtual env and keep it up to date.
- 1:04:25So you don't have to worry about where is this virtual env, how to, which version of pants is in it.
- 1:04:31It will look at the version that's in your pants config file.
- 1:04:34There's a pants.toml file that contains a bunch of pants config.
- 1:04:36One of them is which version of pants is this repo supposed to be using?
- 1:04:40And the script will make sure that is the version being used.
- 1:04:43Yeah.
- 1:04:43So you don't pip install it.
- 1:04:45You run this script and it does a bunch of magic on top of the vanilla virtual env experience.
- 1:04:50Fantastic.
- 1:04:51Okay.
- 1:04:52Yeah.
- 1:04:52Just pantsbuild.org slash docs slash installation and off you go.
- 1:04:57All right.
- 1:04:57Thank you so much for being here.
- 1:04:59Final call to action.
- 1:05:00People want to get started with pants.
- 1:05:01What do they do?
- 1:05:01So pantsbuild.org and probably one of the best resources is our Slack channel.
- 1:05:06So if you go to pantsbuild.org and click on community on that community link at the top,
- 1:05:11it'll take you straight into like how to come chat with us on Slack.
- 1:05:14So obviously you're going to try and get started without that, but it's, we have a very friendly,
- 1:05:20helpful community that firmly believes that there are no bad questions, only bad documentation.
- 1:05:26And so Slack is a great place to kind of sample the community, come chat with us, tell us about
- 1:05:32your needs, tell us about how pants can meet them or how it can't meet them.
- 1:05:35It's open source.
- 1:05:37And we have a lot of contributors from all sorts of companies and all sorts of organizations
- 1:05:41and all sorts of teams who started that way and got really enamored with what pants can
- 1:05:47do and got really involved both in improving the developer experience at their organizations
- 1:05:53and also in improving pants itself.
- 1:05:55So we really, best call to action is come say hi.
- 1:05:58Congrats on cool project and thanks for coming and sharing it with us.
- 1:06:01Thank you.
- 1:06:02It was my pleasure.
- 1:06:03You bet.
- 1:06:03Bye.
- 1:06:03This has been another episode of Talk Python To Me.
- 1:06:07Thank you to our sponsors.
- 1:06:09Be sure to check out what they're offering.
- 1:06:11It really helps support the show.
- 1:06:12Listen to the Local Maximum podcast.
- 1:06:14Learn about topics as diverse as the philosophy of probability and Elon Musk's next move.
- 1:06:20Just search for Local Maximum in your favorite podcast player.
- 1:06:23Starting a business is hard.
- 1:06:26Microsoft for Startups, Founders Hub provides all founders at any stage with free resources
- 1:06:32and connections to solve startup challenges.
- 1:06:34Apply for free today at talkpython.fm/founders hub.
- 1:06:39Want to level up your Python?
- 1:06:41We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:06:45Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:06:50And best of all, there's not a subscription in sight.
- 1:06:52Check it out for yourself at training.talkpython.fm.
- 1:06:56Be sure to subscribe to the show.
- 1:06:57Open your favorite podcast app and search for Python.
- 1:07:00We should be right at the top.
- 1:07:01You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:07:07and the direct RSS feed at /rss on talkpython.fm.
- 1:07:12We're live streaming most of our recordings these days.
- 1:07:14If you want to be part of the show and have your comments featured on the air,
- 1:07:18be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:07:22This is your host, Michael Kennedy.
- 1:07:24Thanks so much for listening.
- 1:07:25I really appreciate it.
- 1:07:26Now get out there and write some Python code.
- 1:07:28Thank you.
- 1:07:28Thank you.
- 1:07:28Thank you.