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