I've got package management for Python going through pip right now, but I keep having people on my team forget to redo pip install -r requirements.txt when rerunning our code base and then getting confused about why stuff doesn't work. That said, is there any way I can tie that command into something else that they always have to do anyway, like git pull
so that it's done for them and they don't need to think about it?
You could use a shell script in the git post-merge hook, which will execute whenever a merge takes place. Just be aware that this hook will execute on every merge (all pulls that actually do something are a merge, but not all merges are pulls).
I don't know if its possible to automatically install a client side hook when a repository is cloned, but you should at least be able to get your post-merge hook installed once instead of getting your team to remember to do something with every pull.
A post-merge
hook should work fine here. Open the file .git/hooks/post-merge
in your project's .git
directory. Paste the following code snippet in the file.
#/usr/bin/env bash
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_and_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
check_and_run requirements.txt "/path/to/virtualenv/bin/pip install -r /path/to/requirements.txt"
Run chmod +x post-merge
to make the file executable.
Thats it. Now every time when you do git merge and there is a change in requirements.txt
file pip install
will run automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With