1
+ SHELL := /bin/bash
2
+
3
+ PWD ?= pwd_unknown
4
+
5
+ THIS_FILE := $(lastword $(MAKEFILE_LIST ) )
6
+ export THIS_FILE
7
+ TIME := $(shell date +% s)
8
+ export TIME
9
+
10
+ ifeq ($(docker ) ,)
11
+ DOCKER := $(shell which docker)
12
+ else
13
+ DOCKER := $(docker )
14
+ endif
15
+ export DOCKER
16
+
17
+ ifeq ($(compose ) ,)
18
+ DOCKER_COMPOSE := $(shell which docker-compose)
19
+ else
20
+ DOCKER_COMPOSE := $(compose )
21
+ endif
22
+ export DOCKER_COMPOSE
23
+
24
+
25
+
26
+ PYTHON := $(shell which python)
27
+ export PYTHON
28
+ PYTHON2 := $(shell which python2)
29
+ export PYTHON2
30
+ PYTHON3 := $(shell which python3)
31
+ export PYTHON3
32
+
33
+ PIP := $(shell which pip)
34
+ export PIP
35
+ PIP2 := $(shell which pip2)
36
+ export PIP2
37
+ PIP3 := $(shell which pip3)
38
+ export PIP3
39
+
40
+ python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1) ) )
41
+ python_version_major := $(word 1,${python_version_full})
42
+ python_version_minor := $(word 2,${python_version_full})
43
+ python_version_patch := $(word 3,${python_version_full})
44
+
45
+ my_cmd.python.3 := $(PYTHON3 ) some_script.py3
46
+ my_cmd := ${my_cmd.python.${python_version_major}}
47
+
48
+ PYTHON_VERSION := ${python_version_major}.${python_version_minor}.${python_version_patch}
49
+ PYTHON_VERSION_MAJOR := ${python_version_major}
50
+ PYTHON_VERSION_MINOR := ${python_version_minor}
51
+
52
+ export python_version_major
53
+ export python_version_minor
54
+ export python_version_patch
55
+ export PYTHON_VERSION
56
+
57
+ # PROJECT_NAME defaults to name of the current directory.
58
+ ifeq ($(project ) ,)
59
+ PROJECT_NAME := $(notdir $(PWD ) )
60
+ else
61
+ PROJECT_NAME := $(project )
62
+ endif
63
+ export PROJECT_NAME
64
+
65
+
66
+
67
+
68
+ .PHONY : venv
69
+ venv :
70
+ test -d .venv || $(PYTHON3 ) -m virtualenv .venv
71
+ ( \
72
+ source .venv/bin/activate; pip install -r requirements.txt; \
73
+ );
74
+ @echo " To activate (venv)"
75
+ @echo " try:"
76
+ @echo " . .venv/bin/activate"
77
+ @echo " or:"
78
+ @echo " make test-venv"
79
+ # #: test-venv source .venv/bin/activate; pip install -r requirements.txt;
80
+ test-venv :
81
+ # insert test commands here
82
+ test -d .venv || $(PYTHON3 ) -m virtualenv .venv
83
+ ( \
84
+ source .venv/bin/activate; pip install -r requirements.txt; \
85
+ );
86
+ # ######################
87
+ .PHONY : prune-network
88
+ prune-network :
89
+ $(DOCKER_COMPOSE ) -p $(PROJECT_NAME ) down
90
+ docker network rm $(PROJECT_NAME ) _default 2> /dev/null || echo " retry..."
91
+ # ######################
0 commit comments