Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 37, recorded July 31st, 2017. I'm Michael Kennedy.
And I'm Brian Okken.
And we've got a bunch of sweet stuff lined up for you.
Brian, let's talk about contributing to Python.
If there's something in CPython itself we want to change, and we don't like how it works, maybe we just go change it.
It is open source, right?
Right, it is open source. And there is and has been a developer's guide for a long time for CPython.
But the URL has changed recently. I think I saw that recently.
But it's at devguide.python.org.
And I bring it up mostly because the URL changed, and I like that URL.
But also, it is how to contribute to Python.
But I was looking over the initial page where it drops in.
And there's some really cool links in there.
And one of them is just for everybody.
It's how to contribute to open source.
And another one is building welcoming communities.
And those are both at opensource.guide.
But they're pretty good articles.
I also liked basically the structure of some of the getting started.
They have a whole bunch of, I think it's a good onboarding thing.
Even if you're not going to contribute to CPython, I think it's a nice outline of things to include in any large open source project to try to get people onboarded fairly quickly.
Yeah, for sure.
We've got, like, here's how you propose changes to Python itself.
They've got some nice things that take you through the whole, like, get flow style.
You know, the lifecycle of a pull request, running and writing tests, talking about coverage.
You know, there's a lot of good stuff here.
Yeah, and talking about the issue tracker.
And apparently there's an experts index, which is kind of native, like, who do you send issues to.
And then even things like how to run the tests and stuff.
So it's nice.
Yeah.
Yeah, very nice.
Cool.
So if you have an idea for CPython, the thing is still changing a lot.
Like, we just covered recently the 362 changes.
And that was pretty extensive for just a little, you know, tiny release to, like, basically a maintenance release.
So how would you like to rule over your shell, Brian?
Rule over my shell.
Yeah.
In fact, not just ruling over your shell, but over many of the shells.
Like, even the shells that are in the outer kingdoms.
So the thing that I want to talk about next is called Sultan.
And it says, command and rule over your shell.
And so basically you can run shell commands using this library, this package called Sultan in a Pythonic manager.
So the simplest thing, like, let's suppose you want to install tree.
So you can type tree and you get this cool, like, ASCII hierarchical view of your files.
And you would just say, you know, pip install Sultan.
And then you would say, you know, pip install Sultan.
And then you would say, create a Sultan object.
And you can say, Sultan.sudo yum install tree is a string.
And then say, dot run.
And it will actually go and it will run that command as sudo on your system.
Right?
That's pretty cool.
And you can do things like work with aptitude or yum or ls or all the shell commands.
Right?
And they also have a way to work with it inside of a with block, a context manager, so that it can clean up with itself.
It runs a slightly different command that I think has some sort of better cleanup.
I don't actually know all the details with yum.
So anyway, it's pretty cool.
It even works remotely.
So I could, like, say, Sultan.load and give it a host name and say to do that as sudo and then run that remotely on the server.
And if there's any errors or whatever, it brings all that information back and prints it out for you in the warnings, I think.
I think it would be useful.
I think it right off the bat, some of the automation stuff that just large projects have, like build scripts and whatever.
I'd like to have them in Python, but sometimes I don't really know how to do it within Python itself.
But this is kind of neat.
I'll have to check this out.
Yeah, it's pretty cool.
I think it's pretty focused on the use case that, you know, people have, like, running stuff over SSH, remote servers, a lot of shell stuff.
But if you find yourself doing that a lot and you want to do more of it in Python, here's a pretty cool library.
It's really simple.
So what is yum?
Yum is a package manager.
I don't remember which distribution it's for, but, like, Ubuntu has aptitude, you know, like apt-get.
Yum is for some of the other distributions.
For some others.
Okay.
Got it.
Yeah, I don't remember.
I probably just haven't run into that yet.
Yep.
Okay.
It's tasty.
Okay.
Next, I just want to talk about a tool that helped me a lot recently.
And I've been working on the book, which I'm not working on it anymore because it's turned into my editor.
I've been using Sublime to write it and write all the code for it.
But one of the things I wanted to do was to, I got harassed by not being PEP 8 compliant in a couple places.
So I wanted to quickly go through and just check everything.
Once, of course, I can use Flake 8 just on the command line.
But once I know that there's a bunch of files with errors, what's the fastest way to go fix them?
And for me, it was a Sublime Text plugin called Flake 8 Lint.
And I know there's a lot of Sublime Text linters out there.
But this one, like, did everything I needed it to do just right off the bat and was super easy.
It just installed it and it just worked.
So I highly recommend Flake 8 Lint.
It's got all the, it's got Flake 8, of course, and it's also got PyDoc style and some naming conventions, import order and stuff.
Yeah, I think having these automated tools makes tons of sense, right?
Like, your editor should do as much of the work for you as possible.
So definitely a good recommendation there.
So one example is I would bring up, if I knew that there was a directory with a bunch of files that had problems,
I would bring it up, open up a file.
And the default, I didn't ever change it.
The default is just to check it on save.
When I would save the file, it would check everything and then also pop up a pop-up window with all the errors.
So I could, if I could just hit enter, it would take me to like the very first error and I could just walk through all the errors.
It was great.
Nice.
And it's not just, just purely following like the PEP 8 rules.
Like, for example, it has a cyclomatic complexity checking, which is pretty sweet.
So that's like, hey, I've got a highly, highly nested 500 line method.
What's wrong with that?
It only has 20 if blocks, loops, whatever.
It would complain about that if it goes over 10.
That's cool.
All right.
So how would you be like, how would you like to, you know, travel time and be sucked into, say, like a magic wormhole?
I'm pretty excited to hear about magic wormhole.
Magic wormhole is pretty cool.
Maybe you guys have heard of this.
So the problem magic wormhole is trying to solve is I want to get things, be this text, be this a small file, be this a huge file from one computer to the other safely.
So encrypted in a way that other people can't get to and things like that.
So magic wormhole is basically a command line thing where you just type wormhole and it will come up with like a code that your computer has.
Right.
So you say, I want to create a wormhole and send this file and it'll come up with a code.
If you give that code to someone else, they can run wormhole receive on their command line, enter that code.
And then over an encrypted connection that will automatically connect the two computers, even if they both have firewalls blocking it.
There's like some sort of intermediary server that will link them together.
And it'll just do, from what I understand, end-to-end encryption between these two things.
So if you need to get something and you don't want to put it somewhere public like Dropbox or you don't want to put it somewhere that's hard to erase or just hard to actually physically transfer like a USB drive, you can wormhole it.
And there's even a PyCon presentation on this at PyCon 2016.
So you can check it out.
What do you think about that, Brian?
That looks pretty cool.
I don't think I've got a use for it, but I want to have a use for it.
I know.
Well, you know, like suppose you want to get something to some server you're maintaining, maybe, or say you're on vacation and you want to send something back.
You don't want to send it over Dropbox.
I can see some good uses for it.
They talked about things like here's a way that you might be able to share like SSH keys that you don't want to put anywhere, but you've got to get them somewhere.
Things like that.
Yeah.
Yeah, it's pretty cool.
The codes, one of the things I thought was a nice touch was the codes are short and human pronounceable.
Oh, wow.
Yeah.
So they had some nice examples.
Let me see if I can find it.
Yeah.
So like the one that they have an example on the website is 7-crossover-clockwork.
So pretty long password, if you will, but also you can tell it to someone over the phone.
So the idea is like this is when you have the ability to communicate with a person, but your computer and their computer don't necessarily have a way to directly connect.
Oh, great.
So you don't have to like email them the secret code or something non-secure.
Yeah.
I emailed you the ISO.
It was only three gigs.
I'm sure it'll be fine.
Thanks for that.
And finally, there's actually an API that's part of this.
So it's not just a command line tool.
You can actually make wormhole capabilities in your own applications by just by importing the library.
Okay.
Now that sounds even more fun.
I don't know what to do with it, but it sure sounds fun.
It sure does.
Yeah.
So take us back to some fundamentals.
One of the things that I think we really don't do enough with as developers is virtual environments.
What do you think?
It's one of those things that I forget that it's hard to figure out the first time.
So virtual environments are something, if you're not using virtual environments, you need to be.
And there's an older tutorial, but this is from realpython.com.
And it's a Python virtual environments, a primer.
It covers what they are.
Why do we need them?
How do you use them?
Of course.
And then it also covers a few extra tools that a lot of people use, like Pyvenv for that came with Python 3.6 and virtual env wrapper.
I point to it because it's a pretty good, this article is a pretty good description of really the, why do we need them and how and what they are for?
If you're not understanding of what they're, why you need them.
This is a good, good document to talk about it.
The thing that I ran into recently was I was, I was trying to help somebody and install something.
And it turned out that the problem that they were, that they were having was they were not using virtual environments.
And when they would pip install something, they weren't able to import it from within the tests.
And the problem was that their pip was pointing to a different Python than the py test was using a different Python.
So when you pip install something, it goes into the virtual environment or the, the site packages for that version of Python, not for all of Pythons.
So yeah, he was pip installing it with Python.
His pip was 2.7 and it goes into 2.7 folder then.
And for me, that's the main reason why I, one of the main reasons why I use it is because once you use virtual environments, your pip and your Python and your py test and everything are all using the same Python and they don't get confused.
Yeah, it's great.
I use it a lot to basically, basically make it very, very clear what versions a particular web app of mine is running and what I need to deploy and things like that.
I think your point about it's easy to forget why this should ever be hard.
Like it's just second nature for those of us who've been doing a long time, but your example is perfect.
Like helping someone out who is somewhat new.
Like I thought Python was simple.
Why is this not working?
What is this?
That happens all the time.
And the, all the extra stuff like virtual and wrapper and py environment and all these, these extra things, those are great for the people that work with them.
But if you, if you try these out and they don't work for you, it might not be your fault or maybe it is, but I haven't been able to get any of these extra things to work.
I've tried virtual and wrapper.
It's never worked for me.
So I don't know what I'm doing wrong, but just the straight, straight virtual environments work great.
So that's what I use.
Yeah.
That's, that's cool.
Nice to have a little reference there.
So last thing I want to touch on is an interesting article that actually highlights a couple of projects.
I think there's four projects that highlights.
Okay.
Yeah.
And the idea is Rust, Rust, the programming language from Mozilla is a pretty interesting alternative to C, right?
It's, it's kind of a systems level programming language like C is, but it has a type system that helps eliminate memory leaks.
It has proper interfaces.
It has better type inference, better support for concurrency, better support for first class functions, those kinds of things.
And so compared to C, it's a pretty nice language.
And so when you think of a lot of the important Python packages, many of their important internal low level pieces are written as C extensions, right?
Yeah.
So could those be written in a better language than something like C?
How about Rust?
So here's four projects that make it easier to implement the, what would be the C extensions, the native compiled hotspot type of code, but do it in Rust instead of in C.
So the first one is Rust dash CPython.
So that's an interesting, just describes what it is.
So it's a set of bindings for Rust for the CPython runtime.
It allows Rust to connect to CPython using its application binary interface, which is a Rust thing.
And you can run Python programs from Rust or work with Python objects directly, the representations of Python objects directly in Rust.
So this is actually for if you want to, if you're a Rust programmer and you want to hook into CPython and control it from the outside.
There's Py03, which is a way for, for people to write software, Rust software with bindings of Python in both directions.
So a Rust program can interface with Python objects and the Python interpreter, and it can expose Rust methods to the Python program the same way like a C module does.
All right, so that's pretty cool.
Then there's Snake, S-N-A-E-K, which is a kind of early stage project, but it lets developers create Rust libraries that are loaded dynamically into Python as needed.
And they don't have to be statically linked against Python's runtime, which is kind of cool.
And I think it pulls it off using CFFI, which is the C interoperator for PyPy, the alternate interpreter JIT compiler for Python, rather than C types.
So if you don't have some old library that is based on C types, like say in C and you want to upgrade, then this might be a pretty sweet option.
And then finally, there's actually a cookie cutter template, and it says, the goal of this project is to be able to produce a binary distribution, a wheel, which will not require the end user to actually compile Rust code themselves, which everyone would appreciate that, right?
So here's a bunch of cool options if you are like, I really don't want to write this in C, but it probably should be written, you know, not in Python, but in some other way.
Like, maybe try Rust if you're looking to check that out.
That actually looks pretty cool.
Have you done any Rust yet?
No, I've, it's one of the languages I want to learn that I'm kind of intrigued by.
I looked at Go a little while ago.
I'm not a huge fan of Go, but people sort of compare these a lot.
So I want to check out Rust.
I think it's pretty different than Go.
Yeah, it's definitely something on my to-do list.
Yeah, cool.
Check this out.
Yeah.
Do you guys have any uses for Rust with all the hardware stuff you're doing?
I'm sure we could come up with, invent some reason to use Rust.
There you go.
Perfect.
All right.
How about you?
Any, any personal news here at the end of the show?
Just that I'm not writing anymore.
Congratulations.
That's awesome.
How's it feel?
It feels incredible.
Yeah.
To go from, I'm, I'm writing a book to, I wrote a book is great.
So.
Yeah.
That's cool.
Was your wife and kids like, Hey, there's some random guy in our house.
What's going on?
Oh wait, no, it's just Brian.
It's dad.
Yeah.
No, I've tried to, I've tried to limit the writing to, to things, obscene things like early in
the morning and late at night.
But yeah.
So punish yourself instead of your family.
Yeah, exactly.
So.
Cool.
All right.
Well, I am packing my bags and I'm going on vacation.
So either we might be a little bit intermittent or, you know, there's, there's some talk that
we might have some guests co-hosts coming in here.
We'll see.
Um, so if you don't see some podcasts in the next few weeks, don't worry, it'll come back,
but you might see them anyway with, some new faces.
So yeah, that would be awesome.
So either way, great chat with you, Brian.
Thanks everyone for listening.
All right.
Thanks.
Yep.
Bye.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
That's Python Bytes as in B-Y-T-E-S.
And get the full show notes at pythonbytes.fm.
If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
We're always on the lookout for sharing something cool.
On behalf of myself and Brian Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.