<commit_before>SHELL := /bin/bash
.DEFAULT_GOAL := default
.PHONY: \
	default all-editable
	clean clean-all clean-bin clean-build clean-pyc clean-test clean-$(VENV_NAME) purge\
	install install-all install-all-editable install-mcr install-tomato \
	install-tomato-$(PIP_INST_DEV) install-tomato-$(PIP_INST_DEMO) \
	docker-build docker-run-import docker-run-tests \
	test test-docker lint pylint flake8

VENV_INTERP = python3.6
VENV_NAME ?= venv

PIP_INST_EXTRA = 
PIP_INST_DEV = development
PIP_INST_DEMO = demo
PIP_INST_ALL = $(PIP_INST_DEV),$(PIP_INST_DEMO)
PIP_FLAG = 
PIP_INST_FLAG = 
PIP_INST_EDIT = -e

MCR_DOWN_URL = http://www.mathworks.com/supportfiles/downloads/R2015a/deployment_files/R2015a/installers/glnxa64/MCR_R2015a_glnxa64_installer.zip
MCR_DOWNLOAD_PATH = /tmp/mcr-install
MCR_INST_PATH = /usr/local/MATLAB/MATLAB_Runtime/
MCR_PATH = $(MCR_INST_PATH)v85

DOCKER_TAG = sertansenturk/tomato
DOCKER_VER = latest
DOCKER_FILE = Dockerfile

HELP_PADDING = 28
bold := $(shell tput bold)
sgr0 := $(shell tput sgr0)
padded_str := %-$(HELP_PADDING)s
pretty_command := $(bold)$(padded_str)$(sgr0)

help:
	@printf "======= General ======\n"
	@printf "$(pretty_command): run \"default\" (see below)\n"
	@printf "$(pretty_command): run \"clean-all\", \"$(VENV_NAME)\", and \"install\" sequentially\n" default
	@printf "$(pretty_command): run \"clean-all\", \"$(VENV_NAME)\", and \"install-all-editable\" sequentially\n" all-editable
	@printf "\n"
	@printf "======= Cleanup ======\n"
	@printf "$(pretty_command): remove all build, test, coverage and python artifacts\n" clean
	@printf "$(pretty_command): remove all (see: above) plus virtualenv, and tomato binaries\n" clean-all
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(pretty_command): remove tomato binaries\n" clean-bin
	@printf "$(pretty_command): remove build artifacts\n" clean-build
	@printf "$(pretty_command): remove python file artifacts\n" clean-pyc
	@printf "$(pretty_command): remove test artifacts\n" clean-test
	@printf "$(pretty_command): remove python virtualenv folder\n" clean-$(VENV_NAME)
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(pretty_command): alias of \"clean-all\"\n" purge
	@printf "\n"
	@printf "======= Setup =======\n"
	@printf "$(pretty_command): install tomato in a virtualenv, and install MCR\n" install
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(pretty_command): install tomato in a virtualenv with all extra dependencies, and install MCR\n" install-all
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(pretty_command): install tomato in editable mode and in a virtualenv with all extra dependencies, and install MCR\n" install-all-editable
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(pretty_command): install MATLAB Runtime Compiler (MCR)\n" install-mcr
	@printf "$(padded_str)MCR_DOWNLOAD_PATH, temporary folder to download MCR into (default: $(MCR_DOWNLOAD_PATH))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(pretty_command): install tomato in a virtualenv\n" install-tomato
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(padded_str)PIP_INST_EXTRA, install from extras_require (default: $(PIP_INST_EXTRA), possible values: $(PIP_INST_ALL))\n"
	@printf "$(pretty_command): create a virtualenv\n" $(VENV_NAME)
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(padded_str)VENV_INTERP, python interpreter (default: $(VENV_INTERP))\n"
	@printf "\n"
	@printf "======= Docker =======\n"
	@printf "$(pretty_command): build docker image\n" docker-build
	@printf "$(padded_str)DOCKER_TAG, docker image tag (default: $(DOCKER_TAG))\n"
	@printf "$(padded_str)DOCKER_VER, docker image version (default: $(DOCKER_VER))\n"
	@printf "\n"
	@printf "======= Testing and linting =======\n"
	@printf "$(pretty_command): run all testing and linting automations using tox\n" test
	@printf "$(pretty_command): run docker build and test automation using tox\n" test-docker
	@printf "$(pretty_command): run all style checking and linting automation using tox \n" lint
	@printf "$(pretty_command): run flake8 for style guide (PEP8) checking using tox\n" flake8
	@printf "$(pretty_command): run pylint using tox\n" pylint
	@printf "$(pretty_command): sorts python imports\n" isort

