Skip to content

Instantly share code, notes, and snippets.

@mandeepbal
Created July 10, 2023 19:29
Show Gist options
  • Select an option

  • Save mandeepbal/82b2e3e3c526d10b7fb4a94a86667c19 to your computer and use it in GitHub Desktop.

Select an option

Save mandeepbal/82b2e3e3c526d10b7fb4a94a86667c19 to your computer and use it in GitHub Desktop.

Revisions

  1. mandeepbal created this gist Jul 10, 2023.
    30 changes: 30 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    SHELL := bash
    .SHELLFLAGS := -eu -o pipefail -c
    # .DELETE_ON_ERROR:
    MAKEFLAGS = --warn-undefined-variables
    MAKEFLAGS += --no-builtin-rules


    # Override PWD so that it's always based on the location of the file and **NOT**
    # based on where the shell is when calling `make`. This is useful if `make`
    # is called like `make -C <some path>`
    PWD := $(realpath $(dir $(abspath $(firstword $(MAKEFILE_LIST)))))

    WORKTREE_ROOT := $(shell git rev-parse --show-toplevel 2> /dev/null)


    # Using $$() instead of $(shell) to run evaluation only when it's accessed
    # https://unix.stackexchange.com/a/687206
    py = $$(if [ -d $(PWD)/'.venv' ]; then echo $(PWD)/".venv/bin/python3"; else echo "python3"; fi)
    pip = $(py) -m pip

    .DEFAULT_GOAL := help
    .PHONY: help
    help: ## Display this help section
    @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z\$$/]+.*:.*?##\s/ {printf "\033[36m%-38s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

    .venv: requirements.txt ## Build the virtual environment
    $(py) -m venv .venv
    $(pip) install -U pip setuptools wheel build
    $(pip) install -U -r requirements.txt
    touch .venv