-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (86 loc) · 2.26 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
DAY:=$(shell date +%-d)
YEAR:=$(shell date +%Y)
ZERODAY:=$(shell printf "%02d" $(DAY))
.PHONY: all
all:
@$(MAKE) usage | less
.PHONY: usage
usage:
@echo
@echo 'make TARGET [option=value, ...]'
@echo
@echo 'ENVIRONMENT'
@echo
@echo ' make env'
@echo ' - Rebuild development envionrment'
@echo
@echo 'CREATING FILES'
@echo
@echo ' make edit [DAY=<day>, YEAR=<year>]'
@echo ' - Create template if missing, and edit'
@echo
@echo 'TIMING'
@echo
@echo ' make time [YEAR=<year>]'
@echo ' - Time all puzzle for a year'
@echo
@echo 'LINTING'
@echo
@echo ' make lint'
@echo ' - Run linters'
@echo
.PHONY: edit
edit:
@program="$(ROOT_DIR)/$(YEAR)/day$(ZERODAY).py"; \
if [ ! -f "$$program" ]; then \
mkdir -p "$${program%/*}"; \
$(MAKE) template > "$$program"; \
chmod a+x "$$program"; \
fi; \
vim "$$program"
.PHONY: lint
lint: $(ROOT_DIR)/env
@flake8 common 20*
@pylint common 20*
.PHONY: time
time:
@time -p for pgm in $(ROOT_DIR)/$(YEAR)/day*.py; do [[ ! $$pgm =~ _ ]] && "$$pgm" -d; done
.PHONY: template
template:
@sed "s/YEAR/$(YEAR)/g; s/DAY/$(DAY)/g" < $(ROOT_DIR)/common/template.py
.PHONY: env
env: env-destroy $(ROOT_DIR)/env
$(ROOT_DIR)/env:
@$(MAKE) env-create env-update env-report
.PHONY: env-create
env-create:
@if ! command -v python3 &>/dev/null; then \
echo "Python 3 is not available, please install it."; \
false; \
fi
@echo "Building development virtual env"
python3 -m venv --clear "$(ROOT_DIR)/env"
"$(ROOT_DIR)/env/bin/pip3" install --upgrade --no-cache-dir pip setuptools wheel
@printf "#!/bin/sh\nexec /usr/bin/env python -m pydoc \"\$$@\"\n" > $(ROOT_DIR)/env/bin/pydoc
@chmod a+x $(ROOT_DIR)/env/bin/pydoc
.PHONY: env-update
env-update:
@for egg in "$(ROOT_DIR)"/common/*.egg-info; do \
rm -rf "$$egg"; \
done
@echo "Updating virtual env with latest source distribution"
"$(ROOT_DIR)/env/bin/pip3" install --editable $(ROOT_DIR)/common[test]
.PHONY: env-report
env-report:
@echo
@echo Python virtual environment built, to enable run the following:
@echo
@echo " source $(ROOT_DIR)/env/bin/activate"
@echo
.PHONY: env-destroy
env-destroy:
@if [ -d env ]; then \
echo "Removing previous virtual env"; \
rm -rf $(ROOT_DIR)/env; \
fi