Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created January 27, 2023 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konsumer/4c0ea1492b09df08d416fcaf96ba7f4a to your computer and use it in GitHub Desktop.
Save konsumer/4c0ea1492b09df08d416fcaf96ba7f4a to your computer and use it in GitHub Desktop.
Self-help for a Makefile in a python project
# this will provide help for a makefile
import sys
import re
if len(sys.argv) < 2:
print("Usage: help.py Makefile")
exit(1)
print("Type make followed by one of these commands to run a task:")
for makefile in sys.argv[1:]:
s = open(makefile.strip(), 'r').read()
matches = re.finditer(r"^(.+):.+##\W?(.+)", s, re.MULTILINE)
for m, match in enumerate(matches, start=1):
print(f" \033[36m{match[1]:<20}\033[0m{match[2]}")
.PHONY: help clean
help: ## Show this help
@python tools/help.py "$(MAKEFILE_LIST)"
clean: ## Remove all built files
@rm -f FILES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment