Python HOW: Create a Local pre-commit Hook for Conda

Gabriel Harris Ph.D.
3 min readApr 25, 2023
source: author

But why?

In short, so you don’t have to remember to do this every single time after installing/updating a package!

You do do this, right, right? 🧐

But how?

By using the pre-commit framework. Unfortunately, however, there isn’t a pre-defined hook by conda to do this easily. Instead, we will define a local hook that runs a local python script that generates environment.yaml !

1. Define target environment name 🎯

We will define the target environment name in the pyproject.toml. If you are not sure what a pyproject.toml file is, check Brett Cannon’s article “What the heck is pyproject.toml?” 🔗:

“a standard file that…all projects should (eventually) have … development tools realized they … could put their own configuration”

--

--

Gabriel Harris Ph.D.

I’m an End-to-End Lead Data Scientist and Data Science Manager. My articles are love letters to my future self