-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (87 loc) · 4.14 KB
/
Copy pathMakefile
File metadata and controls
114 lines (87 loc) · 4.14 KB
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
# s3 directory for DVC (data)
PROJECT_NAME = ml-deep-learning-final
IMAGE_TAG=0.1.0
ECR_URL=193567999519.dkr.ecr.us-east-1.amazonaws.com
# Save pyenv as local variable in Makefile
PYENV := $(shell command pyenv --version 2> /dev/null)
# Specify python kernel name used for Jupyter Notebook
PROJECT_KERNEL := dl_final
# Specify whether kernel already created
KERNEL_EXISTS := "$(shell command poetry run jupyter kernelspec list | grep $(PROJECT_KERNEL) 2> /dev/null)"
# Specify whether poetry already installed local package
LOCAL_EXISTS := "$(shell command poetry run pip freeze | grep adapticons)"
# Declaring all phony targets (avoid filename/directory collision)
.PHONY: help checkenv init_project download_data create_kernel start_lab lint test build_inference_image build_training_image local_train sagemaker_train
#========= Dependencies - No need to call directly ==========#
#============================================================#
# Make sure that a .python-version file exists in this directory. Dependency of init_project
checkenv:
ifndef PYENV
$(error "make sure pyenv is installed and is accessible in your path, (usually by adding to PATH variable in bash_profile, zshrc, or other locations based on your platform) See: https://github.com/pyenv/pyenv#installation for the installation insructions.")
endif
ifndef PYENV_SHELL
$(error "Add 'pyenv init' to your shell to enable shims and autocompletion, (usually by adding to your bash_profile, zshrc, or other locations based on your platform)")
endif
@echo Detected $(PYENV)
# pyenv install --skip-existing
#============================================================#
#============================================================#
#================ Recipes for CLI Consumption ===============#
#============================================================#
help:
@echo "Step X) [DO NOT USE] Run: make init_project"
@echo " Prepare development environment, ONLY USED WHEN CREATING NEW PROJECT. Initializes a poetry package and pre-commit"
@echo "Step 1) Run: make download_data"
@echo " Download data using DVC from s3 remote - just for processed datasets, not raw"
@echo "Step 2) Run: make install_dependencies"
@echo " Install dependencies listed in pyproject.toml"
@echo "Step 3) Run: make create_kernel"
@echo " Creates a kernel using poetry virtualenv - used by Jupyter Lab server"
@echo "Step 4) Run: make start_lab"
@echo " Starts up a Jupyter Lab server for local experimentation/analysis"
@echo "Step 5) Run: make build_inference_image"
@echo " Build and push the inference image for the development environment"
@echo "Step 6) Run: make test"
@echo " Runs tests"
@echo "Step 7) Run: make lint_project"
@echo " Format with black and isort, lint with flake8 and mypy"
@echo " "
@echo "Running macro test: 'make run_macro_test'"
@echo "Training on AWS Sagemaker: 'make sagemaker_train'"
@echo "Training on local: 'make local_train'"
@echo " "
@exit 0
# Install dependencies listed in pyproject.toml file
install_dependencies:
poetry install --no-root
init_project: checkenv install_dependencies
pre-commit install && python3 -m ipykernel install --user --name=adapticons
# Create a poetry virtualenv based kernel for jupyter consumption
create_kernel:
ifdef KERNEL_EXISTS
yes | poetry run jupyter kernelspec uninstall $(PROJECT_KERNEL)
endif
poetry run python -m ipykernel install --user --name=$(PROJECT_KERNEL)
# Start a jupyterlab server
start_lab:
poetry run jupyter lab
# Build and push the inference image for the development environment
build_inference_image:
./build_inference.sh --environment development --push
# Perform all necessary formatting on source code
lint:
yes | poetry run isort
poetry run black .
poetry run flake8 .
poetry run mypy .
# Test the package
test:
PYTHONPATH=. poetry run python -m pytest tests
# Build the training docker image - push to ECR
build_training_image:
./build_training.sh --push
# Run training locally
local_train:
poetry run python -m adapticons.modeling.standard.train --input-path data/cli_input --output-path tmp_models
#============================================================#
#============================================================#