Skip to content

Commit 690241a

Browse files
committed
Added self-documenting comments and default Rule to list commands with descriptions
1 parent 2d106de commit 690241a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

{{ cookiecutter.repo_name }}/Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,93 @@ BUCKET = {{ cookiecutter.s3_bucket }}
1010
# COMMANDS #
1111
#################################################################################
1212

13+
## Install Python Dependencies
1314
requirements:
1415
pip install -q -r requirements.txt
1516

17+
## Make Dataset
1618
data: requirements
1719
python src/data/make_dataset.py
1820

21+
## Delete all compiled Python files
1922
clean:
2023
find . -name "*.pyc" -exec rm {} \;
2124

25+
## Lint using flake8
2226
lint:
2327
flake8 --exclude=lib/,bin/,docs/conf.py .
2428

29+
## Upload Data to S3
2530
sync_data_to_s3:
2631
aws s3 sync data/ s3://$(BUCKET)/data/
2732

33+
## Download Data from S3
2834
sync_data_from_s3:
2935
aws s3 sync s3://$(BUCKET)/data/ data/
3036

3137
#################################################################################
3238
# PROJECT RULES #
3339
#################################################################################
40+
41+
42+
43+
#################################################################################
44+
# Self Documenting Commands #
45+
#################################################################################
46+
47+
.DEFAULT_GOAL := show-help
48+
49+
# Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
50+
# sed script explained:
51+
# /^##/:
52+
# * save line in hold space
53+
# * purge line
54+
# * Loop:
55+
# * append newline + line to hold space
56+
# * go to next line
57+
# * if line starts with doc comment, strip comment character off and loop
58+
# * remove target prerequisites
59+
# * append hold space (+ newline) to line
60+
# * replace newline plus comments by `---`
61+
# * print line
62+
# Separate expressions are necessary because labels cannot be delimited by
63+
# semicolon; see <http://stackoverflow.com/a/11799865/1968>
64+
.PHONY: show-help
65+
show-help:
66+
@echo "$$(tput bold)Available rules:$$(tput sgr0)"
67+
@echo
68+
@sed -n -e "/^## / { \
69+
h; \
70+
s/.*//; \
71+
:doc" \
72+
-e "H; \
73+
n; \
74+
s/^## //; \
75+
t doc" \
76+
-e "s/:.*//; \
77+
G; \
78+
s/\\n## /---/; \
79+
s/\\n/ /g; \
80+
p; \
81+
}" ${MAKEFILE_LIST} \
82+
| LC_ALL='C' sort --ignore-case \
83+
| awk -F '---' \
84+
-v ncol=$$(tput cols) \
85+
-v indent=19 \
86+
-v col_on="$$(tput setaf 6)" \
87+
-v col_off="$$(tput sgr0)" \
88+
'{ \
89+
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
90+
n = split($$2, words, " "); \
91+
line_length = ncol - indent; \
92+
for (i = 1; i <= n; i++) { \
93+
line_length -= length(words[i]) + 1; \
94+
if (line_length <= 0) { \
95+
line_length = ncol - indent - length(words[i]) - 1; \
96+
printf "\n%*s ", -indent, " "; \
97+
} \
98+
printf "%s ", words[i]; \
99+
} \
100+
printf "\n"; \
101+
}' \
102+
| more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars')

0 commit comments

Comments
 (0)