-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
87 lines (65 loc) · 3.26 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
# Self-Documented Makefile https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: clean setup install
#################################################################################
# GLOBALS #
#################################################################################
SHELL=/bin/bash
PYTHON = python
PROJECT_NAME = bioblp
PACKAGE_NAME = bioblp
PYTHON_INTERPRETER = python3
KERNEL_NAME=Python (${PROJECT_NAME})
PYTHON_FULL_V = $(shell python -V)
PYTHON_V := $(PYTHON_FULL_V:Python%=%)
CONDA_ENV=${PROJECT_NAME}-env
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CONDA_ACTIVATE=source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate
#PYTHON_V=3.8.6
#################################################################################
# COMMANDS #
#################################################################################
default: help
print-%: ## Prints a variable value. Usage: make print-VARIABLE, eg: make print-TAG, result: TAG = 0.0.0
@echo $* = $($*)
setup:
make install_poetry
@echo $(shell poetry --version) || "Install Poetry"
install_poetry: ## installs poetry. Remember to `source /home/jovyan/.poetry/env` from a terminal after running this recipe. Need only be run once
curl -sSL https://install.python-poetry.org | python3 -
install:
poetry install
poetry export -f requirements.txt --without-hashes --with dev --output requirements.txt
update:
poetry update
poetry export -f requirements.txt --without-hashes --with dev --output requirements.txt
test:
poetry run pytest tests -s -vv
create_ipython_kernel:
poetry run ipython kernel install --user --display-name="${KERNEL_NAME}"
freeze_requirements: ## Writes python project dependencies as a requirements.txt
poetry export -f requirements.txt --output requirements.txt --without-hashes
freeze_dev_requirements: ## Writes python project dependencies (including dev) as a requirements-dev.txt
poetry export -f requirements.txt --output requirements-dev.txt --without-hashes --dev
dist: ## Builds a distribution package with version ${PACKAGE_NAME}.__version__, eg: dist/test_me-0.0.0.tar.gz
make clean
poetry build
### JH setup
setup_jh_env:
make conda_setup
make create_conda_env
make create_conda_kernel
conda_setup: # ensures conda env is persistent, need run only once
mkdir -p /home/jovyan/.conda/pkgs/
touch /home/jovyan/.conda/pkgs/urls.txt
create_conda_env:
conda create --yes --prefix /home/jovyan/.conda/envs/${CONDA_ENV} ipykernel
#conda create --yes --prefix /home/jovyan/.conda/envs/${CONDA_ENV} python==${PYTHON_V} ipykernel
($(CONDA_ACTIVATE) /home/jovyan/.conda/envs/${CONDA_ENV} | make setup | source /home/jovyan/.poetry/env)
# to install the project module as a dependency
($(CONDA_ACTIVATE) /home/jovyan/.conda/envs/${CONDA_ENV} | make install)
conda env export -n ${CONDA_ENV} -f ${PROJECT_DIR}/environment.yml
create_conda_kernel:
python -m ipykernel install --user --name=${CONDA_ENV} --display-name="${KERNEL_NAME}"
update_conda_env:
#($(CONDA_ACTIVATE) /home/jovyan/.conda/envs/${CONDA_ENV} | make update)
conda env update --name ${CONDA_ENV} -f ${PROJECT_DIR}/environment.yml --prune