Latest / Talk Python To Me / #400: Ruff - The Fast, Rust-based Python Linter
Transcript
- 0:00Our code quality tools, linters, test frameworks, and others, play an important role in keeping our code error-free and conforming to the rules our teams have chosen.
- 0:08But when these tools become sluggish and slow down development, we often avoid running them or even turn them off.
- 0:15On this episode, we have Charlie Marsh here to introduce Ruff, a fast Python linter written in Rust.
- 0:21To give you a sense of what he means by fast, common Python linters can take 30 to 60 seconds to lint the CPython codebase.
- 0:29Ruff takes 300 milliseconds.
- 0:31I ran it on the 20,000 lines of Python code for our courses web app at Talk Python Training, and it was instantaneous.
- 0:39With that kind of speed, it's the kind of tool that can change how you work.
- 0:43I hope you're excited to learn about Ruff.
- 0:45This is Talk Python To Me, episode 400, recorded January 18, 2023.
- 0:58Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:08This is your host, Michael Kennedy.
- 1:09Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython, both on fosstodon.org.
- 1:17Be careful with impersonating accounts on other instances.
- 1:20There are many.
- 1:21Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:26We've started streaming most of our episodes live on YouTube.
- 1:30Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:38This episode is brought to you by Cox Automotive.
- 1:40Join their team and use your technical skills to transform the way the world buys, sells, and owns cars.
- 1:46Find an exciting position that's right for you at talkpython.fm/cox.
- 1:50And it's also brought to you by User Interviews.
- 1:53Earn extra income for sharing your software development opinion at User Interviews.
- 1:58Head over to talkpython.fm/userinterviews to participate today.
- 2:03Before we get to the conversation for this episode, I have a very brief sponsored message from the PyCharm team.
- 2:09As you know, I'm a huge fan of PyCharm, the tool and the team, and I'm happy to bring it to you.
- 2:14Do you like storytelling?
- 2:15Want a job where you can work with the Python community and help people with their professional development?
- 2:21PyCharm is doing big things this year, and they have an exciting job opening you should consider.
- 2:27Developer Advocate.
- 2:28It's a good job doing good work with a great company.
- 2:31Learn more and apply at talkpython.fm/PyCharm dash Advocate dash Job.
- 2:36The link is in the episode show notes.
- 2:38Charlie, welcome to Talk Python To Me.
- 2:41Thanks so much.
- 2:42It's my pleasure to be here.
- 2:43Yeah, it's a pleasure to have you.
- 2:45I'm going to talk about making Python code fast.
- 2:47Built some pretty interesting tools here with Ruff.
- 2:52We'll see about integrating Rust into Ruff, and there's a lot of cool tools around this
- 2:58sort of code quality side of things, right?
- 3:01Like Black took off in ways, I think, even though Łukasz didn't maybe imagine it would take off,
- 3:06and this is kind of in that same realm, and of course, it plays well with Black along the
- 3:13way as well.
- 3:13So we'll get to talk all about those things.
- 3:16It's going to be tons of fun to dig into them, but before we get to it, let's start with
- 3:19your story.
- 3:20How did you get into programming in Python and Rust?
- 3:22Yeah, yeah.
- 3:23So I got into programming, I guess, the summer before I went to college, when I guess I was
- 3:29supposed to be doing something fun.
- 3:30I taught myself Java, and it was the sort of thing that a lot of people had told me I would
- 3:36like, but I never really had a chance to dig into.
- 3:38I ended up, I went to school, majored in computer science, so I did a bunch of internships while
- 3:43I was in college.
- 3:44And then when I, my sort of junior year internship and my first year out of school, I worked at
- 3:50a company called Khan Academy, which is like an education technology company.
- 3:54And at the time, this is less true now, but at the time they were a really big Python
- 3:59child.
- 3:59I mean, they had one of the biggest like App Engine deployments.
- 4:03It was like Khan Academy and like Snapchat and like a couple other, maybe Spotify or someone.
- 4:09Wow, I had no idea.
- 4:11I mean, I'm just, yeah, I'm obviously I'm familiar with Khan Academy, K-H-A-N, I'm sure a lot of
- 4:17people are.
- 4:17Yeah.
- 4:17But I didn't realize that one, they were such a GCP customer and that was Python.
- 4:22Yes.
- 4:22Was that Flask or Django on GCP or what was it?
- 4:25It was like Flask on App Engine.
- 4:27Yeah.
- 4:28We did not use Django.
- 4:29Yeah.
- 4:29But they actually, I mean, it's a whole nother story, but they did a big Go rewrite after
- 4:34I left, which is also super interesting.
- 4:36I mean, it's not Python, but it is still very interesting.
- 4:38Just like migrating a system from any language to any other language is always pretty interesting.
- 4:43But at Khan Academy, yeah, you know, I did some Python.
- 4:46I would say that like I mostly did web and we can talk a little bit more about this because
- 4:52like really through my career, I've kind of jumped between a lot of different ecosystems.
- 4:55And so like at Khan Academy, I did, I think a year of Android.
- 5:00And did a little bit of iOS, did a lot of web, did a little bit of Python.
- 5:03And then most recently, I worked at a company called Spring Discovery, which is like a computational
- 5:09biotech company.
- 5:10And everything we were doing was based on computer vision.
- 5:13So we'd like take really high resolution pictures of cells and then try to model like the way
- 5:18that they change when you add drugs.
- 5:19Wow.
- 5:19Okay.
- 5:20Which is, yeah, it's pretty wild.
- 5:21I mean, I came into that with no bio background.
- 5:23I joined as like second engineer and build out a lot of our like data and machine learning
- 5:28platform.
- 5:29That was kind of a crash course in building like a massive system in Python, right?
- 5:32We were doing scientific computing.
- 5:34So it made a lot of use Python.
- 5:35So we ended up using Python for like almost everything.
- 5:38Yeah.
- 5:38Yeah.
- 5:39Python is a really good choice for the web, but it's like the de facto choice for data
- 5:44science, right?
- 5:44Like it's.
- 5:45Yes.
- 5:45Yeah, exactly.
- 5:46There's not a whole lot of other choices.
- 5:48Whereas on the web, there's, you know, five or six other platforms and languages that are
- 5:52also contenders for that space.
- 5:55Right, right.
- 5:55So, you know, we built out what I consider to be like a fairly large Python code base.
- 6:00It was like a big monorepo.
- 6:02And, you know, I spent four or five years, you know, building that out and like really writing
- 6:08a lot of Python every day.
- 6:09That's where like a lot of my Python experience comes from.
- 6:12And like that experience specifically also informed a lot of, a lot of growth.
- 6:15And, you know, I can talk more about sort of how those experiences intertwined, but that's
- 6:19kind of my Python background.
- 6:20It must have been really fun to explore some of this visualizing cells and interacting with,
- 6:26you know, microscopes and.
- 6:28That was amazing.
- 6:29Yeah.
- 6:29All those kinds of things.
- 6:30Yeah.
- 6:30The coolest part of the job was just that if you bucket it like really crudely, like a
- 6:35third of our team were sort of like software engineers or like data scientists, machine
- 6:38learning researchers, and then, you know, a third were, you know, wet lab biologists,
- 6:43PhDs.
- 6:45And so every day I was like working directly with scientists and like building software for
- 6:49scientists, which was just like a super cool thing to be able to do as part of a small team.
- 6:53Yeah.
- 6:53But yeah, wrote a lot of Python.
- 6:55That's awesome.
- 6:56I worked at a place that was a bunch of PhD researchers doing eye tracking, like not Apple,
- 7:03but your actual eyes.
- 7:05Like, what are you looking at?
- 7:06wrote the software to actually control the device and get all the information off of
- 7:10it and then like analyze that and put, you know, generate like reports for the scientists
- 7:15and stuff.
- 7:15And it's, there's a, there's a special kind of cool for software that touches like reality,
- 7:21right?
- 7:21Yeah.
- 7:22I mean, it adds a lot of complication.
- 7:24Of course it does.
- 7:25It's very cool.
- 7:26You don't get exact numbers.
- 7:28You want to test it like, you got to approximate all the things, but still, yeah, that sounds
- 7:33like a super fun job.
- 7:34How did it inform rough?
- 7:36Like what are some of the experiences that?
- 7:37Yeah, totally.
- 7:38Just so people know rough is like a super fast linter.
- 7:42Just give us the quick elevator pitch.
- 7:43So they, they, they know what the heck rough is.
- 7:45We'll dive more into it later.
- 7:46Sure.
- 7:47Yeah.
- 7:47Yeah.
- 7:48So rough is what I call an extremely fast Python linter.
- 7:51If you've used linters and Python in the past, you've probably used something like play gate
- 7:56or pilot, or maybe like PI code style, you know, maybe use other tools to help manage your code
- 8:01style, like black or like auto peppy, all this stuff that deals with effectively code style.
- 8:07So rough is a linter.
- 8:09It looks at your source code and it tries to report back and tell you a sort of flag and
- 8:14tell you about issues with it.
- 8:15And those could be stylistic issues.
- 8:17Like this variable name is not great, or they could be, you know, like logical issues.
- 8:22Like you reference a variable here and that isn't defined.
- 8:25Right.
- 8:25I think there's a lot that distinguishes rough, but like the thing that I think caught
- 8:28a lot of people's attention was just how fast it is.
- 8:30So I sort of hate benchmarks, like, cause no matter how much time you like put into a benchmark,
- 8:35like it's always wrong from like a certain perspective and like people always complain about
- 8:39them, but I think rough is comfortably like somewhere in 10 to a hundred times faster.
- 8:44Some people even say like a thousand times faster on their setup.
- 8:47So it can be like really, really dramatically faster.
- 8:49And it can also do a lot of auto fixing, which is kind of a distinctive feature that I don't
- 8:55know that many other tools.
- 8:57And there are certainly tools that do code transformation in Python, but like Pylon and
- 9:02Flake 8 and such don't do this.
- 9:04So for lots of the errors that Ruff will flag, it can actually fix the code for you and fix
- 9:09the issue for you, which is a big time saver.
- 9:11I don't know if this is one of them, but just to give people an idea, like one of the errors
- 9:14or warnings rather that it'll give you is you have an F string, but you're not leveraging
- 9:20its F string capabilities, right?
- 9:22I'll just say F quote, and then it has just static text, a little.
- 9:25Literal string.
- 9:26So it doesn't need the F, right?
- 9:27Theoretically, you could say auto fix and just it drops the F for you.
- 9:31It's like, yeah, you don't need that, right?
- 9:33Yeah.
- 9:33And, you know, we can also like go the other direction.
- 9:36So like if you're doing a bunch of like percent string formatting or using like the dot format
- 9:42style helpers, we're actually, we can fix at least one of those right now.
- 9:47And strings are really complicated, but like we can actually rewrite, I think the dot format
- 9:51calls into strings, which is cool.
- 9:54Fantastic.
- 9:54You know, another thing we can do is we can kind of keep your code like modern in a way.
- 9:58We've taken a lot of inspiration from other tools like Pi Upgrade 2 has like so much cool
- 10:03stuff and functionality in it if you haven't seen it.
- 10:06And we take some of the rules from Pi Upgrade and basically re-implement them in Rust and package
- 10:11them into a single interface and a single tool.
- 10:14So you just install one thing and you get, you know, 370 something rules.
- 10:20I can assert that it is indeed fast.
- 10:23We'll dive into it a little bit later, but I ran it on Talk Python training, the courses
- 10:29website that I have.
- 10:30And I think that's got 20,000 lines of Python and it's instant.
- 10:34It's like you press enter and then out, you know, the stuff is just printing out.
- 10:38These are the things that found, which is pretty awesome.
- 10:41So back to your data science work.
- 10:44Yeah, yeah.
- 10:44How are you, what you're doing influence your creation of RUF?
- 10:47Like why not just use Flake 8 or something like that?
- 10:51You know, like I said, I'd like worked in a lot of other ecosystems where, with sort of
- 10:55like stricter languages, right?
- 10:57Like Java and whatever else.
- 10:59And it's not to say those ecosystems are better, but I often come at the stuff from a perspective
- 11:03of wanting a lot of like static analysis tooling.
- 11:06So we had like a really heavily typed code base.
- 11:08We used, like we used mypy, you know, we used Black, we used Flake 8, we used Eyesore, we
- 11:15used, I don't know, like doc formatter.
- 11:18There's like a lot of different stuff that we used.
- 11:19Yeah.
- 11:19You know, really my job was like, I was the maintainer of this big system.
- 11:22And like most of, like a lot of people in the team were effectively like clients of that
- 11:27code base.
- 11:27So they were kind of like using the stuff that, you know, I and some others were building
- 11:31as like a library.
- 11:32And so I had to maintain like this really big system.
- 11:35And like the more static tools you have, you know, in my opinion, it just like greatly
- 11:40increases the leverage that you can have as a maintainer.
- 11:43So we use a lot of tooling.
- 11:44And I think like a couple of things happened.
- 11:47One, you know, I was spending a lot of my time in Python, but I was also doing a lot of
- 11:51web.
- 11:51And so, you know, like one week I'd be doing Python, the next I'd be going and doing like
- 11:56React and TypeScript and whatever else.
- 11:58And so people complain a lot about web tooling and like, you know, there are certainly lots
- 12:04of valid complaints about it.
- 12:05But there's been a lot of interesting innovation, I think, in that space.
- 12:08And I was certainly influenced by some of it, just seeing some of the tools that came out
- 12:13and how fast they were.
- 12:14Sure.
- 12:14And the fact that a lot of those tools were not being written in JavaScript sort of intentionally
- 12:18to make them super performant was pretty interesting to me.
- 12:21So like, I don't know, I don't want to like name drop a bunch of tools, but you know, in
- 12:24the web ecosystem, more tooling is being written in like Go, Rust, even some other sort of more
- 12:30out there languages like Zig.
- 12:31And to me, that was kind of an interesting thing.
- 12:33It was like, well, does the Python tooling have to be written in Python?
- 12:36Like what does, like, why does that have to be the case?
- 12:39And like, what does it buy you and what do you lose?
- 12:41So that was one thing.
- 12:42The other was we actually started to do a lot of Rust Python hybrid stuff in our own code base.
- 12:48You know, our code base was fully Python.
- 12:50And over time, we took some of the like really performance critical pieces and started to
- 12:56rewrite them in Rust and expose them to the Python side using some of these like really great
- 13:03Rust Python hybrid tools that, you know, maybe we'll get into later.
- 13:06So like one example is we were dealing with image data.
- 13:09So like a common thing we had to do is just like download a lot of image files, like really,
- 13:14really fast.
- 13:14Right.
- 13:15And so, you know, we wrote that in Python.
- 13:17We wrote like a bunch of versions that use all sorts of like multiprocessing, threading,
- 13:21and like we tried everything.
- 13:22And then eventually we like rewrote it in Rust.
- 13:24And so we had a really simple, you know, Rust module that would just download files really
- 13:29fast.
- 13:29And then we exposed that as a Python API.
- 13:31So like from the Python code, it just looked like Python, but the actual code that was running
- 13:36and the way it was, you know, built and executed all went through Rust.
- 13:40Right.
- 13:41So you have these big data, big, let's say big computation problems where you're like, you
- 13:46know, this could be better.
- 13:47The same time you're looking at this happening on the web side, you know, web pack or whatever
- 13:51it is.
- 13:52And it's like, this is way better.
- 13:54We can do this in Python, but we aren't.
- 13:55So let's start, right?
- 13:56Probably you got a little experience there and you're like, what else can I build with Rust
- 13:59now that I know how?
- 14:00Yeah.
- 14:01I was seeing, you know, the way that this innovation was happening in the web.
- 14:04I was seeing specifically the Rust Python like opportunity from what we were doing.
- 14:09And then I was, you know, frankly, like feeling a fair amount of frustration just with the
- 14:14performance of a lot of the existing tools.
- 14:16Like, I don't know.
- 14:17I'm always really careful with how I talk about this stuff because I hate being, I'm
- 14:20really like not a hater.
- 14:21And like, I've actually gotten like so much value out of like all of those tools.
- 14:25But I was being like, well, should it really take like one to two minutes to let my code,
- 14:31like couldn't it be much faster?
- 14:33Right.
- 14:33Like it's like a big code base.
- 14:34And like, as you add more plugins and everything else, it really like changes, like how you
- 14:39feel about the tool.
- 14:40Right.
- 14:41Like it's no longer like something I just run and get feedback.
- 14:43It's like, oh, I have to run the linter now.
- 14:46Oh, I have to run the blah blah blah.
- 14:47And I was sort of craving that.
- 14:49Yeah.
- 14:49And if you're doing it on a team, my experience at least has been some people in the team continue
- 14:55to run it because they find more value than stress.
- 14:58And others are like, eh, I'm not running that stupid thing.
- 15:00But then their problems git pushed onto the people who still care.
- 15:04And so then it creates this kind of like a tension, like Joe's code is always kind of crappy
- 15:08because he won't lent it.
- 15:09But then like when I check out his code, my stuff starts reporting.
- 15:13You know, like those are the weird dynamics that happen from tools that are like super slow
- 15:18unit tests or super slow linting or those types of things where certain people stop working
- 15:23with them and others don't.
- 15:24And then you get these weird tensions.
- 15:26So having it fast, there's like real value to that.
- 15:30This portion of Talk Python Nemy is brought to you by Cox Automotive.
- 15:35With brands like Kelly Blue Book, Autotrader, Dealer.com and more, Cox Automotive flips the
- 15:42script on how we buy, sell, own and use our cars.
- 15:46And now the team at Cox Automotive is looking for software engineers, data scientists, scrum
- 15:52masters and other tech experts to help create meaningful change in the industry.
- 15:57Do you want to be part of a collaborative workplace that values your time and work life balance?
- 16:02Consider joining Cox Automotive.
- 16:04Visit talkpython.fm/cox today.
- 16:08Thank you to Cox Automotive for sponsoring the show.
- 16:13I left spring and like mid to late August.
- 16:17I started working on Ruff along with like a couple other projects and I never built a linter
- 16:22before.
- 16:22It was sick.
- 16:23So like I didn't, yeah, I didn't really know what I was doing, but it felt maybe this is
- 16:28like a little bit of hubris or not, I guess, because like it seems to be working.
- 16:33But like I was kind of like, I'll start with a linter because it feels like a tractable
- 16:36like scope of problem.
- 16:38I was like, type checker.
- 16:39I know that's hard and like I don't really know much about it.
- 16:42A linter.
- 16:42I feel like I can learn like some of the concepts.
- 16:45I have a good understanding of like of like how it might work.
- 16:48To me, when I look at it, I think linting people's code, like abstract syntax trees and
- 16:52stuff.
- 16:52I'm like, that doesn't sound like a problem to me.
- 16:54But it's good that you saw it that way because you did get through it.
- 16:57Yeah.
- 16:58Well, the first version I released was like very limited.
- 17:01It was sort of, I sort of needed to get it out because I wasn't sure that people would
- 17:05actually really care that much about like what I was doing.
- 17:07Yeah.
- 17:08Because like I've described to you a lot of like pain points.
- 17:11They're also sort of like opinion, right?
- 17:12But like, you know, I wasn't like a fast forward linter.
- 17:15Like who cares?
- 17:16Was sort of, I wasn't sure.
- 17:17Yeah.
- 17:18So, you know, when I released it, I was like, I want to prove it's possible.
- 17:22I want to like have reasonable confidence that the performance won't get worse or much
- 17:26worse as I expand it.
- 17:28But I only supported like, I don't know, maybe like 20 rules, which was fine with me because
- 17:32I was really trying to prove a point more than, you know, get people to adopt it even.
- 17:37Right.
- 17:37Well, and a lot of times go into that experience, even if very few people used it, you learn fantastic
- 17:43things, right?
- 17:44Yeah.
- 17:45I learned so much.
- 17:46And I read a ton of code.
- 17:48Like I read all, I've read like a lot of, I've read like a lot of source code now.
- 17:54So I've read like all of like, you know, PyFlakes, like high doc style, high code style, like, you
- 18:01know, because I've spent time like trying to re-implement a lot of those, a lot of those rules
- 18:04and like understand how they do things.
- 18:06And you just learn a lot from like reading and trying stuff.
- 18:09Yeah.
- 18:09Rust is sort of like a whole nother thing where, you know, I did some Rust at Spring,
- 18:13but I would say that building Rust was really like my Rust learning experience.
- 18:17I think I had to kind of try to build something from scratch to like really understand the language.
- 18:23Sure.
- 18:23Everything I did in Spring.
- 18:24You can do all the tutorials.
- 18:26Yeah.
- 18:26And I was like, I was trying to get in and out as quickly as possible.
- 18:29No, no.
- 18:30I just like, you know, I didn't do the initial Rust migration at Spring.
- 18:33I worked with another like super talented engineer who did that.
- 18:37And so every time I went into, you know, and I made a bunch of changes to it, but every
- 18:41time I was going in and out, I was like, I just need to like ship this and like move on.
- 18:45Like, I'm not going to spend a bunch of time like really understanding everything that's
- 18:49going on here.
- 18:49I just want to get it to work.
- 18:50And so I needed to like sit down and like really like focus and be presented with like
- 18:56a blank plate, I think to learn and just like fail a lot and like build stuff that didn't
- 19:00compile.
- 19:01Right.
- 19:01And figure out how to resolve those problems.
- 19:03It's honestly, it's a tough, it is a tough learning curve.
- 19:05I'm sure that it is.
- 19:07I started out in C++ and so I know there are harder languages and they're easier languages.
- 19:12So I've never written C++.
- 19:15I'm never.
- 19:17You're not missing that much.
- 19:18I would say.
- 19:18Eddie out there says rough is so awesome.
- 19:20I actually changed all the switch statements in my Python 310 code back to if else blocks
- 19:25so I could switch to rough, which is pretty awesome.
- 19:28That's super nice and slightly embarrassing because we don't support Matt.
- 19:32We don't support Matt.
- 19:32We don't support the match.
- 19:34That's the one big language feature that we don't support yet.
- 19:38You could just kind of comment it out.
- 19:39Like it just, we're going to just ignore whatever's in the switch.
- 19:41It must be fine.
- 19:42On to the next part.
- 19:43Yeah, exactly.
- 19:44Right.
- 19:44Yeah.
- 19:45Yeah.
- 19:46Yeah.
- 19:46I mean, not for your code, but for linting.
- 19:48Let's start our dive in with this comment from Tyler.
- 19:51He says, what are the differences between linters like rough and flake gate?
- 19:55Those versus code stylers or formatters like black.
- 19:58And maybe rough lives in the middle of that spectrum.
- 20:00I'm not sure.
- 20:01Yeah.
- 20:02There's certainly like, like, like you said, it's like a spectrum, right?
- 20:07So I guess there's a couple of different ways to think about it.
- 20:09And it, with those tools specifically, like some of the responsibilities have like in my
- 20:14mind, at least shifted a bit over time.
- 20:15So for example, like flake gate, it does a lot of, it doesn't change your code at all.
- 20:20And it'll just tell you about issues.
- 20:22And those issues could be style issues.
- 20:24Like you have extra white space here or.
- 20:27Yeah.
- 20:27I don't know.
- 20:28What's another big example.
- 20:29This line is too long.
- 20:30Yeah.
- 20:30Yeah.
- 20:31But it could also be like a logical issue, which is something that black wouldn't touch.
- 20:35So it might be like this import is unused.
- 20:38So on the one end you have like, you know, different collections of rules and maybe not really
- 20:43changing the code, just kind of telling you about it.
- 20:45Black is different in that black just reformats your code.
- 20:48So it does, it's not actually aware of like the logic in the code.
- 20:52Like it doesn't know that an imports unused.
- 20:54It doesn't know that function is never called.
- 20:57Yeah.
- 20:57It just takes, you know, that abstract.
- 20:59Well, not, not exactly the abstract syntax tree, but it basically preserves your code as
- 21:03is and just tries to restyle it.
- 21:05And so, you know, it's interesting because like if you use black, you probably don't need
- 21:09a lot of style linting.
- 21:11Like if you're using black to format your code, a lot of the rules.
- 21:14Like a part that relevant anymore.
- 21:16They'll say something like you should have followed the rules of this, but black automatically
- 21:21follows those rules for you.
- 21:22Right.
- 21:22So they're kind of, you don't need to correct the line length because black will wrap it
- 21:25because that's what black does.
- 21:27Right.
- 21:28Yeah.
- 21:28Or even like, you know, if you have like X equals one with like no spaces between the
- 21:33X and the equals and the equals and the one, like the linter will yell at you for that.
- 21:37But black fixes that for you.
- 21:39So a lot of people will turn off those rules.
- 21:41You know, this is why I say the responsibilities have shifted a bit over time.
- 21:45Yeah.
- 21:45I think you're right.
- 21:46That rough, like it kind of sits in the middle.
- 21:48We do less stylistic linting for this exact reason.
- 21:51Like I use black a lot.
- 21:53Black is like immensely popular.
- 21:55So I actually like strong, like heavily deprioritized, like all of the stylistic rules that are made
- 22:01redundant by black.
- 22:02Okay.
- 22:03The difference is we do do a lot of that automatic fixing.
- 22:05So like we'll, we can remove unused imports for you.
- 22:08We can even do like a lot of more complicated rewrites.
- 22:11Like if you're using, if you're using like a dictionary constructor, like the actual, you
- 22:16know, D I C T parentheses arguments, we can actually rewrite as a literal.
- 22:21If you have the rules enabled and you want to do that, you know, there's like a bunch of
- 22:25rules around like comprehensions and literals, and we can do those rewrites too.
- 22:28So, you know, it does, it can do like style and reformatting, but it's somewhere in the
- 22:33middle.
- 22:33Yeah.
- 22:33The fact that it makes some changes, but it doesn't go completely all in like black is
- 22:38kind of why I think it lives a little bit in the middle there.
- 22:40Yeah.
- 22:40One of the things that I think might give people a lot of, brought a lot of faith or a willingness
- 22:46to give it a try is there's a lot of projects out here that are large projects that people
- 22:52would know that have adopted, actively adopted and started using rough.
- 22:58I saw a quote from Sebastian Ramirez from FastAPI right now in the audience.
- 23:03We have Olfek says the next release of hatch, which I hope to do this weekend will have
- 23:10all the new projects generated with config for a Linting environment that uses rough, which
- 23:14I think is pretty excellent.
- 23:15Can we speak to speak to some of that, like about these, these projects adopting it and
- 23:20how that's helped you?
- 23:21Yeah, totally.
- 23:22Yeah.
- 23:22I never expected that like this, maybe that like goes without saying, I think you'd have
- 23:27to be like super arrogant to release something and expect a bunch of these people to use it.
- 23:31Yeah.
- 23:31It's been kind of wild.
- 23:32You know, initially there were a couple big projects that I would call like really early
- 23:37adopters and they helped shape the project a lot.
- 23:42like Pydantic was a very early adopter.
- 23:44Zulip was a very early adopter.
- 23:46FastAPI was actually like a pretty early adopter too.
- 23:49Okay.
- 23:50And then like Pandas and Airflow and stuff, those kind of are more recent.
- 23:55Okay.
- 23:55It's been a very interesting, like to reflect on how that's happened because on the one hand,
- 24:01it's like sort of ridiculous that all these products would migrate over because I'm on,
- 24:06I don't even really have like a proper versioning system right now.
- 24:09Like I'm on V00225 or something.
- 24:12I basically release like every day and I consider like, I don't really make, we've made like
- 24:18very few breaking changes, but like in theory we could make breaking change.
- 24:22I don't want to, but like if you have Scribe December, like we could make changes like that.
- 24:27You know, there's not really like docs, like the docs are just like this huge read me.
- 24:30It's kind of wild, right?
- 24:32We don't support like all the Python 3.10 features, right?
- 24:35We don't support match statements.
- 24:36So on the one hand, it's kind of wild that all these projects would move over.
- 24:39I think there are a couple of things that help a lot.
- 24:42So one is that the entire time I've been like very, very focused on compatibility with existing
- 24:48tools.
- 24:48And that comes at a lot of cost.
- 24:51Like if there are things that I like don't agree with, right?
- 24:54Or whatever else, like I sometimes still support them or implement them.
- 24:57And, you know, but the upside is like, it's very easy for people to migrate.
- 25:01Right.
- 25:02It might change nothing potentially.
- 25:04Right.
- 25:05It just, it just goes faster.
- 25:06Hopefully.
- 25:06And over time, like, you know, we don't have like a third party plugin system.
- 25:10We've just like implemented everything like in Rust, like as part of Rust.
- 25:15I viewed that as like, I'm just going to look at the most popular plugins and the most important
- 25:20rules.
- 25:20And I'm just going to figure out like, what's a blocker for whom?
- 25:24And like, what do I need to implement in order to like unblock people and like make sure
- 25:28they can use it?
- 25:28Is there a way for people to let you know which of those are really important to them?
- 25:32Like, for example, if there's some big project out there, it's like, we would love to move
- 25:36to rough, but there's this one, one plugin we're waiting on.
- 25:41Yeah.
- 25:41I mostly hear about it in issues.
- 25:43And there are a couple issues where it's like kind of a big GitHub issue.
- 25:49It'll be like implement this plugin.
- 25:51And a lot of people will come and like give it a thumbs up or whatever.
- 25:54We have pretty good coverage now, actually.
- 25:57Like, I mean, there is a long tail.
- 25:59Like there's a big ecosystem of like flaky plugins.
- 26:01You know, sometimes someone will come along and ask for a plugin that I haven't really like
- 26:06seen before.
- 26:06And then it's just a calculus of like, what do I want to prioritize?
- 26:09How much work is it?
- 26:11Yeah, exactly.
- 26:12Is this a super easy thing to do?
- 26:15Like, oh, the line is too long.
- 26:17That's easy.
- 26:17Or is it, you know, rewrite this?
- 26:19Yeah.
- 26:20This generator in this other interesting way.
- 26:23Yeah.
- 26:23That happened with, well, a lot of people want like, I don't know how to pronounce this library,
- 26:27but like Dargland, like D-Argland, Dargland.
- 26:30I don't know.
- 26:31Anyway.
- 26:31I would go with that as well.
- 26:32Yeah.
- 26:32Yeah.
- 26:33Dargland.
- 26:33Let's go with that.
- 26:34It's very popular, but I've looked at the source.
- 26:35It's pretty complicated.
- 26:36So like, I need to, you know, that's not something I can just like turn around in a day.
- 26:40But like, you know, I hear like what people want.
- 26:43And I mean, some of those migrations though, I didn't even know about them until they'd happened.
- 26:47Yeah.
- 26:48Yeah.
- 26:48Of course.
- 26:48People come, they submit issues.
- 26:50I look at their profiles.
- 26:51I see what they're working on.
- 26:52I get a sense for what the projects are.
- 26:53Right.
- 26:54So sometimes I know, and then I'm kind of fixing things knowing that hopefully it's unblocking
- 26:59them in different ways.
- 27:00But I think, like I said, I think the compatibility piece is like really huge.
- 27:03And I actually think that like black and eyesword and like the popularity of those things has
- 27:08made compatibility for me like a little bit easier because I can just like adhere to what
- 27:12they do.
- 27:13And then hopefully there's like no code changes.
- 27:16Yeah.
- 27:16They centralize around what like black is the truth.
- 27:19And then we'll, then we'll stop.
- 27:20We'll debate beyond that.
- 27:21But like, we're just going to accept black because it's no fun to go commas on the end
- 27:27of the line.
- 27:27No commas on the trailing thing in the list.
- 27:29You know, like that, those kinds of debates just go on and on.
- 27:32Yeah.
- 27:33I know.
- 27:33I think black kind of solves that by just making a decision for you and not everyone's
- 27:38totally happy with every choice, but it stops the debate.
- 27:41And that actually probably wins the day for most of them.
- 27:43One thing that's interesting here that I'm noticing about these projects in the large open
- 27:48source projects that have adopted rough, not all of them, surely, but many of them like
- 27:54Pydantic and Polars and so on themselves are adopting Rust.
- 28:00Do you see a synergy of those?
- 28:02Like, well, we're rewriting Pydantic core and Rust like Samuel Colvin is, or the folks behind
- 28:07Polars are like, that's the core of it is about Rust.
- 28:10And that's the RS on the end, I think.
- 28:13So there might be a little extra draw there, right?
- 28:15I think it's just more like, like spiritual alignment.
- 28:19Yes, exactly.
- 28:20Because it doesn't matter.
- 28:21No, it doesn't.
- 28:23But spiritually.
- 28:24But there's, yeah, there's a little bit of a bug.
- 28:27Sorry, bug in the sense of like, like once people start writing some stuff in Rust and
- 28:32improving their Python, they're kind of like more open to like, you know, trying out other
- 28:37things that are written in Rust and so on.
- 28:39So it's, I mean, that community has like been very interesting to sort of watch and be a
- 28:44part of the like Rust Python community.
- 28:46It still feels like pretty nascent, but there are, the tooling is actually like really great.
- 28:52And, you know, we could talk about that more, but like, you know, there was definitely like
- 28:57a bunch of initial setup for actually like distributing Rust, PyPI and making pip installable.
- 29:03But now that that's over, it all like just works.
- 29:05And I mean, I wouldn't say it's like requires no effort, but it's actually pretty amazing.
- 29:10Like how, like the degree of integration and how much you can do now with these tools like
- 29:15Py03 and, and MatcherIn and some others.
- 29:18That was one of the things that was really nice surprise for me as well as how easy it is to
- 29:22install, right?
- 29:23Like, unless you told me, unless it wasn't part of, you know, the elevator pitch, you know,
- 29:29the little one sentence subtitle on the project, like you would know from a interacting perspective,
- 29:34which is kind of exactly what you want.
- 29:36I also think that it's really, there's some value to having these popular projects adopt
- 29:40RUF because Martin and the audience, for example, says, I found out about Ruff by looking to see
- 29:45what FastAPI does, because presumably it's a ton of respect for FastAPI and Sebastian, his choices.
- 29:52So yeah, it's got to sort of create the snowball effect as well.
- 29:56So this portion of Talk Python To Me is brought to you by user interviews.
- 30:02As a developer, how often do you find yourself talking back to products and services that you use?
- 30:08Sometimes it may be frustration over how it's working poorly.
- 30:11And if they just did such and such, it would work better.
- 30:15And it's easy to do.
- 30:17Other times it might be delight.
- 30:19Wow, they auto-filled that section for me.
- 30:21How did they even do that?
- 30:22Wonderful.
- 30:23Thanks.
- 30:23While this verbalization might be great to get the thoughts out of your head,
- 30:27did you know that you can earn money for your feedback on real products?
- 30:31User interviews connects researchers with professionals that want to participate in research studies.
- 30:36There is a high demand for developers to share their opinions on products being created for developers.
- 30:42Aside from the extra cash, you'll talk to people building products in your space.
- 30:47You will not only learn about new tools being created,
- 30:50but you'll also shape the future of the products that we all use.
- 30:53It's completely free to sign up and you can apply to your first study in under five minutes.
- 30:58The average study pays over $60.
- 31:00However, many studies specifically interested in developers pay several hundreds of dollars for a one-on-one interview.
- 31:07Are you ready to earn extra income from sharing your expert opinion?
- 31:11Head over to talkpython.fm/user interviews to participate today.
- 31:16The link is in your podcast player show notes.
- 31:19Thank you to user interviews for supporting the show.
- 31:24One thing that's a little bit overlooked about why that adoption is useful is that it actually feeds back into the project in so many great ways.
- 31:34So, you know, for example, DAG sir adopted ROUGH and they have a really big Python monorepo with 50 or 100 separate Python modules or packages in there.
- 31:48And they filed like a bunch of issues about around how can we make ROUGH better for monorepos.
- 31:54And so now they can run ROUGH once and it runs over all their separate projects that can all have their own configuration.
- 32:00And that's like a really, really powerful thing.
- 32:03And something that like if I was just sort of sitting around like building ROUGH, like I don't know that I would have known to prioritize that or what it should look like.
- 32:11And so like actually like working with people who want to adopt ROUGHs and like figuring out what stops using it provides a ton of value to the project and just prioritization.
- 32:21Like a lot of the iSort stuff, I pushed on it a lot when I started because ROUGH does import sorting.
- 32:25So you can use it if you want in lieu of iSort.
- 32:28And we implement a lot of the same configuration options, not all the same.
- 32:33iSort just is like really configurable.
- 32:35So we went, we sort of implement them as they get requested.
- 32:37But anyway, I prioritize that stuff because a lot of people wanted it and they were coming to the issues and being like, hey, this would really help me adopt it, blah, blah, blah.
- 32:46So just like getting the feedback and like hearing what's blocking people, like that itself is like so valuable for the project.
- 32:52Right.
- 32:52And you have a lot of people involved in these larger projects.
- 32:54So they, and they have specific polished needs, right?
- 32:59Like there's a lot of people who work on pandas or FastAPI and those are mature code bases.
- 33:05It's not just a pet project, right?
- 33:07Yeah.
- 33:07Yeah.
- 33:08Those are very mature.
- 33:08Yeah.
- 33:09Yeah, exactly.
- 33:10That's good.
- 33:11But also it's a challenge.
- 33:12One other thing I would like to point out, you know, you started off by introducing rough saying, maybe people will be interested.
- 33:18I don't really know if they will.
- 33:20Maybe they will.
- 33:20That'd be cool.
- 33:21You know, 6.5, 6.4 thousand stars.
- 33:24That's a, it's a non-trivial amount of interest.
- 33:27That's a lot of love.
- 33:28Yeah.
- 33:29Yeah.
- 33:30Yeah.
- 33:30And like, I don't know.
- 33:32One thing that I guess I might feel weird, like highlighting all the big projects.
- 33:36Cause one thing that I really appreciate is just like anyone who's willing to try a tool
- 33:41like this.
- 33:41Sure.
- 33:42Like moving tools and trying new tools is like a big decision.
- 33:45I just like really appreciate everyone who says nice things about it or everyone who's
- 33:49like willing to give a try, give it a try, like no matter what they're working on.
- 33:53Yeah.
- 33:53It's not a platform to say that out loud.
- 33:55So hopefully people hear it.
- 33:57Yeah, absolutely.
- 33:58So the other thing I want to highlight about the repo here, not just the stars, but when
- 34:03I look at a project and I want to sort of assess, I really want to adopt this thing.
- 34:08Do I want to make this part of my dependencies or things or layers that I got to live with
- 34:13here?
- 34:13And if it goes sideways, I got to change something is, you know, how old is the project?
- 34:19How active is the project?
- 34:20And so on.
- 34:21So look, we started this podcast 40 minutes ago.
- 34:26The last commit was 52 minutes ago.
- 34:28Oh yeah.
- 34:30Sorry.
- 34:30Yeah.
- 34:31It's kind of.
- 34:32That's awesome.
- 34:32I mean, you're like, but you're looking here and it's then it's, it's yesterday.
- 34:36It's, it's last week.
- 34:37I want to point out there's just a lot of activity, 78 contributors.
- 34:41It's a very lively project and not just something that's cool, but you know, there's a lot of interest
- 34:45and energy in it, which I think is a very strong signal that it's something people should
- 34:51be comfortable adopting.
- 34:52Thanks.
- 34:52I appreciate you calling that out.
- 34:54I think I guess companies one, that's actually something that when I talked before about
- 34:58why would these big projects adopt this thing that like seems really experimental, that's
- 35:03actually something that comes up a lot is, and I'm not in the conversation, but obviously
- 35:07I'm sleuthing a little bit on the PRs.
- 35:09Right.
- 35:09And they're saying, well, it doesn't support X, but it's like really actively developed.
- 35:14And I'm like very confident that they will support that, you know, at some point.
- 35:18Yeah.
- 35:19And so like, just like having something that is clearly very actively worked on, I think
- 35:24is quite like appealing and comforting to people.
- 35:26Yeah.
- 35:26I actually like do feel bad saying this, but like one of my favorite, not favorite, but
- 35:31it kind of an interaction that happens on the repo is someone will file an issue and they'll
- 35:38say, this is actually also a bug that exists in the, let's call it the upstream implementation.
- 35:44So the existing Python version of that tool also has that bug.
- 35:48Right.
- 35:48Like Pyland or FlickAids or something like that.
- 35:50Yeah.
- 35:50It does this, but we think it's wrong.
- 35:52We disagree with it or something, right?
- 35:54Or there's an issue where, you know, the maintainer is like, oh yeah, this is broken.
- 35:58Yeah.
- 35:58Yeah.
- 35:58Okay.
- 35:59It's really not like the reason I tell that thing is like, I, you know, every project is
- 36:02different and like every maintainer, like most people, like everyone's doing this like
- 36:06for free, right?
- 36:07Like I'm not, I'm not here to like call out other maintainers, but I think it's a very satisfying
- 36:11interaction for people when, you know, they link to an issue it's been open for, for maybe
- 36:15for like years.
- 36:16And then I can actually just like fix it in like, like pretty quickly and ship a release
- 36:21in the same day.
- 36:22And like that, I think that's like a really like powerful thing that resonates with people
- 36:27a lot.
- 36:27It's just the feeling of like stuff getting shipped and like things getting fixed.
- 36:32And yeah, I'm like, you know, I'm working on this full time.
- 36:35So like, I'm fortunate to be able to do that.
- 36:37And like, I totally get it that like other projects are in different states and stuff.
- 36:41But I get a lot of, you know, and people are always super appreciative.
- 36:45And so it all just like funnels into, you know, giving me energy.
- 36:49Eddie has called you a commit machine.
- 36:51Literally every time I update my project dependencies, I'm guaranteed to see new stuff on Ruff, a new
- 36:56version of Ruff.
- 36:57I appreciate that.
- 36:58You know, it's, I do appreciate that.
- 37:00Like, yeah, I do try to write a lot of code, but you know, it's obviously not just, not just
- 37:04me and like the contributors, the contributors have been awesome.
- 37:07And I think, I mean, one thing I'm particularly impressed by is just the number of, number of
- 37:12people who, like, I don't even know if I always believe them when they say this, but like
- 37:16just the number of people who are like, this is my first time writing Rust or like, I'm
- 37:21really not good at Rust or like, blah, blah, blah.
- 37:23And hear something amazing.
- 37:25Yeah.
- 37:25And they just like make like great contribution.
- 37:27They're like, Hey, I'm trying to learn Rust.
- 37:29And I obviously love that stuff.
- 37:31Like for interested in learning Rust, I actually think Ruff is like a great, a great project
- 37:35and like a great place for that.
- 37:37But I mean, there are people who are working on stuff, especially the stuff that I just
- 37:41like, it's like big things I can't like focus all my time on and just like having great
- 37:45contributors who are like really, you know, like thoughtful and like prolific.
- 37:50Every project is lucky to have people like that.
- 37:52How old is the project?
- 37:54When did you start it?
- 37:55In August.
- 37:55Yeah.
- 37:56So it's not that old.
- 37:57My brain is like melting, but it's somewhere.
- 37:59Yeah.
- 37:59I think it's like, like somewhere between four and six months.
- 38:02Okay.
- 38:02Did you say you're working on this full time as like your full time job?
- 38:06Yeah.
- 38:06Okay.
- 38:06And so how's that work?
- 38:08Is that GitHub sponsors or are you employed by someone to completely work out?
- 38:12What's the story?
- 38:13That sounds awesome.
- 38:13Still figuring out, you know, I'll probably share more on that soon.
- 38:17Okay.
- 38:17I don't know if sponsors enabled right now.
- 38:19Still figuring out exactly what, like how I want that all to evolve.
- 38:22Right.
- 38:22I am working on it full time.
- 38:24I don't anticipate that changing in any way.
- 38:25Like I, I'm really happy in getting so much out of this and yeah, I think there are a lot
- 38:31of ways to make it work.
- 38:32And if not rough, I want to be working on like other Python tooling.
- 38:35So, you know, I think there's like more stuff to come.
- 38:37Well, it certainly is neat tooling.
- 38:39Let's go, let's go through the GitHub page here a little bit.
- 38:42So we've talked about the speed a couple of times.
- 38:45We talked about ways in which that happens.
- 38:47You know, Rust is an important part, but it sounds like it's not the only reason that it's
- 38:52fast.
- 38:52You have a chart with the obvious like a little asterisk caveat benchmarks.
- 38:58It's reproducible, you know, like all the stuff's in the readme, but yeah.
- 39:02That's fast in this situation, but my situation is different in which case, you know, such
- 39:07and such.
- 39:07Right.
- 39:07But for some large code base, we've got rough in 0.3 seconds, autoflake at six, pylint at
- 39:16over 60 seconds, just barely.
- 39:18This is on the CPython code base from scratch, which is pretty ridiculous.
- 39:23And I already told you the numbers.
- 39:24I don't have a millisecond number, but it appears to be instant on 20,000 lines of Python code
- 39:31that I wrote.
- 39:32And it found some issues, which I thought would already be discovered.
- 39:35So that's pretty excellent.
- 39:36Nice.
- 39:37It's nearly Python 3.11 100% compatible, right?
- 39:41You said the one major language feature is the match statement, but other than that, it's
- 39:46compatible, right?
- 39:46Correct.
- 39:47Yeah.
- 39:47Okay.
- 39:48It supports some of the other language features like that are maybe less high profile, like
- 39:52the parenthesized width statements and stuff like that.
- 39:55But it doesn't support the pattern of structural pattern matching yet.
- 39:59Got it.
- 39:59So it's got the autofix support near parity with the Flake 8 rule set, which is cool.
- 40:04You talked about the way that you keep the performance fast, but still have parity with Flake 8 is
- 40:11you have native re-implementations of the Flake 8 plugins.
- 40:14That's right.
- 40:15Yeah.
- 40:15So we re-implement everything in Rust.
- 40:18And a lot of the time, that's like me or whoever's working on it, like looking actually at the plugin and
- 40:24like the logic it uses and trying to mimic that in a high fidelity way.
- 40:29And often we'll like try to use the same test suite and really try to make sure that we're compatible, except in cases where we think there is like an actual sort of factual error.
- 40:39Yeah.
- 40:39Why rough is fast?
- 40:41The plugin stuff, there's a lot of interesting stuff to say about like plugins, because I think Rust is a big part of why rough is fast.
- 40:50But there are a couple of other big pieces.
- 40:53So we take a lot of care in the code base to like only do necessary work, if that makes sense.
- 40:59So, you know, we support 300 something rules, but depending on which exact rules you have enabled, we'll skip a lot of unnecessary work.
- 41:07Okay.
- 41:08That can help a lot.
- 41:09So, you know, it's basically tailored to how much you're using it.
- 41:12So like if you're not using it as an import sorter, you know, there's a bunch of stuff that we get.
- 41:16It's just how I would think about it.
- 41:17But the other like really big one is because everything is sort of implemented in like one system.
- 41:24There's a lot of work that would normally be duplicated between a lot of different tools that can actually just be done once.
- 41:30So the way to think of that is like if you look at like flake 8 with flake 8 doc strings, there's maybe one example which uses PyDoc style.
- 41:40Sorry, I know it's like a huge like a tree of tools.
- 41:42You know, if you add that plug in.
- 41:44So PyFlakes is going to parse your source code and turn that into an AST.
- 41:48And then PyDoc style actually has basically its own parser that will go back over the source code and look at all the tokens and extract the doc string.
- 41:56And if you have a bunch of different tools, like some of them will share that abstract syntax tree.
- 42:01But a lot of them end up doing work that other tools are also doing.
- 42:04Right, because they can't count on necessarily that being done or the plug in system doesn't provide work that's already been done to them.
- 42:12So they got to start over anyway. Right.
- 42:14Yeah. Or they might want to do things in like a slightly different maybe you have like three different plugins.
- 42:18Like I guess one example is a lot of plugins like need some way to tell if a function is like public or private.
- 42:24And it's not like super complicated, but you know, it's not like totally trivial.
- 42:28Like you need to account for functions that are in inside of classes.
- 42:32Like is it a public method or private method to account for functions that are inside of other functions.
- 42:36Right. So there's like a lot of rules actually for like determining what's like public and private.
- 42:41And, you know, you might have one lint rule that's like all public methods need to have doc string.
- 42:46And you might have another rule that's like all public methods need to have type in two things.
- 42:50And if you have two separate plugins that are doing that, they both need a way to actually like extract that information.
- 42:57And, you know, it's not necessarily the case that like it'll be way faster to do it with one pass and one.
- 43:03I think it will. It may not be like or as magnitude.
- 43:06But the other thing is you have a lot of like consistency. So like, you know, it's defined in one way.
- 43:11You're not going to be at the whims of like small decisions that the tools have to make.
- 43:16For us as like maintainers and like building rough, you know, there's a lot of stuff you like don't have to implement multiple times.
- 43:21Right.
- 43:22I can leverage that and like go and implement other lint rules.
- 43:24And I don't have to like figure out from scratch, how do I determine like what public and private in it?
- 43:28How do I like extract all the doc strings from a file? Like we already have all that infrastructure.
- 43:33So there's kind of like economies of scale, I guess, to like implementing new stuff.
- 43:38Like it sort of snowballs a little bit, like the tool gets more powerful, it gets kind of easier to do things.
- 43:43I mean, I think you'd be surprised like how much of building a tool.
- 43:47I don't know about you personally, but like I was surprised by like how much of building a tool like this is just done.
- 43:52It's like settings and like configuration and like how do people express their settings?
- 43:58What is the command line interface look like?
- 44:00How do you find all the Python files in a directory?
- 44:03Like it sounds trivial, but like, you also want to respect like getting more is do you want users to be able to ignore files?
- 44:09Like there's a lot of rules.
- 44:10And so again, it's like if I look at a new Python tool, you know, that wants to go off and implement something,
- 44:15they might have to implement all that stuff themselves.
- 44:17But for us, it's like we have all that infrastructure in place.
- 44:21And so if we want to build a new fun piece of functionality, it's just sort of defining the rule and we get all this other stuff for free.
- 44:27Yeah, you can definitely build on the layers that are in place because it's all together.
- 44:31That's cool.
- 44:31Yeah.
- 44:32All right, let's look through here a little bit.
- 44:34Like I said, there's the testimonials from the different projects like Brian from Bokeh or Sebastian from FastAPI and whatnot there.
- 44:43But let's start with installing it.
- 44:45Like I said, you would know that this wasn't just a Python tool you could use.
- 44:49Pipinstall ruff. That's the way to go.
- 44:51But when I installed it, I didn't pip install.
- 44:54I pip x installed it.
- 44:56Are you a fan of pip x?
- 44:57Yeah, I use pip x.
- 44:58Yeah, to me, it seems like rough is something I want to run on different projects.
- 45:02And I just kind of want rough in my tool set.
- 45:05And so I pip x installed rough.
- 45:08What do you think?
- 45:08Good idea.
- 45:09Is it better to put it, say, like in a per version of per project?
- 45:12Like everything.
- 45:13I think it probably depends.
- 45:15Yeah.
- 45:15I mean, I definitely saw a lot of stuff at pip x.
- 45:17I think the one thing that I, the one issue with rough, and I guess I recognize wines can be annoying for some people, for sure.
- 45:25Like we released a lot.
- 45:26And so if projects don't pin their dependencies, then they can start to see like new errors as we add new rules, which I guess in some sense is like a breaking change.
- 45:36But I don't really consider it as such.
- 45:38It's like, you know, they have the like, let's say they have the like, like a simplify rule set enabled and we add a new rule and that gets turned on for them.
- 45:47So anyway, the point is like people, I guess I recommend pinning rough if you're using it for a project, which I mean, with pip x, you're just going to stay on one burger.
- 45:55Right.
- 45:55So you run pip x, you upgrade dash all or whatever, or upgrade that thing.
- 45:59Yeah, exactly.
- 46:00It's doing it to a sense.
- 46:01It's kind of a pin, but it's pinned globally and it gets upgraded globally and that not, not per project.
- 46:06Yeah.
- 46:06Yeah.
- 46:07Yeah.
- 46:07For me, that's kind of okay.
- 46:08But if I was on a large team, you know, lots of people who were working on it, you might want to control that more.
- 46:13I can see that.
- 46:14We have a homebrew distribution and a condo distribution on condo forage.
- 46:20And then I did those and then there's everything else was done by other people.
- 46:25So I'm like, which is cool, but most of me, I'm like less familiar with them.
- 46:28Yeah, sure.
- 46:29I mean, I don't know.
- 46:30Publishing on homebrew and condo forage was like pretty interesting experience for me.
- 46:33I've never done that and I didn't actually really know that.
- 46:36much about how those worked.
- 46:37I think so.
- 46:38Yeah.
- 46:38Yeah.
- 46:39That was cool.
- 46:40Hopefully it's useful for people.
- 46:41There's definitely some complexity with like the packaging and release stuff, which I don't
- 46:46know if you want to talk about that or not, but you know, because we're building Rust, there's
- 46:49like a couple of things that we need to do that are a little different from a standard Python package.
- 46:53Maybe just touch on it a bit because what you deliver is a wheel, right?
- 46:58But it's got the compiled Rust bit for me on my ARM 64 macOS build, right?
- 47:04Yeah, that's right.
- 47:05Yeah, that's right.
- 47:06So basically it just means we have to do the wheel in some sort of pre-compiled version of
- 47:11the package as opposed to just giving you the source code.
- 47:14And like if I just gave you the source code and not the wheel, you'd actually need to have
- 47:18Rust installed because you'd have to actually build the thing and install it, which is of course
- 47:23an extremely unreasonable expectation for the kind of people who are using this for the most part.
- 47:29Yeah, but before the wheels really became popular, that was part of the step, right?
- 47:33It would build for you.
- 47:35Yeah.
- 47:35Yeah.
- 47:35Or it wouldn't build for you, which was frustrating, but that was part of the step, right?
- 47:39Yeah.
- 47:39Yeah.
- 47:39We just build wheels for all the platforms that I know of.
- 47:43It's not something.
- 47:44Is it all CI/CD?
- 47:45You just push it to some branch and magic happens and then wheels start appearing in places.
- 47:50Whenever I cut a release on GitHub, like I just use like GitHub releases, basically.
- 47:54I just use GitHub releases.
- 47:56It kicks off our release job and then that's all through GitHub
- 47:59action.
- 47:59So it just has a big matrix, right?
- 48:01Of all the different operating systems.
- 48:03We only have to build, thankfully, we only have to build one wheel per operating system.
- 48:09We don't have to build one wheel per Python version, which is something that can happen sometimes.
- 48:13And then you have like a mass explosion of number of wheels.
- 48:16That's all facilitated with a tool called Maturin, which I'm a big fan of, which is,
- 48:21it's sort of like, I don't know, like set up tools and a bunch of other stuff bundled together,
- 48:26but specifically for shipping mixed Rust Python.
- 48:29So I don't actually have to like do anything for the host part to make that work.
- 48:33Yeah.
- 48:33My pyproject.tomol has, you know, Maturin at the top and I have a Rust project and I call
- 48:40Maturin build and it creates a wheel.
- 48:42It's all like, I don't know.
- 48:44I think it's like super cool.
- 48:45That works.
- 48:45Yeah, that sounds super smooth and super neat.
- 48:49Yeah.
- 48:49And like I said, as a consumer of it, also very smooth, right?
- 48:53It was still quickly.
- 48:54I didn't have to wait on some build.
- 48:56I didn't need build tools or config that I don't care about or don't use.
- 48:59I'm pretty sure I do have Rust, Rust C as a CLI option I can use here, but you know,
- 49:05you don't want to depend on that, right?
- 49:06No.
- 49:07So you run it on the command line, you say rough and you point at either a file or a directory
- 49:13or some pattern of files, right?
- 49:15Yep.
- 49:15Star type of thing, which is cool.
- 49:18And that gives you the output.
- 49:20You can also do it with a --watch and just run it constantly, which is pretty cool,
- 49:25right?
- 49:25It's fast enough that basically as you save it, if there's problems that'll just appear
- 49:30in the terminal, right?
- 49:31Or wherever you run it.
- 49:32That's kind of a funny example because I based, or it's a good example because I,
- 49:36I'm pretty sure I took that exactly from probably from TSC, which is the TypeScript compiler.
- 49:43Yeah.
- 49:43They have a watch setting and I like how it works.
- 49:46And so I wanted that for, so it's just a, that's a very literal example of me looking at
- 49:51another tool from like another space and being like, oh, that's really nice.
- 49:55And I wish you had that other tools like it too.
- 49:57Yeah.
- 49:57I suppose it's terrible and not terribly difficult to implement, right?
- 50:00You take the pattern and you put a watch in the OS watch implementation and you say,
- 50:06call me back when something changes and because it's fast, it just reruns, right?
- 50:09But it's still,
- 50:09Yeah, it's exactly right.
- 50:11It's very handy though, that, that it's there.
- 50:13The other thing that's interesting is you can do it as a pre commit hook, which is nice.
- 50:18Yeah.
- 50:19That works pretty well for people.
- 50:20I think a lot of people seem to use it.
- 50:22I'm glad that it exists.
- 50:23Yeah.
- 50:24A little bit of a weird setup because maybe it's actually not that interesting to talk
- 50:27about, but it's in like a separate repo for sort of like, I can't even really remember.
- 50:31Okay.
- 50:32Interesting.
- 50:34Now to configure it, it has a, let's say comprehensive CLI set of options.
- 50:39I can't remember maybe 15 or so command line options.
- 50:42You can pass it, but you can also put, put it into the pyproject.toml with things just
- 50:48like tool.rough and then you can put your various settings in there.
- 50:51Right.
- 50:51So it just sort of integrates along that, or you can have a ruff.toml and then put it in there.
- 50:57Yeah.
- 50:57So that's something that I took basically from hatch.
- 51:00So within hatch, you can have a pyproject.toml or a hatch.toml and the hatch.toml kind of like
- 51:07tests the configuration.
- 51:08Like if you use a ruff.toml, you don't need to have like tool.rough at the top and stuff like that.
- 51:13Yeah.
- 51:13I think one thing that I'm quite happy that we have is like the configuration is very like type safe.
- 51:21So if you try to like, you know, so that, that line select equals EF, those are like error,
- 51:26like rule codes that are defined in rough.
- 51:29And so if you put, if you replaced F with some string that wasn't, you know, a real rule,
- 51:34you'll get an error immediately saying that, you know, your pyproject.toml had invalid,
- 51:38was invalid in like these ways, blah, blah, blah.
- 51:40Interesting.
- 51:41Okay.
- 51:41And similarly, we create what are called like JSON schemas or the configuration.
- 51:47If you're in PyCharm and you open up like a pyproject.toml and you type
- 51:51tool.rough, it'll actually like show you all the options.
- 51:54It'll actually surface the documentation we have for the options too.
- 51:57Oh, nice.
- 51:58Which is pretty cool.
- 51:59Yeah.
- 52:00I'd like more tools to do that.
- 52:01Cause I think it's like super useful.
- 52:03I think poetry has it, but not too many others do.
- 52:06You can get it in VS Code as well, but you need to install an extension.
- 52:11It's called like even better.toml, I think.
- 52:13Right.
- 52:13Okay.
- 52:14But I'm happy with those things.
- 52:15I think it makes it like, I think small things like that add up and glad we're able to do them.
- 52:20Yeah.
- 52:21When I looked at the configuration settings, like the exclude directories and various other
- 52:25things, like that's kind of a lot to put on a command line.
- 52:27It would be nice if you could just put it and say ruff.toml or pyproject.toml.
- 52:31And then when you just type rough the thing, it, it sees that and it uses it.
- 52:35Right.
- 52:35Yeah.
- 52:36I've kind of like intentionally like not put a lot of these arguments on the command line.
- 52:40Like for that reason, like you can imagine taking everything here and exposing it on the command
- 52:44line, but the command line really just deals with like how should the thing execute and not like,
- 52:49I don't know, what should the max complexity be?
- 52:51Yeah.
- 52:51Yeah.
- 52:52Yeah.
- 52:52Yeah.
- 52:52Yeah.
- 52:52I think that's fair.
- 52:54Like put the common stuff on the command line and then say, and if you need to go crazy,
- 52:59here's your --config, pass that in and put it in there.
- 53:03Right.
- 53:03Yeah.
- 53:03Yeah.
- 53:04Yeah.
- 53:04Yeah.
- 53:04One thing that I did want to talk about and you kind of touched on, there's a bunch of the
- 53:08command line arguments.
- 53:09One of the things I did want to talk about is the editor integration.
- 53:12There's a huge bunch of rules here.
- 53:14We got to scroll through on the homepage to get, get down to it, which is awesome.
- 53:18That are no, no, it's good.
- 53:19I mean, these are like all the things that checks that I don't have to think about anymore,
- 53:22which is great.
- 53:23Eventually though, geez, I forgot it was this long.
- 53:28Eventually though it has plugins or maybe that's not quite what I said.
- 53:33It has a, an extension of a VS Code and it has ways to basically add it as a command
- 53:40to PyCharm, right?
- 53:41Which is, those are both awesome editors that are kind of very friendly to thinking about code
- 53:46formatting and exposing the errors that this would as well.
- 53:50So that's great.
- 53:50You might want to just talk about that just real quick.
- 53:52Yeah, totally.
- 53:53So yeah, we have a VS Code extension.
- 53:55That was my first time writing a VS Code extension.
- 53:57And actually the, these extensions use, or they conform to something called the language server protocol.
- 54:03And effectively that's sort of like a standard, I believe I'll probably get like a bunch of
- 54:08the history wrong, but I believe it's Microsoft that like publishes and maintains that.
- 54:12It's that.
- 54:13The nice thing about that protocol is you can actually use like the lot, like most, almost all
- 54:19of the code behind the VS Code extension is actually published as a language server.
- 54:23Yeah.
- 54:24Rough LSP.
- 54:25And what that means is you can actually get like the exact same behaviors in all sorts of different
- 54:29editors.
- 54:30It's not confined to VS Code.
- 54:32So if you use like NeoVim or like sublime text or whatever else, those all support this standard
- 54:38protocol and they all have ways to tap into that rough language server protocol.
- 54:44So we have sort of like the standalone LSP, which we have instructions for like sublime and,
- 54:51and you know, other tools.
- 54:52And then we have the actual extension, which is published on the marketplace.
- 54:56And those are things I definitely want to like keep supporting.
- 54:59And I view them as like official arms, right?
- 55:02Of the project, which I think is nice.
- 55:04So people should know that like, you know, those are official and like, I pick bugs and
- 55:08man, and all that kind of stuff.
- 55:09Nice.
- 55:09And then for PyCharm, you just add it as an external tool and then you have the rough command
- 55:15around or for both of these, if you prefer, you just add it as a pre-commit hook.
- 55:19Yeah.
- 55:19That's also.
- 55:19Yeah.
- 55:20That's right.
- 55:20Yeah.
- 55:20That then like, as you interact with it, it'll run the pre-commit hook as well.
- 55:24If you try to check things in.
- 55:26Super cool here.
- 55:27I think this is a neat project.
- 55:29I ran it into my project and I thought, you know, everything is pretty much good to go.
- 55:36Where, you know, when I'm using PyCharm, for example, it'll often tell me many of these things.
- 55:42Like it'll say there's a local variable that's unused or it'll automatically remove unused imports.
- 55:47And yet I'm looking at 331 issues.
- 55:51108 are potentially fixable with the --fix option.
- 55:55So it sounds like there's still a lot of value to like make that part of my tool chain.
- 56:00Yeah.
- 56:00I mean, you know, and feel free to have some of your own opinions about which of those rules actually matter.
- 56:05Sure.
- 56:06And I suspect you can disable them in your config file, right?
- 56:08You can say this rule I don't care about.
- 56:10Yeah.
- 56:10And this is another sort of compatibility thing.
- 56:12Like we, API for actually like turning rules on and off is like essentially identical to the flight gate API.
- 56:19So that's also useful for people migrating over.
- 56:21So the no QA, is it the like comment?
- 56:24Yeah.
- 56:24Like comment no QA is one option.
- 56:26Yeah.
- 56:26We respect.
- 56:27Yep.
- 56:27We respect those too.
- 56:28We also respect like, I sorts action comments.
- 56:31So yeah, we, we like do a lot of stuff to try and
- 56:35maintain compatibility.
- 56:36Nice.
- 56:36Maybe another like interesting thing in that vein is that we ship a tool called
- 56:40flight gate to roughs, which does sort of what it sounds like.
- 56:45So you point it to a flight gate configuration file and it spits out a Tommel for rough,
- 56:50you know, that's compatible.
- 56:51And it also tells you if there were things in the file that we don't support, which is useful too.
- 56:55Like, oh, hey, you're using these rules.
- 56:57Those actually aren't implemented yet.
- 56:58Yeah.
- 56:58That's also maintained as like part of the project.
- 57:00So, you know, I recommend checking it out.
- 57:02Excellent.
- 57:03Well, Charlie, I think we're getting short on time, but not short on topic.
- 57:06There's a whole lot more to dive into.
- 57:08I think it's, it's really cool project.
- 57:10I think it's new.
- 57:12Are we gonna do a big WASM section?
- 57:12No, I'm kidding.
- 57:15I'm kidding.
- 57:15We don't have time for that.
- 57:16We could do a WASM section.
- 57:18We even have some great chat GDP questions in the audience.
- 57:22I don't necessarily think that there's time for those, unfortunately,
- 57:25but there is one final question that I want to ask.
- 57:27It's kind of inspired by the audience, but I think it's good for everyone.
- 57:30Jean Gabriel asks, is there a roadmap or timeline for rough development out there?
- 57:36Like what's next basically?
- 57:38Like, I guess the short answer is no, like there's not like a published
- 57:42timeline, unfortunately, like most of this stuff exists in my head and in issues.
- 57:47Like everything happens on issues.
- 57:49Like we're just talking a lot on issues.
- 57:51Yeah.
- 57:51I'll maybe talk a bit about like the things that I'm thinking about.
- 57:54So one is fixing like the structural pattern matching issue.
- 58:00And so like getting full like Python compatibility, which it's sort of like one bug, but then unlocks
- 58:06us doing what I hope will be like a stable release, even if that's not that much changes.
- 58:10And it's just kind of, you know, the marketing of it, but hopefully we'll fix that.
- 58:14And then we can do like a stable release.
- 58:15The, there are two other kind of big things on my mind.
- 58:18So one is this is like a really big project, but not, not rough.
- 58:23The thing I'm about to talk about, but, I want to extend rough to do like full code auto
- 58:27formatting so that people could use it in lieu of black.
- 58:31If they wanted to think it's like a really natural fit for what rough is doing.
- 58:36And a lot of people asked about it.
- 58:37The way that that will, there's an issue where we talk about this, like on the repo, it's not
- 58:42like some big secret reveal, but, the way that I think about that, like, like with all things is
- 58:47I want it to be like, sort of incrementally adoptable.
- 58:50Like right now you can use rough with ice or.
- 58:52Or you can use just rough, or you can use rough to your input sorting, but like not as a linter.
- 58:57Like you can kind of pick and choose like what you want to use.
- 58:59And I view like the auto formatter is the same way.
- 59:02Like I fully expect that people will keep using rough and black, but it's just like the kind of
- 59:07functionality that makes a lot of sense, given what we're already doing and like the way that the
- 59:11project's evolving.
- 59:12So I need to like, and you be careful because like, it's like that blog work.
- 59:16And so I'm not like saying exactly when that will be done, but I do want to start working on it.
- 59:21And then the other thing, which is maybe like a little bit less exciting to other people.
- 59:24And it's like, you know, I think at some point I'd like rough to get to a world where
- 59:28it kind of stands alone a little bit more.
- 59:30It isn't viewed quite as much as a compatibility as this compatibility layer.
- 59:34Like right now, all the rules kind of map back to like, Hey, or other tools.
- 59:39And when you're using rough, you're kind of thinking in the mindset of those other tools,
- 59:43like what are the rules and how do I configure them at some point in the future?
- 59:47I'd actually like, you know, rough to sort of have its own API, like own indexing of the rules.
- 59:51And to view that as kind of a compatibility layer that will not go away.
- 59:55Like this won't put a burden on users, but I'd like to get
- 59:58to get to a point where like conceptually, a lot of this stuff is like first class and rough.
- 1:00:02And it's not viewed as re-implementations of other extensions, which I think will enable us to do a lot of cool things.
- 1:00:08But I'm hopeful that I'm doing that in a way that has no disruption to users.
- 1:00:12So we'll continue to support the existing API and such.
- 1:00:14Yeah.
- 1:00:15Yeah, exactly.
- 1:00:16Very exciting.
- 1:00:17Very exciting.
- 1:00:18Well, congratulations on a project that people seem to love.
- 1:00:21It's got a lot of traction and definitely doing some cool stuff.
- 1:00:24So before we get out of here, though, final two questions.
- 1:00:27If you're going to write some Python code, what editor are you using these days?
- 1:00:30I use PyCharm for everything.
- 1:00:32And that includes Rust.
- 1:00:33But I do all my Rust and my Python and PyCharm.
- 1:00:35Nice.
- 1:00:36Is there a cool plugin that basically adds Rust support to?
- 1:00:39Yeah, there's just an official IntelliJ Rust plugin.
- 1:00:42Got it.
- 1:00:43Nice.
- 1:00:43Works really well.
- 1:00:43I've used IntelliJ for that platform for Dart and Flutter, but I haven't tried to plug Rust into it.
- 1:00:50But yeah, it does a lot of things.
- 1:00:52Cool.
- 1:00:52And then notable PyPI package, something out there.
- 1:00:55You've named a couple that do the Rust integration nicely.
- 1:00:58But anything you want to give a shout out to?
- 1:01:00Yeah, I really want to give a shout out.
- 1:01:01I've already mentioned it a few times.
- 1:01:02I think if you're interested in doing Rust Python stuff, you should really look at Matrin.
- 1:01:06Matrin.
- 1:01:07All right.
- 1:01:07M-A-T-U-R-I-N.
- 1:01:09It just makes the publishing really easy.
- 1:01:13And you still have to learn Rust, which is not easy.
- 1:01:15I mean, I do.
- 1:01:16It's worthwhile, I think, but it's not easy.
- 1:01:18But it makes the publishing Rust code to PyPI, or PyPI, sorry, really easy.
- 1:01:23Awesome.
- 1:01:23Well, great recommendation.
- 1:01:25Thanks for being here.
- 1:01:26Final call to action.
- 1:01:27People want to get started with Rust.
- 1:01:28What do you tell them?
- 1:01:28The main thing that I would like to say is if you're interested in contributing,
- 1:01:32even if you don't know that much Rust and are interested in learning,
- 1:01:36I'd love to see you on the repo, and I hope it's a place that people feel really welcome
- 1:01:42to come and contribute, even if they are 100% certain if their code is right or anything like that.
- 1:01:47So definitely really excited to have more contributors and have more people coming into the project.
- 1:01:52And of course, you should also try using it yourself.
- 1:01:55All right.
- 1:01:55Excellent.
- 1:01:56Well, thanks for being here.
- 1:01:57It was a great conversation with you.
- 1:01:59Yeah, thanks so much for having me.
- 1:02:00It was a really cool opportunity.
- 1:02:02I appreciate it.
- 1:02:04This has been another episode of Talk Python To Me.
- 1:02:06Thank you to our sponsors.
- 1:02:08Be sure to check out what they're offering.
- 1:02:10It really helps support the show.
- 1:02:11Join Cox Automotive and use your technical skills to transform the way the world buys,
- 1:02:17sells, and owns cars.
- 1:02:18Find an exciting position that's right for you at talkpython.fm/cox.
- 1:02:24Earn extra income from sharing your software development opinion at user interviews.
- 1:02:29Head over to talkpython.fm/userinterviews to participate today.
- 1:02:34Want to level up your Python?
- 1:02:36We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:02:40Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:02:45And best of all, there's not a subscription in sight.
- 1:02:48Check it out for yourself at training.talkpython.fm.
- 1:02:51Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:02:56We should be right at the top.
- 1:02:57You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct
- 1:03:03RSS feed at /rss on talkpython.fm.
- 1:03:06We're live streaming most of our recordings these days.
- 1:03:09If you want to be part of the show and have your comments featured on the air,
- 1:03:13be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:03:18This is your host, Michael Kennedy.
- 1:03:19Thanks so much for listening.
- 1:03:20I really appreciate it.
- 1:03:22Now get out there and write some Python code.
- 1:03:23I'll see you next time.
- 1:03:44Thank you.