Created
January 27, 2023 23:45
-
-
Save konsumer/4c0ea1492b09df08d416fcaf96ba7f4a to your computer and use it in GitHub Desktop.
Self-help for a Makefile in 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
# 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]}") |
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
.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