blob: bcda734a70a75526847299477a4fc04f286509e9 [file] [log] [blame]
Joey Armstrong6b58fd42023-04-12 17:45:53 -04001# -*- makefile -*-
2## -----------------------------------------------------------------------
3# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16## -----------------------------------------------------------------------
17
18$(if $(DEBUG),$(warning ENTER))
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23.PHONY: venv
24
25##------------------##
26##---] LOCALS [---##
27##------------------##
28venv-name ?= .venv# # default install directory
29venv-abs-path := $(PWD)/$(venv-name)
30
31venv-activate-script := $(venv-name)/bin/activate# # dependency
32
33# Intent: activate= is a macro for accessing the virtualenv activation script#
34# Usage: $(activate) && python
35activate ?= set +u && source $(venv-activate-script) && set -u
36
37## -----------------------------------------------------------------------
38## Intent: Activate script path dependency
39## Usage:
40## o place on the right side of colon as a target dependency
41## o When the script does not exist install the virtual env and display.
42## -----------------------------------------------------------------------
43$(venv-activate-script):
44 @echo
45 @echo "============================="
46 @echo "Installing python virtual env"
47 @echo "============================="
48 virtualenv -p python3 $(venv-name)
49 $(activate) && python -m pip install --upgrade pip
50 $(activate) && pip install --upgrade setuptools
51 $(activate) && { [[ -r requirements.txt ]] && python -m pip install -r requirements.txt; }
52 $(activate) && python --version
53
54ifndef NO_PYTHON_UPGRADE_PATCHING
55 @echo
56 @echo '** -----------------------------------------------------------------------'
57 @echo '** Applying python virtualenv patches as needed (v3.10+)'
58 @echo '** -----------------------------------------------------------------------'
59 ./patches/python_310_migration.sh '--venv' '$(venv-name)' 'apply'
60endif
61
62## -----------------------------------------------------------------------
63## Intent: Explicit named installer target w/o dependencies.
64## Makefile targets should depend on venv-activate-script.
65## -----------------------------------------------------------------------
66venv: $(venv-activate-script)
67
68## -----------------------------------------------------------------------
69## Intent: Revert installation to a clean checkout
70## -----------------------------------------------------------------------
71sterile :: clean
72 $(RM) -r "$(venv-abs-path)"
73
74## -----------------------------------------------------------------------
75## -----------------------------------------------------------------------
76help ::
77 @echo
78 @echo '[VIRTUAL ENV]'
79 @echo ' venv Create a python virtual environment'
80 @echo ' venv-name= Subdir name for virtualenv install'
81 @echo ' venv-activate-script make macro name'
82 @echo ' $$(target) dependency install python virtualenv'
83 @echo ' source $$(macro) && cmd configure env and run cmd'
84
85$(if $(DEBUG),$(warning LEAVE))
86
87# [EOF]