Latest / Talk Python To Me / #399: Monorepos in Python
Transcript
- 0:00Monorepos are contrary to how many of us have been taught to use source control.
- 0:04To start a project or app, the first thing we do is create a Git repository for it.
- 0:09This leads to many focused and small repositories.
- 0:12A quick check on my GitHub account shows that I have 179 non-fork repositories.
- 0:18That's a lot, but I think many of us work that way.
- 0:21It's not like this with monorepos.
- 0:23With monorepos, you create one or a couple of repositories for your entire company.
- 0:28This might have hundreds or thousands of employees working on multiple projects within a single repository.
- 0:34Famously, Google, Meta, Microsoft, and Airbnb, amongst others,
- 0:39all employ very large monorepos with varying strategies for coordination.
- 0:44On this episode, we have David Vilyek here to give us his perspective on monorepos,
- 0:49as well as highlight an architectural pattern and set of tools for accomplishing this in Python.
- 0:55This is Talk Python To Me, episode 399, recorded January 13th, 2023.
- 1:14Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:17This is your host, Michael Kennedy.
- 1:19Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython, both on fosstodon.org.
- 1:26Be careful with impersonating accounts on other instances.
- 1:29There are many.
- 1:30Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:36We've started streaming most of our episodes live on YouTube.
- 1:39Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:46This episode is brought to you by Microsoft for Startups Founders Hub.
- 1:51Get early stage support for your startup without the requirement to be VC-backed or verified at talkpython.fm/foundershub.
- 1:59It's also brought to you by Brilliant.org.
- 2:01Stay on top of technology and raise your value to employers or just learn something fun in STEM at Brilliant.org.
- 2:09Visit talkpython.fm/brilliant to get 20% off an annual premium subscription.
- 2:14David, welcome to Talk Python To Me.
- 2:17Thank you.
- 2:18I'm really excited to be on the podcast.
- 2:21I'm really excited to have you on the podcast.
- 2:23And we get to talk about a couple of interesting ideas.
- 2:27We get to talk about software architecture.
- 2:30People may know I'm a big fan of architecture.
- 2:33I think putting your software together bright makes all the difference.
- 2:37We're going to talk about some ideas that are new to me, this polyleth idea that you're an advocate and fan of and how it applies to Python.
- 2:45We're also going to focus a good portion of this conversation on monorepos.
- 2:50And what the heck are monorepos, right?
- 2:52Yeah.
- 2:53That'll be a lot of fun.
- 2:54And I'm really looking forward to it.
- 2:56But let's hear your story first.
- 2:59How did you get into programming and Python?
- 3:01Yeah.
- 3:01How did I get into programming?
- 3:02Well, so I guess it was when I was a kid.
- 3:05My dad bought me Commodore 64.
- 3:08It was like way back in the 1980s.
- 3:11So that's when I started learning basic programming language and how to write things that are code and not pure text.
- 3:24But then I went on a different path.
- 3:28I was working mostly with design and things like that.
- 3:34And the first thing I knew was a job in our business was a web designer.
- 3:41So that was what I wanted to be at first.
- 3:44So I started to learn JavaScript and copy and pasted some snippets of code and stuff like that.
- 3:51Yeah.
- 3:51And that's the era.
- 3:52I'm just guessing from the starting computer where you were sort of in time when this must have happened.
- 3:58And that was probably before all these crazy JavaScript front-end frameworks and all that.
- 4:02And it was more of how do you visually design this page with graphic and more art and more focused on that, right?
- 4:09Yeah.
- 4:09Before like jQuery and before like all these React and all of that good stuff that we have today.
- 4:17Sure.
- 4:18Yeah.
- 4:19And with Python, I think I started about 2015 with Python.
- 4:23I started with Python 2.7 and then learning all I think in that period, I also learned started to think in more like functional programming style, more like functional-ish.
- 4:37Yeah.
- 4:37And that's coming from Python actually.
- 4:40And I was very much into Node.js at that time too.
- 4:44So I think around 2015, and I've been like jumping back and forth between different languages.
- 4:50I'm a really huge fan of Clojure 2, which is like 100% functional.
- 4:55So I've been like visiting some different kinds of programming languages and styles and things like that.
- 5:04And now I'm back to full-time Python on my day job and almost full-time Python during nights because I really love to code on my spare time too.
- 5:15When I assume there is any chance to code.
- 5:19So I'll take that one.
- 5:21Yeah, absolutely.
- 5:22I mean, how much of open source is there's programmers and we have this project we've got to work on, but we really want to build this other thing and we're super passionate about it.
- 5:30We just end up building it and sharing it and it takes off, you know?
- 5:33And I think that's a very common story for sure.
- 5:35So before we move on, how has working in Python influenced something like Clojure or Clojure influenced your Python thinking?
- 5:46They're fairly different languages, right?
- 5:48Yeah.
- 5:48Functional being less stateful, which is a really big different way of programming.
- 5:52Yeah.
- 5:53Well, I think what I learned from Python was like the elegance and the importance of writing elegant and simplistic code.
- 6:04I was really impressed by the Zen of Python.
- 6:08You know, if you type import this in a shell, you get this nice list of how to write your code.
- 6:14I really liked that idea.
- 6:16So I guess that's where I started to think about keeping it simple, clean and short.
- 6:22Yeah.
- 6:22And with Clojure, it was like that's kind of a different, total different syntax, but also digging into a lot of functional aspects and how to think about state, how to separate the calculations from actions and data and things like that.
- 6:43And I think I've brought a lot of those ideas back to when I'm back at Python, how to separate different kinds of code that you write.
- 6:53Yeah, I can see that.
- 6:54I feel like Python is really interesting because you can choose to only focus on little parts of it.
- 7:00That's good for beginners because they only have to learn a little part, but it's also good for people who have particular styles that they like to work.
- 7:07If you want to write functional Python, you don't have to create any global variables or any classes or any, you can just, you can write it that way, but you could completely go really deep OO patterns and can do that in Python too if you want.
- 7:21Right.
- 7:22It's completely up to you.
- 7:23Yeah.
- 7:23And I like that kind of freedom.
- 7:25It's, you can't, you don't, you're not the force to do either this or that you, you can learn an experiment.
- 7:34And especially when you, if you use libraries, they are like designed in different ways too.
- 7:41So you can, you don't have to limit yourself to only use that kind of library or this kind of library.
- 7:46So I really like Python, the capabilities of Python when it comes to that, but it's not very strict in any kind of format.
- 7:55I like that too.
- 7:56And I think other languages are seeing that and adopting that as well.
- 8:00You know, you see Swift with their playgrounds and well, Swift in general and .NET with their, you know, maybe we don't need namespaces and classes and static main void for everything to get started.
- 8:09And they're adopting those types of things.
- 8:12You know, we're talking about this like, well, functional people might want to write this way and more OO oriented people that way, but that also could just be you in different situations.
- 8:20You know, right now, this is the right tool to solve it.
- 8:23And other times here's a different way to solve a different problem, but you can just stay in the same tools and the same editors and the same ecosystem.
- 8:30It's cool.
- 8:31Yeah, definitely.
- 8:32Yeah.
- 8:32All right.
- 8:33Well, let's start in on the first half of our, our main topic here is the mono repo.
- 8:41Now, yeah, it's really easy to confuse what a mono repo is with a mono lith versus same microservices.
- 8:48Yeah.
- 8:49Those are not really at all the same thing.
- 8:51In fact, they might actually be opposites in a sense, a mono repo and a mono lith to some degree.
- 8:56So maybe kick us off by telling us what is a mono repo here?
- 9:01A mono repo is, I don't think it's that complicated, but I actually also, before I started to dig into this thing more,
- 9:10I also had almost put like an equal sign between mono lift and mono repo because that's the way I have used the writing code.
- 9:18I was in the dot net and C# world a lot.
- 9:23And you like building your website and you have a data later and you have a domain layer and everything was in a repo.
- 9:28So I guess Microsoft was like a reaction to that to separate code into isolated environments.
- 9:38And you can have this nice and clean little code base and you have that does one thing and you have this other code base that does a different thing.
- 9:49So if instead of just having the user authentication bit completely just woven into the code, we can make a little API that we call over JSON that does the authentication.
- 9:58And then here's the one has the catalog.
- 9:59Yeah.
- 10:00And we could write just a little bit of code and, you know, the, I guess the benefit, right, is that whoever's working on the catalog bit, they theoretically can just stay focused on that little bit of code and not the entire system.
- 10:11Right.
- 10:12Yeah.
- 10:12With a microservice story.
- 10:14Yeah.
- 10:14A monorepo is, I think, from the way I see it, it's like, it's a Git or any version control repo that has basically all of your code in the same repo, same repository.
- 10:31And that doesn't necessarily mean that it's one program or one app that you are going to build or compile into.
- 10:39You can have several projects or artifacts in that repo.
- 10:44And I guess that's why it's called monorepo because you can have multiple things in it.
- 10:50So I guess that's the difference between a monolith where you have, where you actually build one app and deploy it to one place.
- 10:57Right, right.
- 10:59The monolith is the opposite of the microservice style.
- 11:04Yeah.
- 11:04Whereas the monorepo is just a way of organizing your code and sharing how do you propagate changes, look at dependencies across either libraries or, there are companies that take this really far.
- 11:18Crazy, crazy far.
- 11:20Like Google and Facebook, I believe, haven't worked on it, but I hear that they have one repo.
- 11:26Yeah.
- 11:28Or like all of it.
- 11:29What, one?
- 11:30Really?
- 11:31Just like, what's the checkout story look like on that?
- 11:34It's got to be a lot of code.
- 11:35Yeah.
- 11:36It's got to be a lot of code.
- 11:37I believe Google, I'm probably going to misassociate this, but I think Google uses Bazel and there's different tools that allow them that are kind of not just Git, but something that can handle that scale of code.
- 11:54So it really, when I think about organizing my code, it's either me or me and a couple of people working on the code and it's pretty contained.
- 12:03But when you start to think about hundreds or thousands of people across projects, it starts to get really wild, right?
- 12:09Yeah.
- 12:10That has to be a completely different story.
- 12:14We're really fun to see how they do, how they work in the teams.
- 12:19Yeah, absolutely.
- 12:20So maybe we could talk about some of the, you know, why, if you're not doing this, you know, why would you do that?
- 12:29Like it seems, you know, you highlighted that there's kind of these two trends that you saw out there in some of your articles.
- 12:38And we'll talk about the articles and link to them.
- 12:40You talked about seeing a trend of more people trending towards this monorepo and more people or other groups of people trending towards having more small repos.
- 12:52Yeah.
- 12:52For you take my little microservice example, the user access service might be its own repository separate from the catalog service.
- 13:01Whereas others might say, we're going to put all that together and all the utilities and that other data reporting project.
- 13:08And all of that goes into one giant repo, even though there's a big team on it, right?
- 13:11Yeah.
- 13:12Well, I think from my experience, what I've seen joining different teams and different companies that I've seen exactly that some quite recently, I joined a team at a company with several teams.
- 13:28And they actually migrated from a monorepo to several repositories.
- 13:34And it was part of their microservice journey, as they call it, because they had one repo with all their code.
- 13:44But that code base was so difficult to work with.
- 13:47So they kind of wanted to extract one app at a time into a separate repository just to be able to deploy that one and work with it in a reasonable way with tooling support and things like that.
- 14:02So before that, I was at a different company joining a different team.
- 14:07And we went the total opposite way.
- 14:10We had a couple of microservices that were quite easy to work with.
- 14:20But we identified issues or problems with it because maybe there's one service that has outdated dependencies.
- 14:29So the biggest problem was the actual code duplication because we had one service that we had developed one thing for.
- 14:37And we had another service that we needed code that was very much like the thing we had in that other service.
- 14:47So I guess the solution could be to extract that one into a library, but then you have three repositories.
- 14:53And I guess there's difficult to find that good balance between one or the other.
- 15:00I agree.
- 15:00And that extracting, I mean, that's certainly one of the possibilities.
- 15:05As you say, well, we're going to, you know what, we now have a third repository and we have the data access repository and package.
- 15:13And, you know, that's probably not the type of thing you publish to PyPI, but it's very likely something you would publish to some kind of internal dependency artifact.
- 15:23System that you would depend upon, right?
- 15:25But the problem is, if it's used in just these two places, it's, and it sounds like that sort of description, the kind of the team is probably working on both sides of those microservices and they understand the broader system.
- 15:39But as it grows and more people depend upon it, it's harder to understand this little standalone project.
- 15:45Who is using it and what ways are they completely?
- 15:48Can we make a change here?
- 15:50If we refactor this, who do we talk to about changing even just the signature of a function?
- 15:56How do we reach out to the other parts of code or other stakeholders and say, look, we need to change this function, but we got to, you know, we're changing the data model and you're going to have to figure out how to go along.
- 16:12On the other hand, if all of those projects were together in a giant mono repo, we have tooling that understands, well, what functions call this function or what thing imports this class or who's using it?
- 16:26Is it used at all?
- 16:27Actually, maybe you could delete it.
- 16:29You thought someone was using it and no one's using it, right?
- 16:31There's a lot of understanding of the broader integration if it's all there with you, right?
- 16:38Definitely.
- 16:39This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 16:46Starting a business is hard.
- 16:48By some estimates, over 90% of startups will go out of business in just their first year.
- 16:54With 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.
- 17:02Microsoft for Startups Founders Hub was born.
- 17:05Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
- 17:12The platform provides technology benefits, access to expert guidance and skilled resources, mentorship and networking connections, and much more.
- 17:21Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be investor-backed or third-party validated to participate.
- 17:30Founders Hub is truly open to all.
- 17:33So what do you get if you join them?
- 17:34You speed up your development with free access to GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.
- 17:42To 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.
- 17:52Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
- 17:57You'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.
- 18:11You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
- 18:16Make your idea a reality today with the critical support you'll get from Founders Hub.
- 18:21To join the program, just visit talkpython.fm/foundershub, all one word, no links in your show notes.
- 18:27Thank you to Microsoft for supporting the show.
- 18:32Yeah, I totally agree.
- 18:33And our editors are so smart and they can find usages and if you have this function signature isn't really correct and stuff like that.
- 18:46And that's so much easier when you have your source code in a folder that is like right next to the one using it.
- 18:55So that's a huge benefit, like editor-wise to the developer experience, I guess.
- 19:00Yeah, absolutely.
- 19:02And I think one of, this is both a benefit and a challenge.
- 19:06You know, I'll maybe link to the Monorepo Wikipedia page and it says, here are some of the advantages.
- 19:10One of the number one advantage list is ease of code reuse.
- 19:15So it's possible, not necessarily suggested, but possible that you say, well, the data access functions and classes that we need on this side, we need some of them over here.
- 19:25But if you have the whole Monorepo, you could just say, well, import them in both projects and deploy, you know, a larger piece of code to your server.
- 19:33But who cares?
- 19:34The servers have a lot of storage and they'll be fine, right?
- 19:36The challenge, I think, is going to be the, you're going to end up with a tightly coupled architecture pretty badly if you just say, well, I see way over there, there's that file and that's the one I want.
- 19:47And we're just going to grab that.
- 19:48And, you know, it doesn't necessarily encourage good behavior, but it does make reusing code and understand how it's being used easy, right?
- 19:56Yeah.
- 19:56And also you have, you're like in the risk zone of actually building a Monoly again.
- 20:02Yeah, exactly.
- 20:04You're just part of the, part of the API points run there and part of the API points run there, but they're, they're effectively just one giant thing, right?
- 20:11So I guess what I think is that if you are using a Mono, if you want to have your code in a Mono repo, I guess you would need some sort of tooling or ideas about how to separate your code into separate artifacts that don't have the entire code base in its package.
- 20:33Only the code that is actually needed for this artifact.
- 20:38So, again, I guess that's, that's part of the challenge, having a Mono repo.
- 20:42I would say so.
- 20:43I've been thinking about this a little bit leading up to our conversation today.
- 20:48And certainly you can use packages in the, you know, we have this problem in Python or this challenge where packages mean different things, but it has the same word.
- 21:01So a package could be just a grouping of modules into a directory that has a __init__(), or it could be something on PyPI that you ship and you deploy and you version on its own.
- 21:11And I mean, in just the on disk, the __init__() sort of local grouping, right?
- 21:18So you could create these, these sort of groups within your Mono repo and say, we're going to import that, but have a little bit of a formal separation and say, look, we're not necessarily going to deploy it through some versioning story and let other people pull it in.
- 21:34Because then we lose track of who's using it and how they're using it.
- 21:37Are they on the right version?
- 21:39But we'll still maybe think of them as a Python package, in a sense.
- 21:44Do you have any experience with doing it one way or the other?
- 21:47Any preference?
- 21:48Yeah.
- 21:49What I was thinking of from the company that I joined that were migrating from their Mono repo, they had done a couple of attempts to do this code sharing thing.
- 22:02with the likes, I think it was like Git sub modules or, or similar things.
- 22:08But all of that ended up into in, it was became too complicated to, to understand what was going on.
- 22:17And, and I think even the editor support where it wasn't really, really perfect when you had like these kind of dynamic linking.
- 22:26So I guess that's, that's why they, they chose to, to abandon that idea.
- 22:31Yeah.
- 22:33Yeah.
- 22:34It sounds a little bit like with the sub modules that it was not a pure Mono repo, but kind of a, let's have different sections on, on our repository, but bring it together.
- 22:46Yeah.
- 22:49Yeah.
- 22:49Yeah.
- 22:49like, we're going to sort of put these files and it's, this is a sub module, that's a sub module and they're kind of separate.
- 22:56But then once they're all checked out and linked up, then our tool thinks of it as one giant thing.
- 23:02Like the Mono repo would be right.
- 23:03Yeah.
- 23:04So it's kind of a, an intermediate, I also thought about this as well.
- 23:07Like maybe, maybe you could put together the get tools like that.
- 23:10I do want to highlight a couple of get tools because maybe I'll, I'll take a quick bit of audience feedback real quick.
- 23:19But I do think that, you know, when it's five people, 10 people, you just check the thing out and it's going to be fine.
- 23:25But as it gets larger and larger, both over time and lines of code and number of people, it's, it's going to be a thing where it almost becomes unmanageable to just do a, a git clone URL and see what happens.
- 23:39Right.
- 23:40You can go grab, grab a coffee.
- 23:41And when it got back, it's not, it hasn't downloaded.
- 23:44We've probably seen that XKCD where there's people like fake sword fighting on a chair.
- 23:49It's like, get back to work.
- 23:49Like, you know, we're doing a git clone, leave us alone.
- 23:53Okay.
- 23:54Sure.
- 23:54Fine.
- 23:54Gotcha.
- 23:55It's going to be a while.
- 23:56Quick bit of audience feedback says model repos are okay.
- 23:59If you have a dedicated team that manages the advanced tooling required to deal with them.
- 24:04Yeah, absolutely.
- 24:04And I sort of related Lucas asks, they would use Bazel for your projects or rather have make files or similar in case of lints and builds.
- 24:14So yeah, there's the different tools that like Facebook and Google and those folks use.
- 24:20There's also pants.
- 24:22Benji Weinberger has talked a lot about it.
- 24:24I've had him on the show.
- 24:25I've had him on the show before.
- 24:26And pants is one of these tools that can kind of help pants build.
- 24:31But David, how about you?
- 24:32What were you all using in terms of more advanced tooling or was there anything special?
- 24:38Back then it was not really more advanced than actually make files to make things happen.
- 24:45But the other place, the team that I joined actually started to use this, I guess we're going to talk about it in the architecture called polyleth.
- 24:55And there's also tooling for that.
- 24:57Yeah.
- 24:58And there's also tooling for that kind of offers a solution to many of these headaches with having a monorepo.
- 25:06Yeah, absolutely.
- 25:08And back then it was because polyleth originates from closure.
- 25:13So we were actually writing closure code.
- 25:15And then for Python, I started to look around for a solution.
- 25:23I actually read a little bit about pants.
- 25:26So I think that can solve a lot of problems too.
- 25:30It seems like a really great tool with a lot of useful functionality.
- 25:37And then there's also poetry.
- 25:41I don't think that it's not really about monorepos, but you can, I believe that you can use pure poetry and have your dependencies,
- 25:52like the third party libraries, your own or the one at PyPy in sort of an, not the third party, but your own in an editable mode.
- 26:02So they will, as soon as you change something, it will be updated.
- 26:05So I guess there are some tools that can help you along the way, but I guess there's still a lot of frustration with having that smooth and really joyful monorepo experience that you would like to have.
- 26:19So that's what led me to, to, to start working on this project.
- 26:24I do think that Python, the way that its dependencies and its understanding of linking, you know, files together through directories and things like that makes it a little bit more challenging than other systems.
- 26:37Like if I was doing C++, I could open up Visual Studio Code and create a broader project and say, these three libraries are what I want to see as my project.
- 26:46And it doesn't really matter where they come from.
- 26:48You build it and they link together and there's sort of a build the Delta only type of thing.
- 26:53Whereas in Python, you kind of need to bring on a little bit more tooling to say, I know it looks like there's some giant Python thing here, but just these two pieces.
- 27:01That's what I want to think of as the thing, you know, what we're going to talk about with some of the stuff that you've done with poetry with polyleth and others certainly make that relevant.
- 27:11I do want to talk about the Git tools, but it's also interesting.
- 27:14This comment from David Poole, it says we use sub modules for legal licensing reasons.
- 27:20That is to have GPL code separate from our proprietary code rather than just dropping it in, which obviously has different implications.
- 27:29Oh, that was very interesting to learn about.
- 27:31Yeah.
- 27:32Yeah.
- 27:32I hadn't really thought about that either, but yes, you definitely want to think about it.
- 27:36So let's just talk Git for a moment.
- 27:38Now, one of the big challenges is if we're going to put this all into one giant GitHub repository, which I hinted at, it could get really large.
- 27:48Especially if you put binary files, like some of your build tooling or other assets, you might put it in there.
- 27:54And then that makes it extra tricky.
- 27:56The less something can diff, the more it kind of piles up quick.
- 27:59As I was thinking about this thing, I learned about a couple cool ideas.
- 28:03Let's talk about this one first.
- 28:04Partial clone.
- 28:05This is something that was totally new to me.
- 28:09So normally it's Git clone the URL to the Git repository.
- 28:14However, you can say things like filter, --filter equals blob.
- 28:21Have you seen this before, David?
- 28:22No, this is totally new to me.
- 28:24So, but it looks really interesting.
- 28:27Yeah, so what happens here is if you, the blob is like a binary file, right?
- 28:33And what you're saying when you say filter blob is it'll check out all of the Git history.
- 28:39And normally when you do a clone, you get, at least for the branch you're on, you get every
- 28:43version of the file.
- 28:44So you git clone, you disconnect from the network and you've got everything, right?
- 28:48Which is the beauty of Git.
- 28:50But if you've got a really huge repository, it also might be the drawback of Git.
- 28:55So you can filter out these blobs in the historical sense.
- 29:00And if you say this, what you see in your hard drive for the working directory is identical.
- 29:06But the .git folder with the history only has the working version, not all copies of the
- 29:12history of the blob.
- 29:13This has like a really huge effect.
- 29:16So I did this on Talk Python training, my courses website.
- 29:19And if I just say git clone, the repo, it pulled down 118,000 objects.
- 29:26It resolved 71,000 deltas and it updated 10,000 files and it was a gig on disk.
- 29:32If I just say filter, --filter equals blob colon none, it goes from 118,000 to 10,000
- 29:38downloads.
- 29:39It goes, it's less than half the size.
- 29:42And the resulting files on disks, those were the same, but the intermediate deltas were
- 29:49like 170th or 150th.
- 29:52Really a big difference.
- 29:54And this is, you know, it's a pretty old repo.
- 29:59It's got a lot of stuff.
- 30:00It's nothing compared to what a lot of people have.
- 30:01So one, there's one problem where like, okay, if I'm going to try to git clone a mono repo,
- 30:06there's just no way.
- 30:08Right?
- 30:09So adding this aspect here, I think actually would be really valuable.
- 30:12Yeah, definitely.
- 30:13because it's, I guess in the normal, the use case is that you want to work with the latest
- 30:20version of the source code.
- 30:21You want to develop something new.
- 30:23So I guess that's what you want on disk.
- 30:27It makes a lot of time.
- 30:28And what happens is if you say, well, actually we need to switch branches or we need to go
- 30:34back three months in time.
- 30:36It just goes back to the network and clones a little bit more.
- 30:39It's like an incremental clone as it needs it.
- 30:42So I think actually this, this would help a lot of people who don't know about it, working
- 30:46with mono repos that turn out to have a lot of files and a lot of historical, especially
- 30:51binaries that grow over time.
- 30:52Yeah.
- 30:52Because those are the ones that are huge, you know, it's not the text files usually that
- 30:56are the problem.
- 30:56So I have to bookmark this.
- 30:58Yeah, yeah, yeah.
- 31:00This portion of Talk Python To Me is brought to you by Brilliant.org.
- 31:06You are a curious person who loves to learn about technology.
- 31:09I know because you're listening to my show.
- 31:11That's why you would also be interested in this episode's sponsor, Brilliant.org.
- 31:15Brilliant.org is entertaining, engaging, and effective.
- 31:19If you're like me and feel that binging yet another sitcom series is kind of missing out
- 31:23on life, then how about spending 30 minutes a day getting better at programming or deepening
- 31:28your knowledge and foundations of topics you've always wanted to learn better, like chemistry
- 31:33or biology over on Brilliant.
- 31:34Brilliant has thousands of lessons from foundational and advanced math to data science, algorithms,
- 31:41neural networks, and more with new lessons added monthly.
- 31:44When you sign up for a free trial, they ask a couple of questions about what you're interested
- 31:48in as well as your background knowledge.
- 31:50Then you're presented with a cool learning path to get you started right where you should
- 31:53be.
- 31:54Personally, I'm going back to some science foundations.
- 31:57I love chemistry and physics, but haven't touched them for 20 years.
- 32:01So I'm looking forward to playing with PV equals NRT, you know, the ideal gas law, and all the
- 32:07other foundations of our world.
- 32:08With Brilliant, you'll get hands-on on a whole universe of concepts in math, science, computer
- 32:14science, and solve fun problems while growing your critical thinking skills.
- 32:18Of course, you could just visit brilliant.org directly.
- 32:20Its URL is right there in the name, isn't it?
- 32:22But please use our link because you'll get something extra.
- 32:2520% off an annual premium subscription.
- 32:28So sign up today at talkpython.fm/brilliant and start a seven-day free trial.
- 32:33That's talkpython.fm/brilliant.
- 32:36The link is in your podcast player show notes.
- 32:38Thank you to brilliant.org for supporting the show.
- 32:43Related to that, so quirky ads, wouldn't a shallow clone be more predictable?
- 32:47So this is also interesting.
- 32:49So shallow clones is a older way to do this in GitHub.
- 32:54The problem is with shallow clones, you don't get the full history and changelog.
- 33:01With these partial clones, you have all of the history, commit history and details.
- 33:06You just don't have the files and they're incrementally pulled in.
- 33:10So you could do a shallow clone.
- 33:11And then there's another one, what was it called?
- 33:15A sparse clone.
- 33:17So a sparse clone is another tool that you can bring in here for advanced Git usage, where
- 33:24you say, I know I've got this huge directory structure, but I just want to get these three
- 33:29directories or this subdirectory structure.
- 33:33And you clone only part of the files, right?
- 33:37So we were talking about how Python understands just like the whole thing as one giant project.
- 33:41And maybe even you check it out and try to open it.
- 33:43Your editor will just say they're indexing, indexing, and autocomplete won't really work
- 33:48and very well and go crazy.
- 33:50So you can just say, I want these three directories and I want them partially cloned.
- 33:55So they only have like the recent history and they're not so insane.
- 33:59And you can kind of combine these to get really focused views into a monorepo, which I thought
- 34:05was pretty interesting.
- 34:06Yeah.
- 34:07So anyway, when I think back to the story you told about how you guys were using submodules,
- 34:14I kind of feel like these partial clones plus sparse clones might be a better fit than trying
- 34:20to, you know, symlink things together.
- 34:22Because it really just is the same thing.
- 34:25If you want to clone the whole thing, you do.
- 34:26But then you can kind of just, as you clone it, filter out.
- 34:30And you can also, with those sparse clones, you can retroactively add in.
- 34:34You go, oh, I also need that directory.
- 34:35You can say like, get sparse ad.
- 34:37Oh, cool.
- 34:38This now needs to be this piece to come in as well.
- 34:40And there's some interesting ways to put these together.
- 34:42So I think these tools are going to be, for people who are working with monorepos, I think
- 34:46those advanced Git features that I called out might be really helpful.
- 34:51What do you think, David?
- 34:52Yeah, I totally agree.
- 34:53Especially when you have a monorepo that is a lot of code.
- 34:57So it seems like this is, you wouldn't live with, want to live without it, I guess.
- 35:03Because it's probably not helpful.
- 35:05Yeah, I think so too.
- 35:06So sparse checkout, I believe, is actually the first.
- 35:10Sparse checkout.
- 35:10Okay.
- 35:11I think sparse checkout is the term.
- 35:13I'll link to it as well.
- 35:14It's partial clone and sparse checkout.
- 35:16There we go.
- 35:16Nice.
- 35:18Okay.
- 35:18There's so many good features in Git that I guess most of us don't use.
- 35:22Yeah.
- 35:23I think so too.
- 35:24Like I've been doing Git for a really long time and this sparse checkout is completely
- 35:29new to me.
- 35:30I only learned about it because I was trying to research a little bit more of some like,
- 35:34well, how do you do actually manage with these monorepos as we are preparing for our chat
- 35:38today?
- 35:38So yeah, I think there's a lot of tools and flexibility that are not obvious or not apparent
- 35:45that people can use to make monorepos work really, really well.
- 35:49There's still a lot of interesting ways to structure your code and put it together and
- 35:53use it once you get it checked out.
- 35:55So maybe let's, what do you want to start?
- 35:59You want to start with a fresh take on monorepos?
- 36:00This is one of your articles.
- 36:02Yeah.
- 36:02Yeah.
- 36:02Why not?
- 36:03Yeah.
- 36:03Yeah.
- 36:03So tell us the story here.
- 36:05I wrote this article about a year ago, almost a year ago.
- 36:09Before that, I was trying to figure out how to work and have this nice developer experience
- 36:15in a monorepos.
- 36:17And coming from closure and having learned new things and have some new fresh ideas on how
- 36:24you can solve things, I wanted to give it a try in Python too.
- 36:31And also at the same time, I was actually doing work with microservices, but in several
- 36:38repos.
- 36:39And I kind of found myself, there was not a huge thing, but it was like a logger, sort
- 36:45of a logger module or a package.
- 36:48I knew that I had done it in the other microservice just a couple of weeks ago.
- 36:54So, okay, what should I do?
- 36:56Should I create a library?
- 36:57No, this is way too small to create a library.
- 37:00And it wasn't even open source.
- 37:03It's like a proprietary system.
- 37:06So when you would need a lot of private repo servers, things like that.
- 37:12So I just ended up in copying some code.
- 37:14And, you know, while people would go, of course, you should never do that.
- 37:17But sometimes it's just not complicated enough or important enough or big enough to justify
- 37:23all the change management and dependencies.
- 37:26And you know what?
- 37:27That file, it goes into this project.
- 37:29And usually it's fine until they get out of sync or there's some weird, you want to upgrade
- 37:35one and then, oh, where else is it, right?
- 37:37Or you discover a bug in that part and you forget about that you have copied it a couple of times
- 37:44and now with the other repo.
- 37:45So then you have a lot of work to do.
- 37:47There's probably a whole section of cybersecurity history and like breaches where they thought they fixed a problem in some system.
- 37:56Yeah.
- 37:56And it turns out someone else found a copy of it that wasn't fixed and broken.
- 38:00And yes, this is not ideal.
- 38:02I really wanted to give the polyleth in Python a try because I really enjoyed the way things are structured
- 38:10and a lot of these like headaches are solved there.
- 38:15Polyleth is really, really new to me.
- 38:17Maybe tell people about polyleth before we go on because I suspect a lot of people don't know about this.
- 38:21Yeah, maybe we should begin.
- 38:22Yeah, let's begin there.
- 38:23Then we'll come back to it.
- 38:24Well, polyleth, it's an architecture, but it's also a tool or something with a tooling support.
- 38:31And it's open source and it's developed by a fellow Swede, Joachim Tengstrand.
- 38:37And I was fortunate to actually work in the same team as him.
- 38:43So he was done introducing this.
- 38:46We decided to give it a try.
- 38:49He was new in our team.
- 38:51And I have to confess, I was a little bit skeptical at the beginning because skeptical of monorepos in general too, because based on previous bad experiences.
- 39:03So the polyleth is the main idea is that you have, when you write code, you're supposed to, you aim to write them in small parts.
- 39:12And that's what polyleth called components.
- 39:15And a component, polyleth uses the idea of Lego, but for code.
- 39:21So a component could be a piece, a Lego brick that you can reuse in several ways.
- 39:28And a component can be everything from a small tech, something that you normally would put in a utils folder, like functions that do maybe some parsing or something.
- 39:41But it can also be a combination of other components.
- 39:44They don't have to be of the same size.
- 39:46It's the idea of composability and reusability that is the important thing.
- 39:52So the big parts of polyleth are our components.
- 39:57And then we have something called bases.
- 40:00And that is also a component, but a kind of special kind of component.
- 40:06If you think about Lego, if you're going to build like a house, you often have a base plate where you put your Lego bricks on it.
- 40:15So a base is sort of that part.
- 40:17And in code, that could be like, if you have like a FastAPI app, maybe a base plate could be where you define the endpoints.
- 40:28Like you use the API decorator side or something like that.
- 40:33So that could be a base.
- 40:35And then the code that actually does something could be a combination of different components.
- 40:42Yeah, that's an interesting way to think of it.
- 40:44Whenever you talk about stuff, what are the things that's difficult as to understand?
- 40:47What is the scale or how are these different?
- 40:50So one way, well, our functions components, our modules components, our packages components, like, how do I identify that since it's not a formal language runtime term?
- 41:04Yeah. That's really, really good. Help me understand how I make these things in Python. Yeah. Yeah. That's really interesting. Because you can see a component. It's not a full blown feature, like maybe a library that you publish in on PyPy would be. It's smaller than that. And I guess it could be a single function. But it's probably one or more functions that kind of relates to it. Let's say that you...
- 41:32And what should I have prepared with an example, but let's say that you want to parse a CSV file or something, then you would probably separate the different things you want to do with that CSV file into functions already.
- 41:52And the component is where you kind of group the functions that kind of relate to each other or that make sense to have in a Python package.
- 42:02Then I mean a namespace with a dunder in it.
- 42:05So that could be a component.
- 42:07Yeah.
- 42:07Although it could be modeled in one of these sub packages.
- 42:11Those sub packages often have multiple jobs and roles and you're like, let's stay really focused on the one thing that it does, right?
- 42:18Yeah.
- 42:19And all of this lives in what Polylyph calls a workspace.
- 42:23And that is basically a repository with a configuration about how your repository looks like.
- 42:35So you have your components in namespace packages, basically.
- 42:39And you have your basis, the entry points of your apps.
- 42:43Then you have something called projects or a project.
- 42:47And that is the artifacts or artifacts that you want to build.
- 42:52So you can have only one project if you're going to build one thing, maybe a FastAPI service.
- 42:59But the benefit comes when you are about to build something new.
- 43:03Then you have your project infrastructure, like the project configuration and what it is defined in a folder called projects.
- 43:14And then with the code you use, you pick the code from the components and bases folder.
- 43:19So you will reuse the same source code.
- 43:23And then you package it into different artifacts.
- 43:26So it sounds a little bit like we've got this monorepo with all of this stuff.
- 43:30And the polylyph, its job is to say, well, we're going to look into these little parts of this monolith.
- 43:38And I need this part and this part and this part.
- 43:40And it's some tooling and some concepts to help you manage some artifact.
- 43:47We don't usually have exact build artifacts often if you're not shipping out separate packages.
- 43:54But maybe these three pieces here make up the FastAPI service that we're going to host over there.
- 44:00And maybe these two services make up the data science tools we're going to give to the data scientists for their notebooks.
- 44:06And there could be some overlap in those, right?
- 44:09Yeah, exactly.
- 44:10Yeah.
- 44:10Okay.
- 44:11And another good thing is with the workspace is that you don't really do much work in the project folder or something like that.
- 44:20Because the main idea is that you have a development environment that includes all your bases, all your components.
- 44:29So the good thing with that is that you can experiment and try out code without worrying about if you have imported the correct stuff.
- 44:39So you just, you have a top project folder containing all of your dependencies and packages.
- 44:45And then you can take it from there.
- 44:48Once you're ready to build a project, build something out of it, an app or whatever it is, then you can start constructing that project-specific configuration.
- 44:58You can choose where you want to start.
- 45:00But I usually start from the development workspace.
- 45:04And I really like a way of working called REPL-driven development.
- 45:08But I also learned from Closure, which is they try out things in the REPL, basically.
- 45:12Yeah.
- 45:13That's a really nice developer experience that you get from having the entire source code.
- 45:19You can try out things, combine components, and develop new features.
- 45:23Yeah.
- 45:23I'm doing more and more of that as well, this REPL-driven development.
- 45:27Or I'd say not necessarily development, but exploration.
- 45:30I kind of want to understand.
- 45:32I'm not really sure.
- 45:33Is this going to click together right?
- 45:35Or is this, rather than putting a lot of structure in place, because I'm not even sure I really want to stick with it, fire up a REPL.
- 45:42For those of you who don't know, if you just type Python, what you get, redevelop print loop, that's the REPL.
- 45:47I do it in PyCharm these days, because PyCharm has a Python console, but it gives you autocomplete and tab completion.
- 45:55Like, of the things that are in your project when you're playing in the REPL, but, you know, still, same idea.
- 46:00Yeah, that's really great.
- 46:01Yeah, yeah, absolutely.
- 46:02So are you guys using this on your projects right now?
- 46:06Or what do you do with it these days?
- 46:08Yeah, I'm fairly new to the team that I join.
- 46:11So I've introduced them to the ideas, but they have, like, already code and stuff in place.
- 46:17So my hopes are that we will give it, once we have something new to develop or include an existing microservice, maybe we could give this idea a try.
- 46:28So that's basically because I'm coming.
- 46:31Yeah, that's always the problem is, even if you yourself are not new, the ideas may be new to you, and you've done a bunch of previous work.
- 46:37Like, for me, I was showing you that repo before.
- 46:40I'm just, I'm thinking, there's a lot of cool stuff I could do about how I restructure this and reuse it and make it available, you know, sort of bring more of the mono repo stuff to some of the things I'm doing.
- 46:50I'm like, then I got to update the continuous deployment changes, and I've got to update where the web server, I'm just like, you know, it's just like, there's all this stuff that's there.
- 46:59And it's, you know, do you kind of pause what you're doing to try some new big organization of code here?
- 47:06That's how it goes, right?
- 47:07We still learned the polylet.
- 47:09That's where we actually used it in production.
- 47:11We had several kinds of different services and apps where we had everything in a polylet, not a repo.
- 47:18But that was Clojure.
- 47:19And Clojure is a compiled language, like C++ or C#.
- 47:22Is that right?
- 47:23Yeah, it's on top of the JVM.
- 47:26So that is compiled through that engine.
- 47:31Yeah, I do feel like things are just a little, the deliverable artifacts are slightly more obvious and easy to distinguish when you're talking about something that compiles.
- 47:43And like, here's the library that drops into the bin folder, and here's the executable binary that drops.
- 47:49You know, there's an output folder that has all the pieces that were selected.
- 47:53Whereas Python, you've got to be a little more careful how you put that together.
- 47:57So what I came up to was how can this idea be used in Python?
- 48:03And then that was actually what led me to poetry, which I think is a really nice tool.
- 48:09Well, because poetry, I think it's a lot of nice ways of handling projects and dependencies and structure and stuff like that.
- 48:18There were a couple of things missing to make this idea work.
- 48:23Because when you have a project configuration, you actually include components from a relative path.
- 48:30So you navigate up and navigate down to the actual component.
- 48:34And if you would just build a wheel or a source distribution from that, that wouldn't be a valid package.
- 48:42Because then you would need to ship the entire monorepo structure.
- 48:47And you don't want to do that.
- 48:49So what I did was I developed a plugin to poetry that actually allows for having relative includes.
- 48:57And that will build the code.
- 49:00That will build a wheel and a source distribution with the kind of correct path.
- 49:05So it takes all the package dependencies and puts them in the same folder, basically, before it does the wheel.
- 49:13And then you have a valid distribution that you can use.
- 49:16So it does a little bit of copying and stuff like that.
- 49:21All right.
- 49:21So the actual output here, it's a couple of wheels that we could say pip install into a virtual environment.
- 49:29And they work together.
- 49:30Is that right?
- 49:30Yeah.
- 49:31Okay.
- 49:31Try this idea with like services, like FastAPI services.
- 49:37Instead of including the source code like as a tree, installing it with pip from a wheel or a source distribution.
- 49:47Preferably be from a wheel if you don't have any like operating system specific stuff.
- 49:53So I think that works really.
- 49:55And it's the end result.
- 49:57If you do it in a Docker container, you can like have the full control of what's in there.
- 50:03Yeah.
- 50:03So in your Docker file that builds the Docker image, you can just say, you know, copy these three wheels over, pip install them into my Python environment I have over there.
- 50:14And it's just taken the, what do you call them, workspaces that you need over there.
- 50:20What is the terminology that you call the artifacts here?
- 50:23I mean, I know they're wheels and packages, but is there a polyleth term that matches over here?
- 50:28Oh, I don't think so.
- 50:30Maybe it's like a built artifact perhaps.
- 50:34Yeah.
- 50:35And it's probably the most simplistic scenario is that you have like an app, like an API endpoint or maybe a CLI app or even a library.
- 50:46And you probably want to install them in different places, maybe even on AWS Lambda.
- 50:53So you can have the control over the deployment in your CI saying that I want to deploy this Lambda here and I want to deploy this FastAPI over there.
- 51:04So, and with polyleth, you can build these wheels differently.
- 51:08Nice.
- 51:08Yeah.
- 51:09I feel like the, if you think of microservices and monolith, the AWS Lambda or any serverless functions as a service story is like the most extreme version of this.
- 51:21Yeah.
- 51:21Here's a single function that gets deployed.
- 51:23Here's a single function that gets deployed, like just one after another, right?
- 51:27It's kind of out of control.
- 51:29And you have all of them in separate repositories.
- 51:32Oh, please.
- 51:33No.
- 51:33Yes.
- 51:34That would be definitely tricky.
- 51:35I want to come back and talk more about this poetry plugin because it's really cool.
- 51:39But let's address this question from Lucas here.
- 51:41How would you approach versioning in a monorepo, like of these different services and of the different pieces?
- 51:50So if I'm going to have that FastAPI thing that builds over there, I'm going to have some other projects that are built
- 51:56with some overlap that are shared over to, say, my data science team.
- 52:00They're going to analyze data in some other way, but reuse some of the code.
- 52:04I've got some thoughts, but what are your thoughts on versioning, say, in the repository or how you deploy them?
- 52:09Yeah, that's a really good question.
- 52:11If I'm looking at it from a polyleth perspective, I would suggest a very simplistic solution.
- 52:18Let's say that you have your this project depends on something with this version and the other project is still on an earlier version.
- 52:27And I think that can be solved with the components itself because all source code is made up of all these components.
- 52:36So if you're going to build a new version of something and if that version uses a new third-party dependency or that is incompatible,
- 52:45I would suggest you to add it as a new separate component.
- 52:50So your new projects that will use that one will pick that component instead of the old.
- 52:57I think it's a good practice if these components have the same or as long as it's possible, the same API.
- 53:05So it should be easy to switch from the old to the new one.
- 53:10So that would be my solution to versioning, at least when using polyleth.
- 53:16If we look at not the monorepo style, but you build an artifact like a wheel from one repo
- 53:22and you put it up there and someone else depends upon that, maybe through an internal artifact management, private PYPI,
- 53:30you would pin your version in the requirements file for that other one, right?
- 53:34Because that repo is changing at a different rate and a different cadence than maybe the library that it depends upon.
- 53:41And that's really natural for us as Python people because we already have a great long list of things that are open source
- 53:49that we don't build that we depend on, right? FastAPI, Pydantic, and Starlette would be an example from what we've been talking, right?
- 53:56Those things you don't control and you depend on them.
- 53:59So you pin the versions and upgrade them as you see fit.
- 54:01But one of the advantages of the monorepo to me, as far as I see it at least, is the whole system,
- 54:08not just your part of the system, but the whole system is consistent all the time.
- 54:15The main branch or the production branch or whatever the shipping branch is.
- 54:20So I think you would maybe branch, do some of your work, merge that back in.
- 54:25And at that point, you could ship everything if you need to, right?
- 54:29Yeah.
- 54:29Because you're continuously keeping it together as a whole system, not like, well, that library built and that library built
- 54:36because they're separate repos, but you put them together and who knows what's going to happen.
- 54:40I think this is an advantage of the monorepo in a sense.
- 54:43Yeah, me too.
- 54:44Definitely.
- 54:44I think it makes it easier to notice about using some parts of the code.
- 54:51It's using a certain version of a dependency.
- 54:54You will learn about it quite quickly because if you would install it and try to run the code.
- 55:00it's easier to note, and hopefully it's easier to also update that code.
- 55:04But if you are in a situation where there's so much code that you need to refactor,
- 55:09maybe there's a breaking change that kind of has rethought the entire idea of that happens.
- 55:16Maybe you need to do some sort of separation and keep the oldest until you have the time to refactor that.
- 55:23I guess in most cases, it's pretty straightforward to update just everything in the monorepo.
- 55:28Right. Yeah, exactly.
- 55:29And if you've got some sort of continuous integration or some kind of automated check,
- 55:34you're going to find out pretty quickly this change you made has a consequence over there.
- 55:39And I think that's why people who are psyched about monorepos are excited about it.
- 55:45It also feels to me like if there was going to be a breaking change, it's going to happen either way.
- 55:51It's just, is it going to happen in small little pieces or is it going to happen in one terrible, huge,
- 55:56oh, you got the new one?
- 55:58Well, let me tell you, the new one's really different.
- 56:00It doesn't work anymore.
- 56:01Like, oh no.
- 56:02You know, just like you want to merge more often or you want to try to integrate things more often
- 56:08and not just wait some long period of time and go, now do they go together?
- 56:12Why are there a hundred or a thousand, you know, merge conflicts?
- 56:16I don't know, right?
- 56:16Like the more you do these little continuous checkbacks and integrations, it's just going to be so much easier.
- 56:25Oh yeah.
- 56:25Totally agree.
- 56:26Yeah.
- 56:27I mean, the only scenario where you don't have to go back and pay that penalty is where the other service
- 56:34that you're versioning against says, we're never going to go to the new version.
- 56:39And if this is internal code, it's unlikely that it's never going to go to the new version
- 56:43unless it becomes just dead.
- 56:45And then who cares?
- 56:45You're going to need to integrate them eventually.
- 56:47Just keep doing it continuously.
- 56:50So yeah, I'm starting to really come around to the idea of these things.
- 56:52Yeah.
- 56:53Yeah.
- 56:53So this polyleth plugin for poetry, it's super cool.
- 56:58So for example, here on your example, you say poetry, space poly, space info on the terminal,
- 57:04on the command prompt.
- 57:05And it'll say, hey, look, in here we have two projects made of two components and two bases,
- 57:10the Lambda project and the FastAPI project.
- 57:13And they're made up of these different elements.
- 57:17And it really shows what part of your code is depending on the other ones.
- 57:22It even gives you a pretty table.
- 57:24Is this made with rich?
- 57:25Yeah.
- 57:26Yeah, it's rich.
- 57:27I love that tool.
- 57:28It's so great.
- 57:29Yeah.
- 57:30It's been my new favorite tool.
- 57:32It's so good.
- 57:34Yeah.
- 57:35So it's a really nice looking UI that you put together here as well.
- 57:38Yeah.
- 57:38Thanks.
- 57:38I'm really happy to hear that.
- 57:41Well, how easy for people to...
- 57:42Yeah, go ahead.
- 57:42Sorry.
- 57:43Don't mean to just talk over you.
- 57:44Yeah, I just want to mention that what we see here is the tooling support for the polyleth thing in Python.
- 57:51And I decided to make it as a poetry plugin.
- 57:53I have some plans to break it out of poetry to make it separate.
- 57:59CNI 2, maybe I'll do that in the future.
- 58:01But I thought it was a good fit for poetry since I'm relying on a lot of poetry features.
- 58:07And the command there, polyinfo, is showing you an overview of your monoree.
- 58:13And this is my example project with...
- 58:16So it's not a lot of code, but the idea is that you will list all your components and bases.
- 58:23The command there for these are bricks.
- 58:25Then you get a sort of an overview of what's in that monoree.
- 58:30You can sort of get an idea of what's in there.
- 58:33What does this thing do?
- 58:35And then it's listed per project.
- 58:38So you can see which project is actually using which brick.
- 58:42Yeah, let me just give a little bit of visual information for people listening.
- 58:47So under the brick column, it says we have the logging, we have the messaging, we have the greet API, and we have the messages for Lambda.
- 58:54And then you've got, in different columns, the different projects that might be consuming them in little check marks or dashes to say using or not using it.
- 59:02It makes it really visually clear how your elements fit together, right?
- 59:07I'm continuing adding commands to this tooling.
- 59:11There is also, you can use this information, the information about the workspace and the individual project to, in your CI to determine if, let's say that you change the message component, you do something in it.
- 59:27And then you would want to have the projects that are affected built for that.
- 59:34So the tooling will help your CI to make decisions, should build this project or if it should skip building because nothing has changed.
- 59:44So that's part of the tooling to work.
- 59:46That's pretty interesting because we've had attempts and they've always been like an awesome 80% solution that never quite works.
- 59:53But really good solution, really good tool, ideas, I guess, to say, if you change this code, what actually needs to be tested again or what needs to be analyzed again?
- 1:00:04If this other part of your system doesn't depend on it, you don't need to run those tests, right?
- 1:00:10If just the file changes, that doesn't tell you anything.
- 1:00:13You need to look at things like code coverage.
- 1:00:16What part of the system was touched if this part, you know, by affected by this at all, right?
- 1:00:22Those are always really tricky.
- 1:00:24And how do you keep like a history of code coverage to know what to do?
- 1:00:27And all those attempts I've seen just kind of like, we tried, but we don't really do that.
- 1:00:32We'll just run the files that change, which is never enough.
- 1:00:35But this kind of is a natural way to express dependencies in that tree to say, okay, if we change the greet API, we see that the Lambda thing doesn't work with it.
- 1:00:48So we don't need to test anything to do with the Lambda stuff.
- 1:00:51We only need to test the FastAPI aspect, right?
- 1:00:54Yeah, exactly.
- 1:00:54Is that tooling in place now?
- 1:00:55Yeah, that's in place now.
- 1:00:57Okay.
- 1:00:57The poly info command, I think it was like the first command that I actually added.
- 1:01:03Then there's a...
- 1:01:04diff command and what did I add?
- 1:01:07Yeah, the latest addition to commands is a check command.
- 1:01:12Because since you are...
- 1:01:15I was talking about development experience that you're working at in a development project where you have everything.
- 1:01:22And then you might not touch the project that much.
- 1:01:24And that means that you could potentially forget to include dependencies.
- 1:01:30Because as of today, there's no automatic thing yet.
- 1:01:34I'm planning to add that later.
- 1:01:36But so far, you need to keep track of your dependencies and stuff like that.
- 1:01:41So I added a check command that actually does performance analysis on the source code.
- 1:01:48So if you...
- 1:01:49Let's say that one of the components uses the requests library or something like that.
- 1:01:54And you don't have it in your dependencies.
- 1:01:56Then you would be notified for that particular project.
- 1:02:00It's very likely that you would discover it anyway in your development environment.
- 1:02:05But this is an extra check to just make sure once you're about to build something,
- 1:02:11can I really build this specific project?
- 1:02:14So it's a few commands, but it will be more commands that are more and more useful, I guess.
- 1:02:20Yeah, it looks great.
- 1:02:21And you have some examples over in the Python polyleth examples repository that people can check out.
- 1:02:29Yeah.
- 1:02:29Yeah.
- 1:02:29So is the poetry plugin ready for people if they wanted to use it?
- 1:02:34I think so.
- 1:02:35I know I haven't seen any stats yet, but I have a couple of users that have contacted me through the GitHub repo and social media.
- 1:02:46Maybe some of them are just experimented with it and others have.
- 1:02:50I think they actually are working with it in their daily work.
- 1:02:55And I think it's useful.
- 1:02:57I have to remind myself to contact them regularly to just check out how it goes.
- 1:03:06And hopefully they will come to this repo and let me know if something doesn't work as intended.
- 1:03:14But it's a new tool and I probably need some more work on it, of course.
- 1:03:21Yeah.
- 1:03:22Well, a lot of people will hear about it now.
- 1:03:24They can come check it out and play with it.
- 1:03:27Oh, that would be great.
- 1:03:27Yeah.
- 1:03:28And I'm sure you're taking contributions and PRs and you wouldn't mind if people had some additions.
- 1:03:34Oh, yeah, definitely.
- 1:03:34Yeah.
- 1:03:35I would love to have that.
- 1:03:37Cool.
- 1:03:38So contributions are very welcome.
- 1:03:40Yeah.
- 1:03:41And you also have really nice examples here.
- 1:03:43Like you have two videos that show how it works.
- 1:03:47You know, 15 minute YouTube videos.
- 1:03:48You've got some pictures and, you know, well done on that.
- 1:03:51It makes it really easy for people to come and just see like, okay, is this interesting?
- 1:03:54Does it apply to me?
- 1:03:55So good work.
- 1:03:58I do want to make one really quick follow-up.
- 1:04:01Corky out there had mentioned that maybe shallow clones were a better, more predictable choice than the partial clones with the filter equals blob.
- 1:04:11In general, the people at GitHub are recommending not to use the shallow clones anymore, but to use instead these partial clones because it keeps the history and it can incrementally go back and pull the stuff in as needed.
- 1:04:25However, there is one time where you may really want those shallow clones.
- 1:04:29And the reason I'm thinking of this is you talked about builds and using this to make builds run faster and only focusing on the parts that have changed.
- 1:04:37If you have a CI, the CI doesn't care about the history of your GitHub project.
- 1:04:42It just wants the working files, right?
- 1:04:45So you can do a shallow clone and say, just get me only the files on the tip of this branch and then build it.
- 1:04:52And that could be dramatically faster than saying, give me all five years of history of every single file and reassociate that.
- 1:05:00So if you're thinking about CI, this shallow clone idea that I was dismissing a little bit is exactly a good choice, I think, because you don't care about version history if you're trying to see if the current version builds or not, right?
- 1:05:14So anyway, just a quick follow-up on that.
- 1:05:16All right, David, I think we're probably out of time.
- 1:05:19I definitely encourage people to go check out your poetry plugin.
- 1:05:22They can check out polylith at polylith.getbook.io.
- 1:05:28Of course, I'll link to it in the show notes.
- 1:05:30Now, before you get out of here, I've got the two final questions to ask you, of course.
- 1:05:35If you're going to write some code, if you're going to work on the poetry polylith plugin, whatever, what editor are you using these days?
- 1:05:44Well, these days I use Emacs.
- 1:05:45I really like the two final things.
- 1:05:48Before Emacs, I really liked PyCharm too.
- 1:05:53But then I decided to learn Emacs and I'm stuck.
- 1:05:57Okay.
- 1:05:59Every programming language, I'm going to code everything in Emacs.
- 1:06:03Nice.
- 1:06:03Yeah.
- 1:06:04Long, long ago, that was my very first editor for programming.
- 1:06:08Oh, cool.
- 1:06:09And then, yeah.
- 1:06:10It brings me back to working on Silicon Graphics mainframes, computers doing C++.
- 1:06:15So, notable PyPI package.
- 1:06:17Something we simply talked about.
- 1:06:20Something else that you want to just tell people about that you thought was awesome.
- 1:06:22Ran across recently.
- 1:06:24I have to say Rich because it's such an awesome tool.
- 1:06:27And when you're going to develop a CLI and want it to look nice, and yeah, Rich is a really, really good tool.
- 1:06:37There were a lot of visualization features and stuff like that.
- 1:06:41So, that's a fantastic tool.
- 1:06:42Yeah.
- 1:06:42Good recommendation.
- 1:06:43There's so much momentum behind Rich these days.
- 1:06:46And if you're making some CLI developer-oriented tool, just give it a little color.
- 1:06:53Give it a little structure.
- 1:06:54And something like Rich, even just a little bit of color or a little bit of distinguishing one line of text from the other makes such a big difference in being able to use it really quickly and easily.
- 1:07:06And Rich is probably the best way to do that by far, right?
- 1:07:09Yeah.
- 1:07:09You should check out my new latest command, PolyCheck, because it uses a rich feature that I'm really happy about.
- 1:07:16It's silly, but I'm really happy.
- 1:07:17It uses an emoji while you're waiting.
- 1:07:20Fantastic.
- 1:07:21Oh, yeah.
- 1:07:22I love emojis.
- 1:07:23I love emojis and CLIs as well.
- 1:07:26All right.
- 1:07:27Final call to action.
- 1:07:28People want to get started with monorepos, with polyleth, with some of these ideas we've talked about.
- 1:07:34What do you tell them?
- 1:07:34Head over to the polyleth git repo or the official polyleth docs and read about it and see.
- 1:07:42Also, if you're interested in monorepos in general, check out the other solutions that are out there, because there are a lot of different approaches with different kind of focuses that maybe fit your situation best.
- 1:07:55I'm, of course, pro polyleth because I, yeah, develop a tool and really like that.
- 1:08:02But there's probably tools that are better for a difference to situation.
- 1:08:06So just explore, I would say.
- 1:08:09Right, right.
- 1:08:10The tools that maybe Google chooses to manage its code base might be the wrong tools that you choose for yours because the scale is so different.
- 1:08:18Right.
- 1:08:19Yeah.
- 1:08:19You might add so much complexity that it's not relevant.
- 1:08:22You know, it makes it really hard, but you don't need that complexity because you've got five projects, not 5,000 projects.
- 1:08:27Right.
- 1:08:28So, yeah, absolutely.
- 1:08:29Look around is good advice.
- 1:08:31Okay, David.
- 1:08:32Thank you for being here.
- 1:08:33It's been a really fun chat.
- 1:08:34I learned a bunch.
- 1:08:35Yeah.
- 1:08:35Thank you.
- 1:08:36So we really have fun to be on the show.
- 1:08:39Thank you.
- 1:08:40Yeah.
- 1:08:40You bet.
- 1:08:40Bye-bye.
- 1:08:41Bye.
- 1:08:41This has been another episode of Talk Python To Me.
- 1:08:45Thank you to our sponsors.
- 1:08:47Be sure to check out what they're offering.
- 1:08:48It really helps support the show.
- 1:08:50Starting a business is hard.
- 1:08:52Microsoft for Startups Founders Hub provides all founders at any stage with free resources and connections to solve startup challenges.
- 1:09:01Apply for free today at talkpython.fm/founders hub.
- 1:09:06Stay on top of technology and raise your value to employers or just learn something fun in STEM at brilliant.org.
- 1:09:13Visit talkpython.fm/brilliant to get 20% off an annual premium subscription.
- 1:09:20Want to level up your Python?
- 1:09:22We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:09:26Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:09:31And best of all, there's not a subscription in sight.
- 1:09:34Check it out for yourself at training.talkpython.fm.
- 1:09:37Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:09:41We should be right at the top.
- 1:09:42You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:09:52We're live streaming most of our recordings these days.
- 1:09:55If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:10:04This is your host, Michael Kennedy.
- 1:10:05Thanks so much for listening.
- 1:10:06I really appreciate it.
- 1:10:07Now get out there and write some Python code.
- 1:10:09Thank you.
- 1:10:09Bye.
- 1:10:10Bye.
- 1:10:10Bye.
- 1:10:11Bye.
- 1:10:12Bye.
- 1:10:13Bye.
- 1:10:14Bye.
- 1:10:15Bye.
- 1:10:16Bye.
- 1:10:17Bye.
- 1:10:18Bye.
- 1:10:19Bye.
- 1:10:20Bye.
- 1:10:21Bye.
- 1:10:22Bye.
- 1:10:23Bye.
- 1:10:24Bye.
- 1:10:25Bye.
- 1:10:26you
- 1:10:27you
- 1:10:27you
- 1:10:28you
- 1:10:28Thank you.