Skip to content

Commit 1df61f4

Browse files
committed
Print Makefile help via Python; reorganize targets
1 parent 9e9f70e commit 1df61f4

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

Diff for: Makefile

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# type `make help` to see all options
1+
# type `make help` to see all options
2+
.DEFAULT_GOAL := help
23

34
BASEURL ?=
45

@@ -8,16 +9,21 @@ endif
89

910
.PHONY: help prepare teams-clean teams serve clean
1011

11-
# Add help text after each target name starting with '\#\#'
12-
help: ## show this help
13-
@echo "\nHelp for this makefile"
14-
@echo "Possible commands are:"
15-
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\(.*\):.*##\(.*\)/ \1: \2/'
16-
1712
prepare:
1813
git submodule update --init --recursive
1914
python gen_config.py
2015

16+
serve: ## serve the website at http://localhost:1313/
17+
serve: prepare
18+
hugo $(BASEURLARG) --i18n-warnings server -D
19+
20+
html: ## build the static website in ./public
21+
html: prepare
22+
hugo $(BASEURLARG)
23+
24+
clean: ## remove build artifacts
25+
rm -rf public
26+
2127
TEAMS_DIR = static/gallery
2228
TEAMS = emeritus-maintainers maintainers triage-team survey-team web-team
2329
TEAMS_QUERY = python themes/scientific-python-hugo-theme/tools/team_query.py
@@ -33,14 +39,10 @@ teams-clean: prepare
3339
rm -f $(TEAMS_DIR)/$${team}.html ;\
3440
done
3541

36-
teams: | teams-clean $(patsubst %,$(TEAMS_DIR)/%.md,$(TEAMS)) ## generates numpy.org team gallery pages
37-
38-
serve: prepare ## serve the website
39-
hugo $(BASEURLARG) --i18n-warnings server -D
40-
41-
html: prepare ## build the website in ./public
42-
hugo $(BASEURLARG)
43-
44-
clean: ## remove the build artifacts, mainly the "public" directory
45-
rm -rf public
42+
teams: ## generate numpy.org team gallery pages
43+
teams: | teams-clean $(patsubst %,$(TEAMS_DIR)/%.md,$(TEAMS))
4644

45+
help: ## display this message
46+
@echo numpy.org make targets
47+
@echo ----------------------
48+
@python scripts/makefile_to_help.py Makefile

Diff for: scripts/makefile_to_help.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Modified from https://github.com/cesium-ml/baselayer
3+
4+
Convert ## style comments after a Makefile target into help text.
5+
6+
Usage: makefile_to_help.py <MAKEFILE>
7+
8+
"""
9+
10+
import sys
11+
import re
12+
13+
14+
if not sys.argv:
15+
print("Usage: makefile_to_help.py <MAKEFILE>")
16+
sys.exit(0)
17+
18+
19+
def describe_targets(lines):
20+
matches = [re.match('^([\w-]+): +##(.*)', line) for line in lines]
21+
groups = [m.groups(0) for m in matches if m]
22+
targets = {target: desc for (target, desc) in groups}
23+
24+
N = max(len(target) for (target, desc) in targets.items())
25+
26+
for (target, desc) in targets.items():
27+
print(f'{target:{N}} {desc}')
28+
29+
30+
fname = sys.argv[1]
31+
describe_targets(open(fname).readlines())

0 commit comments

Comments
 (0)