Modern Python Projects Transcripts
Chapter: CI
Lecture: When to use which tool?
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So, we have tools like Tox to automate some tasks on your computer. We have pre-commit to automatically run some checks before you commit code.
0:11
And finally, we have CI tools like GitHub actions and GitHub CI. Do We use all of them. Do we use each of them in a different situation?
0:20
What's the rule of thumb here? Nothing stops you from running all of them. Each to requires a different amount of effort,
0:28
and their feedback can span from instant to when they build finishes. Tox can be run any time on your computer, and it gives you immediate feedback.
0:38
It's especially useful if you need to make sure that your code works under different versions of Python. So it's a best friend.
0:46
to people writing Python packages. You set it up once, and then you have an easy way to test your code under various Python 3 or
0:54
even Python 2 versions, pre-commit, It's mostly run when you finish writing a piece of code, and you want to add it to the git repository.
1:03
I mean, you can run pre-commit in your terminal whenever you want, but people mostly set it up as a pre-commit git hook and use it like
1:10
that. And just like with Tox, you get instant feedback. So you know, if your code checks all the requirements imposed by your team and if it can be
1:19
merged, a continuous integration service is the easiest to use because you don't have to set up anything on your computer.
1:28
Usually, when you work in a team, someone will set it up for you in the git repository, and then it will automatically run on everyone's code.
1:37
But here, the feedback time depends on when the server finishes processing your code, especially the free tools ofer only one concurrent build,
1:45
which means that if a lot of people submit pull request to the repository at the same time, the CI server will run checks one by one.
1:54
So it might happen that you will have to wait for a few minutes or even a few hours, depending on how big your team is.
2:02
So if I were to choose Only one tool from those three, I would go for the CI server. Setting up tools on your computer can be error problem.
2:11
Someone might not know how to properly set up pre-commit or might not have all the dependencies for Tox. Like the additional Python versions,
2:19
A CI sever doesn't require any set up. When a new person joins your team, you just sit down. You decide what tools you are going to run on your
2:28
code, so everyone on your team is happy. You set up, CI and then you let it run. Everyone will get an automatic feedback when they're commit
2:37
has a problem that way. Not only everyone has to follow the same rules, but it also speeds up the code review process.
2:45
A, lot of low hanging fruits like fading test or incorrectly formatted code will be reported automatically by the CI tools.
2:53
Of course, if you're not working as part of a team, but it's just you writing the code, then setting up a CI server might be an overkill.
3:02
If all you need to do is to run, test and maybe run black on your code each time you create and you commit for
3:08
your hobby project, then using a tool like Tox or pre-commit is perfectly fine.