default: clean-all $(VENV_NAME) install
all-editable: clean-all $(VENV_NAME) install-all-editable

purge: clean-all

clean-all: clean-pyc clean-build clean-test clean-$(VENV_NAME) clean-bin

clean: clean-pyc clean-build clean-test

clean-pyc:
	find . -name '*.pyc' -exec rm -f {} +
	find . -name '*.pyo' -exec rm -f {} +
	find . -name '*~' -exec rm -f {} +
	find . -name '__pycache__' -exec rm -fr {} +

clean-bin:
	rm -rf tomato/bin/phraseSeg tomato/bin/extractTonicTempoTuning tomato/bin/alignAudioScore tomato/bin/MusikiToMusicXml	

clean-build: ## remove build artifacts
	rm -rf build/
	rm -rf dist/
	rm -rf .eggs/
	rm -rf .pytest_cache
	find . -name '.eggs' -type d -exec rm -rf {} +
	find . -name '*.egg-info' -exec rm -rf {} +
	find . -name '*.egg' -exec rm -f {} +

clean-test:
	rm -fr .tox/
	rm -f .coverage
	rm -fr htmlcov/

clean-$(VENV_NAME):
	rm -rf $(VENV_NAME)

$(VENV_NAME):
	python3 -m virtualenv -p $(VENV_INTERP) $(VENV_NAME)

install: install-tomato install-mcr 

install-all: PIP_INST_EXTRA:=$(PIP_INST_ALL)
install-all: install-tomato install-mcr 

install-all-editable: PIP_INST_FLAG:=$(PIP_INST_EDIT)
install-all-editable: install-all

install-tomato: $(VENV_NAME)
	source $(VENV_NAME)/bin/activate ; \
	pip install --upgrade pip ; \
	if [ "$(PIP_INST_EXTRA)" = "" ]; then \
        python -m pip $(PIP_FLAG) install $(PIP_INST_FLAG) .; \
	else \
	    python -m pip $(PIP_FLAG) install $(PIP_INST_FLAG) .[$(PIP_INST_EXTRA)]; \
    fi

install-tomato-$(PIP_INST_DEV): PIP_INST_EXTRA:=$(PIP_INST_DEV)
install-tomato-$(PIP_INST_DEV): install-tomato

install-tomato-$(PIP_INST_DEMO): PIP_INST_EXTRA:=$(PIP_INST_DEMO)
install-tomato-$(PIP_INST_DEMO): install-tomato

install-mcr:
	if [ -z "$$(ls -A $(MCR_PATH))" ]; then \
		echo "Installing MCR to $(MCR_PATH)..."; \
		mkdir $(MCR_DOWNLOAD_PATH) ; \
		cd $(MCR_DOWNLOAD_PATH) ; \
		wget --progress=bar:force $(MCR_DOWN_URL) ; \
		unzip -q MCR_R2015a_glnxa64_installer.zip ; \
		$(MCR_DOWNLOAD_PATH)/install \
			-destinationFolder $(MCR_INST_PATH) \
			-agreeToLicense yes \
			-mode silent ; \
		cd / ; \
		rm -rf $(MCR_DOWNLOAD_PATH) ; \
	else \
		echo "MCR is already installed to $(MCR_PATH). Skipping..."; \
    fi

docker-build:
	docker build . \
		-f $(DOCKER_FILE) \
		-t $(DOCKER_TAG):$(DOCKER_VER)

isort:
	isort --skip-glob=.tox --recursive . 

test:
	tox

test-docker:
	tox -e docker

lint:
	tox -e lint

flake8:
	tox -e flake8

pylint:
	tox -e pylint

# black:
# 	black --line-length 79 ./

# test: clean-pyc
# 	py.test --verbose --color=yes $(TEST_PATH)<commit_msg>Simplified makefile<commit_after>SHELL := /bin/bash
.DEFAULT_GOAL := default
.PHONY: \
	help default all-editable
	clean clean-all clean-bin clean-build clean-pyc clean-test clean-$(VENV_NAME) purge \
	install install-all install-all-editable install-mcr install-tomato \
	docker-build test test-docker lint flake8 pylint isort

VENV_INTERP = python3.6
VENV_NAME ?= venv

PIP_INST_EXTRA = 
PIP_INST_DEV = development
PIP_INST_DEMO = demo
PIP_INST_ALL = $(PIP_INST_DEV),$(PIP_INST_DEMO)
PIP_FLAG = 
PIP_INST_FLAG = 
PIP_INST_EDIT = -e

MCR_DOWN_URL = http://www.mathworks.com/supportfiles/downloads/R2015a/deployment_files/R2015a/installers/glnxa64/MCR_R2015a_glnxa64_installer.zip
MCR_DOWNLOAD_PATH = /tmp/mcr-install
MCR_INST_PATH = /usr/local/MATLAB/MATLAB_Runtime/
MCR_PATH = $(MCR_INST_PATH)v85

DOCKER_TAG = sertansenturk/tomato
DOCKER_VER = latest
DOCKER_FILE = Dockerfile

HELP_PADDING = 28
bold := $(shell tput bold)
sgr0 := $(shell tput sgr0)
padded_str := %-$(HELP_PADDING)s
pretty_command := $(bold)$(padded_str)$(sgr0)

help:
	@printf "======= General ======\n"
	@printf "$(pretty_command): run \"default\" (see below)\n"
	@printf "$(pretty_command): run \"clean-all\", \"$(VENV_NAME)\", and \"install\" sequentially\n" default
	@printf "$(pretty_command): run \"clean-all\", \"$(VENV_NAME)\", and \"install-all-editable\" sequentially\n" all-editable
	@printf "\n"
	@printf "======= Cleanup ======\n"
	@printf "$(pretty_command): remove all build, test, coverage and python artifacts\n" clean
	@printf "$(pretty_command): remove all (see: above) plus virtualenv, and tomato binaries\n" clean-all
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(pretty_command): remove tomato binaries\n" clean-bin
	@printf "$(pretty_command): remove build artifacts\n" clean-build
	@printf "$(pretty_command): remove python file artifacts\n" clean-pyc
	@printf "$(pretty_command): remove test artifacts\n" clean-test
	@printf "$(pretty_command): remove python virtualenv folder\n" clean-$(VENV_NAME)
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(pretty_command): alias of \"clean-all\"\n" purge
	@printf "\n"
	@printf "======= Setup =======\n"
	@printf "$(pretty_command): install tomato in a virtualenv, and install MCR\n" install
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(pretty_command): install tomato in a virtualenv with all extra dependencies, and install MCR\n" install-all
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(pretty_command): install tomato in editable mode and in a virtualenv with all extra dependencies, and install MCR\n" install-all-editable
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(pretty_command): install MATLAB Runtime Compiler (MCR)\n" install-mcr
	@printf "$(padded_str)MCR_DOWNLOAD_PATH, temporary folder to download MCR into (default: $(MCR_DOWNLOAD_PATH))\n"
	@printf "$(padded_str)MCR_INST_PATH, path to install MCR (default: $(MCR_INST_PATH))\n"
	@printf "$(pretty_command): install tomato in a virtualenv\n" install-tomato
	@printf "$(padded_str)VENV_NAME, virtualenv name to install (default: $(VENV_NAME))\n"
	@printf "$(padded_str)PIP_FLAG, pip flags (default: $(PIP_FLAG))\n"
	@printf "$(padded_str)PIP_INST_FLAG, pip install flags (default: $(PIP_INST_FLAG))\n"
	@printf "$(padded_str)PIP_INST_EXTRA, install from extras_require (default: $(PIP_INST_EXTRA), possible values: $(PIP_INST_ALL))\n"
	@printf "$(pretty_command): create a virtualenv\n" $(VENV_NAME)
	@printf "$(padded_str)VENV_NAME, virtualenv name (default: $(VENV_NAME))\n"
	@printf "$(padded_str)VENV_INTERP, python interpreter (default: $(VENV_INTERP))\n"
	@printf "\n"
	@printf "======= Docker =======\n"
	@printf "$(pretty_command): build docker image\n" docker-build
	@printf "$(padded_str)DOCKER_TAG, docker image tag (default: $(DOCKER_TAG))\n"
	@printf "$(padded_str)DOCKER_VER, docker image version (default: $(DOCKER_VER))\n"
	@printf "\n"
	@printf "======= Testing and linting =======\n"
	@printf "$(pretty_command): run all testing and linting automations using tox\n" test
	@printf "$(pretty_command): run docker build and test automation using tox\n" test-docker
	@printf "$(pretty_command): run all style checking and linting automation using tox \n" lint
	@printf "$(pretty_command): run flake8 for style guide (PEP8) checking using tox\n" flake8
	@printf "$(pretty_command): run pylint using tox\n" pylint
	@printf "$(pretty_command): sorts python imports\n" isort

