blob: fd178f3721478e2573ab0e9db865b12401f47b29 [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001# -*- makefile -*-
2## -----------------------------------------------------------------------
Joey Armstrong4de98b72023-02-09 14:51:38 -05003# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong36592e32022-11-28 09:00:28 -05004#
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## -----------------------------------------------------------------------
Joey Armstrong64b82492023-06-01 17:34:39 -040017# https://gerrit.opencord.org/plugins/gitiles/onf-make
18# ONF.makefile.version = 1.0
19# -----------------------------------------------------------------------
Joey Armstrong36592e32022-11-28 09:00:28 -050020
Joey Armstrong4de98b72023-02-09 14:51:38 -050021$(if $(DEBUG),$(warning ENTER))
Joey Armstrong36592e32022-11-28 09:00:28 -050022
Joey Armstrong4de98b72023-02-09 14:51:38 -050023##-------------------##
24##---] GLOBALS [---##
25##-------------------##
26.PHONY: venv
Joey Armstrong36592e32022-11-28 09:00:28 -050027
Joey Armstrong4de98b72023-02-09 14:51:38 -050028##------------------##
29##---] LOCALS [---##
30##------------------##
31venv-name ?= .venv# # default install directory
32venv-abs-path := $(PWD)/$(venv-name)
Joey Armstrong36592e32022-11-28 09:00:28 -050033
Joey Armstrong4de98b72023-02-09 14:51:38 -050034venv-activate-script := $(venv-name)/bin/activate# # dependency
35
36# Intent: activate= is a macro for accessing the virtualenv activation script#
37# Usage: $(activate) && python
38activate ?= set +u && source $(venv-activate-script) && set -u
39
40## -----------------------------------------------------------------------
41## Intent: Activate script path dependency
42## Usage:
43## o place on the right side of colon as a target dependency
44## o When the script does not exist install the virtual env and display.
45## -----------------------------------------------------------------------
46$(venv-activate-script):
47 @echo
48 @echo "============================="
49 @echo "Installing python virtual env"
50 @echo "============================="
51 virtualenv -p python3 $(venv-name)
52 $(activate) && python -m pip install --upgrade pip
53 $(activate) && pip install --upgrade setuptools
54 $(activate) && { [[ -r requirements.txt ]] && python -m pip install -r requirements.txt; }
55 $(activate) && python --version
56
57ifndef NO_PYTHON_UPGRADE_PATCHING
58 @echo
59 @echo '** -----------------------------------------------------------------------'
60 @echo '** Applying python virtualenv patches as needed (v3.10+)'
61 @echo '** -----------------------------------------------------------------------'
62 ./patches/python_310_migration.sh '--venv' '$(venv-name)' 'apply'
63endif
64
65## -----------------------------------------------------------------------
66## Intent: Explicit named installer target w/o dependencies.
67## Makefile targets should depend on venv-activate-script.
68## -----------------------------------------------------------------------
69venv: $(venv-activate-script)
70
71## -----------------------------------------------------------------------
72## Intent: Revert installation to a clean checkout
73## -----------------------------------------------------------------------
74sterile :: clean
75 $(RM) -r "$(venv-abs-path)"
76
77## -----------------------------------------------------------------------
78## -----------------------------------------------------------------------
79help ::
80 @echo
81 @echo '[VIRTUAL ENV]'
82 @echo ' venv Create a python virtual environment'
83 @echo ' venv-name= Subdir name for virtualenv install'
84 @echo ' venv-activate-script make macro name'
85 @echo ' $$(target) dependency install python virtualenv'
86 @echo ' source $$(macro) && cmd configure env and run cmd'
87
88$(if $(DEBUG),$(warning LEAVE))
Joey Armstrong36592e32022-11-28 09:00:28 -050089
90# [EOF]