Skip to content

Instantly share code, notes, and snippets.

@balki
Last active August 15, 2022 18:31
Show Gist options
  • Save balki/dc79c2805c1004697580cc961b932ff4 to your computer and use it in GitHub Desktop.
Save balki/dc79c2805c1004697580cc961b932ff4 to your computer and use it in GitHub Desktop.
Makefile to keep python virtualenv up to date
# Usage:
# python3 -m venv pytools
# cp Makefile pytools/
# cd pytools
# make lock && make install
# ln -snf /path/to/pytools/bin/some_useful_cli_tool ~/bin/
# Runs all commands in a target in a single shell. Otherwise each line is run in a seperate shell
.ONESHELL:
# By default runs "sh" which does not have process substitution, i.e. <(blah bla bla ) syntax and `source` builtin
SHELL = /usr/bin/bash
.PHONY: upgrade install lock check
upgrade: check
source ./bin/activate
pip install --upgrade pip wheel setuptools
pip list --not-required --format json | jq -r '.[] | .name' | xargs pip install --upgrade
# Some tools need wheel to be present. So installing in first before anything else
install:
source ./bin/activate
pip install --upgrade pip wheel setuptools
cat packs.lock | xargs pip install --upgrade
lock:
source ./bin/activate
pip list --not-required --format json | jq -r '.[] | .name' > packs.lock
check:
source ./bin/activate
diff packs.lock <(pip list --not-required --format json | jq -r '.[] | .name') && echo "lock is update"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment