|
| 1 | +.PHONY: clean data lint requirements sync_data_to_s3 sync_data_from_s3 |
| 2 | + |
| 3 | +################################################################################# |
| 4 | +# GLOBALS # |
| 5 | +################################################################################# |
| 6 | + |
| 7 | +BUCKET = [OPTIONAL] your-bucket-for-syncing-data (do not include 's3://') |
| 8 | +PROJECT_NAME = LungNoduleCNN |
| 9 | +PYTHON_INTERPRETER = python |
| 10 | +IS_ANACONDA=$(shell python -c "import sys;t=str('anaconda' in sys.version.lower() or 'continuum' in sys.version.lower());sys.stdout.write(t)") |
| 11 | + |
| 12 | +################################################################################# |
| 13 | +# COMMANDS # |
| 14 | +################################################################################# |
| 15 | + |
| 16 | +## Install Python Dependencies |
| 17 | +requirements: test_environment |
| 18 | + pip install -r requirements.txt |
| 19 | + |
| 20 | +## Make Dataset |
| 21 | +data: requirements |
| 22 | + $(PYTHON_INTERPRETER) src/data/make_dataset.py |
| 23 | + |
| 24 | +## Delete all compiled Python files |
| 25 | +clean: |
| 26 | + find . -name "*.pyc" -exec rm {} \; |
| 27 | + |
| 28 | +## Lint using flake8 |
| 29 | +lint: |
| 30 | + flake8 --exclude=lib/,bin/,docs/conf.py . |
| 31 | + |
| 32 | +## Upload Data to S3 |
| 33 | +sync_data_to_s3: |
| 34 | + aws s3 sync data/ s3://$(BUCKET)/data/ |
| 35 | + |
| 36 | +## Download Data from S3 |
| 37 | +sync_data_from_s3: |
| 38 | + aws s3 sync s3://$(BUCKET)/data/ data/ |
| 39 | + |
| 40 | +## Set up python interpreter environment |
| 41 | +create_environment: |
| 42 | +ifeq (True,$(IS_ANACONDA)) |
| 43 | + @echo ">>> Detected Anaconda, creating conda environment." |
| 44 | +ifeq (3,$(findstring 3,$(PYTHON_INTERPRETER))) |
| 45 | + conda create --name $(PROJECT_NAME) python=3.5 |
| 46 | +else |
| 47 | + conda create --name $(PROJECT_NAME) python=2.7 |
| 48 | +endif |
| 49 | + @echo ">>> New conda env created. Activate with:\nsource activate $(PROJECT_NAME)" |
| 50 | +else |
| 51 | + @pip install -q virtualenv virtualenvwrapper |
| 52 | + @echo ">>> Installing virtualenvwrapper if not already intalled.\nMake sure the following lines are in shell startup file\n\ |
| 53 | + export WORKON_HOME=$$HOME/.virtualenvs\nexport PROJECT_HOME=$$HOME/Devel\nsource /usr/local/bin/virtualenvwrapper.sh\n" |
| 54 | + @bash -c "source `which virtualenvwrapper.sh`;mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER)" |
| 55 | + @echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)" |
| 56 | +endif |
| 57 | + |
| 58 | +## Test python environment is setup correctly |
| 59 | +test_environment: |
| 60 | + $(PYTHON_INTERPRETER) test_environment.py |
| 61 | + |
| 62 | +################################################################################# |
| 63 | +# PROJECT RULES # |
| 64 | +################################################################################# |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +################################################################################# |
| 69 | +# Self Documenting Commands # |
| 70 | +################################################################################# |
| 71 | + |
| 72 | +.DEFAULT_GOAL := show-help |
| 73 | + |
| 74 | +# Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html> |
| 75 | +# sed script explained: |
| 76 | +# /^##/: |
| 77 | +# * save line in hold space |
| 78 | +# * purge line |
| 79 | +# * Loop: |
| 80 | +# * append newline + line to hold space |
| 81 | +# * go to next line |
| 82 | +# * if line starts with doc comment, strip comment character off and loop |
| 83 | +# * remove target prerequisites |
| 84 | +# * append hold space (+ newline) to line |
| 85 | +# * replace newline plus comments by `---` |
| 86 | +# * print line |
| 87 | +# Separate expressions are necessary because labels cannot be delimited by |
| 88 | +# semicolon; see <http://stackoverflow.com/a/11799865/1968> |
| 89 | +.PHONY: show-help |
| 90 | +show-help: |
| 91 | + @echo "$$(tput bold)Available rules:$$(tput sgr0)" |
| 92 | + @echo |
| 93 | + @sed -n -e "/^## / { \ |
| 94 | + h; \ |
| 95 | + s/.*//; \ |
| 96 | + :doc" \ |
| 97 | + -e "H; \ |
| 98 | + n; \ |
| 99 | + s/^## //; \ |
| 100 | + t doc" \ |
| 101 | + -e "s/:.*//; \ |
| 102 | + G; \ |
| 103 | + s/\\n## /---/; \ |
| 104 | + s/\\n/ /g; \ |
| 105 | + p; \ |
| 106 | + }" ${MAKEFILE_LIST} \ |
| 107 | + | LC_ALL='C' sort --ignore-case \ |
| 108 | + | awk -F '---' \ |
| 109 | + -v ncol=$$(tput cols) \ |
| 110 | + -v indent=19 \ |
| 111 | + -v col_on="$$(tput setaf 6)" \ |
| 112 | + -v col_off="$$(tput sgr0)" \ |
| 113 | + '{ \ |
| 114 | + printf "%s%*s%s ", col_on, -indent, $$1, col_off; \ |
| 115 | + n = split($$2, words, " "); \ |
| 116 | + line_length = ncol - indent; \ |
| 117 | + for (i = 1; i <= n; i++) { \ |
| 118 | + line_length -= length(words[i]) + 1; \ |
| 119 | + if (line_length <= 0) { \ |
| 120 | + line_length = ncol - indent - length(words[i]) - 1; \ |
| 121 | + printf "\n%*s ", -indent, " "; \ |
| 122 | + } \ |
| 123 | + printf "%s ", words[i]; \ |
| 124 | + } \ |
| 125 | + printf "\n"; \ |
| 126 | + }' \ |
| 127 | + | more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars') |
0 commit comments