Skip to content

Instantly share code, notes, and snippets.

@nutzhub
Last active December 10, 2019 00:03
Show Gist options
  • Save nutzhub/ff1214ffbad91db486d4cf469d8bbf98 to your computer and use it in GitHub Desktop.
Save nutzhub/ff1214ffbad91db486d4cf469d8bbf98 to your computer and use it in GitHub Desktop.
Python Makefile
# https://gist.github.com/prwhite/8168133
# colour vars
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
help: ## This help dialog.
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
printf "%-30s %s\n" "target" "help" ; \
printf "%-30s %s\n" "------" "----" ; \
for help_line in $${help_lines[@]}; do \
IFS=$$':' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf '\033[36m'; \
printf "%-30s %s" $$help_command ; \
printf '\033[0m'; \
printf "%s\n" $$help_info; \
done
WORK_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
AIRFLOW_HOME=$(WORK_DIR)/airflow_home
AIRFLOW_RUN=./airflow
VENV_CMD=. .venv/bin/activate
## target description
.venv:
@if [ ! -e ".venv/bin/activate_this.py" ] ; then virtualenv --clear .venv ; fi
## target description
.airflow_upgradedb: # target description
$(AIRFLOW_RUN) upgradedb
## target description
install_var: .airflow_upgradedb
@for f in airflow_config/variables/*; do \
$(AIRFLOW_RUN) variables -i $$f; \
done
install_pool: .airflow_upgradedb
$(AIRFLOW_RUN) pool -i airflow_config/pools.json
install_conn:
./airflow_config/connections/aws_conn && \
./airflow_config/connections/emr_siebel_etl && \
./airflow_config/connections/emr_siebel_transaction_consolidate
install_deps: .venv
$(VENV_CMD) && pip install pip===18.1 && AIRFLOW_GPL_UNIDECODE=yes pip install -U -r requirements.txt
install_hook: .venv
$(VENV_CMD) && githooks
install: install_deps install_hook install_var install_pool install_conn
## target description
lint:
$(VENV_CMD) && pylint -r n airflow_home/dags
test:
$(VENV_CMD) && pytest -v -s
release:
./release
.PHONY: .venv install lint validate test release install_var install_pool install_conn help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment