forked from plataformapreventiva/politica_preventiva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
219 lines (159 loc) · 6.98 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
########################################
# Makefile for pipeline
# SEDESOL Version 0.1
# Roberto Sánchez
# Tomado de Adolfo De Unánue - github @nanounanue
########################################
.PHONY: clean data lint init deps sync_to_s3 sync_from_s3
########################################
## Variables ##
########################################
PROJECT_NAME:=$(shell cat .project-name)
PROJECT_VERSION:=$(shell cat .project-version)
PROJECT_USER:=$(shell cat .project-user)
w=11
p=ETLPipeline
ptask=auto
## Python Version
VERSION_PYTHON:=$(shell cat .python-version)
## Amazon bucket
S3_BUCKET := s3://dpa-$(PROJECT_NAME)/data/
SHELL := /bin/bash
########################################
## Help ##
########################################
help: ##@ayuda Diálogo de ayuda
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
########################################
## Tareas de Ambiente ##
########################################
init: prepare ##@dependencias Prepara la computadora para el funcionamiento del proyecto
$(source ./infraestructura/.env)
$(shell ./aws_ip_group.sh)
prepare: deps
#pyenv virtualenv ${PROJECT_NAME}_venv
#pyenv local ${PROJECT_NAME}_venv
pyenv: .python-version
@pyenv install $(VERSION_PYTHON)
deps: pip pip-dev
pip: requirements.txt
@pip3 install -r $<
pip-dev: requirements-dev.txt
@pip3 install -r $<
info:
@echo Proyecto: $(PROJECT_NAME) ver. $(PROJECT_VERSION)
@python --version
@pyenv --version
@pip --version
########################################
## Tareas de Limpieza ##
########################################
clean: ##@limpieza Elimina los archivos no necesarios
@find . -name "__pycache__" -exec rm -rf {} \;
@find . -name "*.egg-info" -exec rm -rf {} \;
@find . -name "*.pyc" -exec rm {} \;
@find . -name '*.pyo' -exec rm -f {} \;
@find . -name '*~' ! -name '*.un~' -exec rm -f {} \;
clean_venv: ##@limpieza Destruye la carpeta de virtualenv
@pyenv uninstall -f ${PROJECT_NAME}_venv
echo ${VERSION_PYTHON} > .python-version
########################################
## Set up tasks ##
## Infrastructure ##
########################################
create: ##@infraestructure Create infraestructure for the project (Images, volume & network)
$(MAKE) --directory=infraestructura create
start: ##@infraestructure Create Infrastructure
$(MAKE) --directory=infraestructura start
stop: ##@infraestructure Stop Infrastructure
$(MAKE) --directory=infraestructura stop
restart: ##@infraestructure Restart Tasks Infastructure
$(MAKE) --directory=${PROJECT_NAME} restart
status: ##@infraestructure Report the status of the infrastructure
$(MAKE) --directory=infraestructura status
logs: ##@infraestructure Displays the outputs of the infrastructure logs
$(MAKE) --directory=infraestructura logs
nuke: ##@infraestructure Destroy -F infrastructure and images
$(MAKE) --directory=infraestructura nuke
########################################
## Tareas de Validación ##
########################################
lint: ##@test Verifica que el código este bien escrito (según PEP8)
@flake8 --exclude=lib/,bin/,docs/conf.py,.tox/,shameful/,politica_preventiva.egg-info/ .
tox: clean ##@test Ejecuta tox
tox
########################################
## Tareas de Documentación ##
########################################
#view_docs: ##@docs Ver la documentación en http://0.0.0.0:8000
# @mkdocs serve
#create_docs: ##@docs Crea la documentación
# $(MAKE) --directory=docs html
todo: ##@docs ¿Qué falta por hacer?
pylint --disable=all --enable=W0511 src
########################################
## Tareas de Sincronización ##
## de Datos ##
########################################
#sync_to_s3: ##@data Sincroniza los datos del usuario hacia AWS S3
# @aws s3 sync ./data/user/$(PROJECT_USER) s3://$(S3_BUCKET)/user/$(PROJECT_USER)
S3_BUCKET := s3://dpa-$(PROJECT_NAME)/data/
#sync_from_s3: ##@data Sincroniza los datos del usuario desde AWS S3
# @aws s3 sync s3://$(S3_BUCKET)/user/$(PROJECT_USER) ./data/user/$(PROJECT_USER)
########################################
## Project Tasks ##
########################################
run: ##@project Run pipeline: make run w=10 p=(IngestPipeline|ETLPipeline|FeaturesPipeline|ModelsPipeline
$(MAKE) --directory=$(PROJECT_NAME) run WORKERS=$(w) level=$(p) ptask=$(ptask)
setup: task_build install##@project Crea las imágenes del pipeline e instala el pipeline como paquete en el PYTHONPATH
task_build:
$(MAKE) --directory=$(PROJECT_NAME) setup
remove: uninstall ##@project Destruye la imágenes del pipeline y desinstala el pipeline del PYTHONPATH
$(MAKE) --directory=$(PROJECT_NAME) clean
build:
$(MAKE) --directory=$(PROJECT_NAME) build
install:
@pip install --editable .
uninstall:
@while pip uninstall -y ${PROJECT_NAME}; do true; done
@python setup.py clean
########################################
## Funciones ##
## de soporte ##
########################################
## NOTE: Tomado de https://gist.github.com/prwhite/8168133 , en particular,
## del comentario del usuario @nowox, lordnynex y @HarasimowiczKamil
## COLORS
BOLD := $(shell tput -Txterm bold)
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RED := $(shell tput -Txterm setaf 1)
BLUE := $(shell tput -Txterm setaf 5)
RESET := $(shell tput -Txterm sgr0)
## NOTE: Las categorías de ayuda se definen con ##@categoria
HELP_FUN = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-z0-9_\-]+)\s*:.*\#\#(?:@([a-z0-9_\-]+))?\s(.*)$$/ }; \
print "uso: make [target]\n\n"; \
for (sort keys %help) { \
print "${BOLD}${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${BOLD}${BLUE}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }
## Verificando dependencias
## Basado en código de Fernando Cisneros @ datank
EXECUTABLES = docker docker-compose docker-machine pyenv ag pip hub
TEST_EXEC := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)), some string, $(error "${BOLD}${RED}ERROR${RESET}: No está $(exec) en el PATH, considera revisar Google para instalarlo (Quizá 'apt-get install $(exec)' funcione...)")))
ifeq (,$(wildcard .project-name))
$(error ${BOLD}${RED}ERROR${RESET}: El archivo .project-name debe de existir. Debes de crear un archivo .project-name, el cual debe de contener el nombre del proyecto, (e.g dragonfly))
endif
ifndef PROJECT_NAME
$(error ${BOLD}${RED}ERROR${RESET}: El archivo .project-name existe pero está vacío. Debe de contener el nombre del proyecto (e.g. ghostbuster))
endif
ifeq ($(PROJECT_NAME), dummy)
$(error ${BOLD}${RED}ERROR${RESET}: El nombre del proyecto no puede ser 'dummy', por favor utiliza otro nombre (actualmente: $(PROJECT_NAME)))
endif