default: clean-all $(VENV_NAME) install
all-editable: clean-all $(VENV_NAME) install-all-editable

purge: clean-all

clean-all: clean-pyc clean-build clean-test clean-$(VENV_NAME) clean-bin

clean: clean-pyc clean-build clean-test

clean-pyc:
	find . -name '*.pyc' -exec rm -f {} +
	find . -name '*.pyo' -exec rm -f {} +
	find . -name '*~' -exec rm -f {} +
	find . -name '__pycache__' -exec rm -fr {} +

clean-bin:
	rm -rf tomato/bin/phraseSeg tomato/bin/extractTonicTempoTuning tomato/bin/alignAudioScore tomato/bin/MusikiToMusicXml	

clean-build: ## remove build artifacts
	rm -rf build/
	rm -rf dist/
	rm -rf .eggs/
	rm -rf .pytest_cache
	find . -name '.eggs' -type d -exec rm -rf {} +
	find . -name '*.egg-info' -exec rm -rf {} +
	find . -name '*.egg' -exec rm -f {} +

clean-test:
	rm -fr .tox/
	rm -f .coverage
	rm -fr htmlcov/

clean-$(VENV_NAME):
	rm -rf $(VENV_NAME)

$(VENV_NAME):
	python3 -m virtualenv -p $(VENV_INTERP) $(VENV_NAME)

install: install-tomato install-mcr 

install-all: PIP_INST_EXTRA:=$(PIP_INST_ALL)
install-all: install-tomato install-mcr 

install-all-editable: PIP_INST_FLAG:=$(PIP_INST_EDIT)
install-all-editable: install-all

install-tomato: $(VENV_NAME)
	source $(VENV_NAME)/bin/activate ; \
	pip install --upgrade pip ; \
	if [ "$(PIP_INST_EXTRA)" = "" ]; then \
        python -m pip $(PIP_FLAG) install $(PIP_INST_FLAG) .; \
	else \
	    python -m pip $(PIP_FLAG) install $(PIP_INST_FLAG) .[$(PIP_INST_EXTRA)]; \
    fi

install-mcr:
	if [ -z "$$(ls -A $(MCR_PATH))" ]; then \
		echo "Installing MCR to $(MCR_PATH)..."; \
		mkdir $(MCR_DOWNLOAD_PATH) ; \
		cd $(MCR_DOWNLOAD_PATH) ; \
		wget --progress=bar:force $(MCR_DOWN_URL) ; \
		unzip -q MCR_R2015a_glnxa64_installer.zip ; \
		$(MCR_DOWNLOAD_PATH)/install \
			-destinationFolder $(MCR_INST_PATH) \
			-agreeToLicense yes \
			-mode silent ; \
		cd / ; \
		rm -rf $(MCR_DOWNLOAD_PATH) ; \
	else \
		echo "MCR is already installed to $(MCR_PATH). Skipping..."; \
    fi

docker-build:
	docker build . \
		-f $(DOCKER_FILE) \
		-t $(DOCKER_TAG):$(DOCKER_VER)

test:
	tox

test-docker:
	tox -e docker

lint:
	tox -e lint

flake8:
	tox -e flake8

pylint:
	tox -e pylint

isort:
	isort --skip-glob=.tox --recursive . 
{'fraction_non_alphanumeric': 0.15823647815076944, 'fraction_numerical': 0.005064606194402961, 'mean_word_length': 4.912476007677543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3148974', 'n_tokens_mistral': 6131, 'n_tokens_neox': 5702, 'n_words': 1420}