-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
89 lines (72 loc) · 2.33 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
88
89
SHELL := /bin/sh
##### Variables
##############################################################################
# Python
# /snacks/bin is added for users at the University of Oslo.
python_bin := $(shell PATH=/snacks/bin:${PATH} which python3)
# Requirements
req_floating := requirements-to-freeze.txt
req_pinned := requirements.txt
# Virtual environment (do not change the ordering).
venv_path := .venv
venv_bin_path := $(venv_path)/bin
venv_activate := $(venv_bin_path)/activate
venv_exec := . $(venv_activate) && PS1="venv $$ " exec
# Virtual environment tools.
venv_pip := $(venv_exec) pip3
venv_pylint := $(venv_exec) pylint
venv_python := $(venv_exec) python
# Application
app_root := cardinal
##### Rules
##############################################################################
# Build the virtual environment.
$(venv_path): $(venv_activate)
$(venv_activate): Makefile $(req_floating)
@test -d $(venv_path) || virtualenv -p $(python_bin) $(venv_path)
@$(venv_pip) install --upgrade --editable .
@touch $(venv_activate)
# Destroy the virtual environment and cache files.
.PHONY: clean
clean:
@$(RM) -r $(venv_path) *.egg-info
@find $(app_root) \
-name __pycache__ \
-type d \
-prune \
-exec $(RM) -rf {} \;
# Save a list of all currently installed packages with pinned version numbers.
.PHONY: freeze
freeze: $(venv_path)
@$(venv_pip) freeze > $(req_pinned)
# Generate linting report.
.PHONY: lint
lint: $(venv_path)
@$(venv_pylint) --rcfile=pylintrc --output-format=text $(app_root)
# Recreate the virtual environment with pinned package versions.
.PHONY: unfreeze
unfreeze: clean
@test -d $(venv_path) || virtualenv -p $(python_bin) $(venv_path)
$(venv_pip) install -Ur $(req_pinned)
@touch $(venv_activate)
# Install the latest version of all non-pinned packages.
.PHONY: upgrade
upgrade: $(venv_path)
$(venv_pip) install -Ur $(req_floating)
@touch $(venv_activate)
# Execute a REPL within the virtual environment.
.PHONY: repl
repl: $(venv_path)
@$(venv_python)
# Execute the code within the virtual environment.
.PHONY: run
run: $(venv_path)
@$(venv_exec) cardinal
# Execute a shell within the virtual environment.
.PHONY: shell
shell: $(venv_path)
@$(venv_exec) /bin/bash --norc
# Perform unit tests.
.PHONY: test
test: $(venv_path)
@$(venv_exec) green --processes 1 --run-coverage -v $(app_root)