-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·126 lines (98 loc) · 4.41 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.PHONY: clean clean-model clean-pyc docs help init init-docker create-container start-container jupyter test lint profile clean clean-data clean-docker clean-container clean-image sync-from-source sync-to-source
.DEFAULT_GOAL := help
###########################################################################################################
## SCRIPTS
###########################################################################################################
define PRINT_HELP_PYSCRIPT
import os, re, sys
if os.environ['TARGET']:
target = os.environ['TARGET']
is_in_target = False
for line in sys.stdin:
match = re.match(r'^(?P<target>{}):(?P<dependencies>.*)?## (?P<description>.*)$$'.format(target).format(target), line)
if match:
print("target: %-20s" % (match.group("target")))
if "dependencies" in match.groupdict().keys():
print("dependencies: %-20s" % (match.group("dependencies")))
if "description" in match.groupdict().keys():
print("description: %-20s" % (match.group("description")))
is_in_target = True
elif is_in_target == True:
match = re.match(r'^\t(.+)', line)
if match:
command = match.groups()
print("command: %s" % (command))
else:
is_in_target = False
else:
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
define START_DOCKER_CONTAINER
if [ `$(DOCKER) inspect -f {{.State.Running}} $(CONTAINER_NAME)` = "false" ] ; then
$(DOCKER) start $(CONTAINER_NAME)
fi
endef
###########################################################################################################
## VARIABLES
###########################################################################################################
export DOCKER=docker
export TARGET=
export PWD=`pwd`
export PRINT_HELP_PYSCRIPT
export START_DOCKER_CONTAINER
export PYTHONPATH=$PYTHONPATH:$(PWD)
export PROJECT_NAME=pawnet
export IMAGE_NAME=$(PROJECT_NAME)-image
export CONTAINER_NAME=$(PROJECT_NAME)-container
export DATA_SOURCE=gs://pawnet-asia/data
export JUPYTER_HOST_PORT=8888
export JUPYTER_CONTAINER_PORT=8888
export PYTHON=python3
export DOCKERFILE=docker/Dockerfile
export TEST_SOURCE=pawnet
###########################################################################################################
## ADD TARGETS SPECIFIC TO "pawnet"
###########################################################################################################
###########################################################################################################
## GENERAL TARGETS
###########################################################################################################
help: ## show this message
@$(PYTHON) -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
sync-from-source: ## download data data source to local envrionment
gsutil -m cp -r $(DATA_SOURCE)/* ./data/
sync-to-source: ## sync local data to data source
gsutil -m cp -r ./data/* $(DATA_SOURCE)
lint: ## check style with flake8
flake8 pawnet
profile: ## show profile of the project
@echo "CONTAINER_NAME: $(CONTAINER_NAME)"
@echo "IMAGE_NAME: $(IMAGE_NAME)"
@echo "JUPYTER_PORT: `$(DOCKER) port $(CONTAINER_NAME)`"
@echo "DATA_SOURE: $(DATA_SOURCE)"
clean: clean-model clean-pyc clean-docker ## remove all artifacts
clean-model: ## remove model artifacts
rm -fr model/*
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
distclean: clean clean-data ## remove all the reproducible resources including Docker images
clean-data: ## remove files under data
rm -fr data/*
freeze_environment_local: ## Freeze python dependencies
sh scripts/freeze_dependencies.sh
freeze_environment_docker: ## Freeze python dependencies for docker
sh scripts/freeze_dependencies_docker.sh
freeze_environment_all: freeze_environment_local freeze_environment_docker ## Freeze all environment
run_auth: ## authenticate google credentials
gcloud init
gcloud auth application-default login
run_precommit: ## execute precommit hooks without commits
pre-commit run --all-files
install_precommit: ## install precommit hooks
pre-commit install