-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_python.mk
84 lines (62 loc) · 2.59 KB
/
setup_python.mk
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
$(call log.debug, COOKBOOK BEGIN INCLUDE: cookbook/setup_python.mk)
###############################################################################
# PYTHON SETUP TARGETS
# Targets for setting up the Python environment including pip and pipenv
###############################################################################
# DOUBLE COLON TARGET specifications
setup:: setup-python-env
setup-python-env: setup-python setup-pip setup-pipenv
help::
@echo " setup-python-env: Sets up the Python environment including pip and pipenv"
# USER-VARIABLE: PYTHON_MAJOR_VERSION
PYTHON_MINOR_VERSION ?= 11
$(call log.debug, PYTHON_MINOR_VERSION)
# TARGET: setup-python
#: Installs Python 3.$(PYTHON_MINOR_VERSION) based on the operating system
setup-python:
ifeq ($(OS),Linux)
# Install Python 3.$(PYTHON_MINOR_VERSION) if not available
if ! which python3.$(PYTHON_MINOR_VERSION) > /dev/null; then \
sudo add-apt-repository ppa:deadsnakes/ppa && \
sudo apt update && \
sudo apt install -y python3.$(PYTHON_MINOR_VERSION) python3.$(PYTHON_MINOR_VERSION)-distutils ; \
fi
else ifeq ($(OS),Darwin)
# Install Python 3.$(PYTHON_MINOR_VERSION) if not available
if ! which python3.$(PYTHON_MINOR_VERSION) > /dev/null; then \
brew install python@3.$(PYTHON_MINOR_VERSION); \
fi
endif
PHONY_TARGETS += setup-python
# TARGET: setup-pip
#: Installs pip for the specified Python version if not available
setup-pip:
# Install pip if not available
if ! python3.$(PYTHON_MINOR_VERSION) -mpip help > /dev/null; then \
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.$(PYTHON_MINOR_VERSION); \
fi
PHONY_TARGETS += setup-pip
help::
@echo " setup-pip: Installs pip for the specified Python version if not available"
# TARGET: setup-pipenv
#: Installs pipenv for the specified Python version if not available
setup-pipenv:
# Install pipenv if not available
if ! python3.$(PYTHON_MINOR_VERSION) -mpipenv --version > /dev/null; then \
python3.$(PYTHON_MINOR_VERSION) -mpip install pipenv ; \
fi
PHONY_TARGETS += setup-pipenv
help::
@echo " setup-pipenv: Installs pipenv for the specified Python version if not available"
# TARGET: setup-pip-requirements
#: Updates pip package requirements.txt by pipenv
#
# We want requirements.txt to be more flexible for development.
# Pipfile.lock will contain the exact versions that the production system used.
setup-pip-requirements:
pipenv lock
pipenv requirements > requirements.txt
PHONY_TARGETS += setup-pip-requirements
help::
@echo " setup-pip-requirements # Updates pip package requirements.txt from pipenv"
$(call log.debug, COOKBOOK END INCLUDE: cookbook/setup_python.mk)