Last active
June 29, 2022 18:29
-
-
Save dadrian/f4895aede1dff6b11b0d65005e910a1d to your computer and use it in GitHub Desktop.
Makefile for bootstrapping a Python project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VIRTUALENV_DIR ?= ./env | |
PYTHON ?= python3 | |
PIP=$(VIRTUALENV_DIR)/bin/pip | |
VIRTUAL_PYTHON=$(VIRTUALENV_DIR)/bin/python | |
VIRTUALENV_BIN=$(PYTHON) -m venv | |
REQUIREMENTS ?= requirements.txt | |
all: help | |
.PHONY: build | |
build: pip ## set up environment and install dependencies | |
.PHONY: pip | |
pip: $(REQUIREMENTS) $(PIP) ## install dependencies | |
$(PIP) install -r $(REQUIREMENTS) | tee $(VIRTUALENV_DIR)/.pip.log | |
.PHONY: bootstrap | |
bootstrap: $(VIRTUALENV_DIR) ## set up virtual env | |
.PHONY: clean | |
clean: ## reset checkout, clear virtual environment | |
rm -rf $(VIRTUALENV_DIR) | |
touch $(REQUIREMENTS) | |
$(PIP): $(VIRTUALENV_DIR) | |
$(VIRTUAL_PYTHON): $(VIRTUALENV_DIR) | |
$(VIRTUALENV_DIR): | |
$(VIRTUALENV_BIN) $(VIRTUALENV_DIR) | |
# via https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | |
.PHONY: help | |
help: ## List tasks with documentation | |
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment