blob: c20333f4964fceb0cbaede2d7c8bfe6b066c8ad2 [file] [log] [blame]
Joey Armstrong0205d332023-04-11 17:29:23 -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.
Joey Armstrong7ad5c362023-07-09 19:10:16 -040016# -----------------------------------------------------------------------
Joey Armstronge98239c2023-05-08 17:10:07 -040017# https://gerrit.opencord.org/plugins/gitiles/onf-make
Joey Armstronge6a99912023-09-15 14:47:51 -040018# ONF.makefile.virtualenv.version = 1.2
19# -----------------------------------------------------------------------
20# Usage:
21# include makefiles/virtualenv/include.m
22#
23# Target Dependencies:
24# tgt : $(venv-activate-patched) python 3.10+ local use
25# tgt : $(venv-activate-script) python < v3.8
Joey Armstronge98239c2023-05-08 17:10:07 -040026# -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -040027
28$(if $(DEBUG),$(warning ENTER))
29
30##-------------------##
31##---] GLOBALS [---##
32##-------------------##
Joey Armstronge6a99912023-09-15 14:47:51 -040033.PHONY: venv venv-patched
Joey Armstrong0205d332023-04-11 17:29:23 -040034
35##------------------##
36##---] LOCALS [---##
37##------------------##
38venv-name ?= .venv# # default install directory
Joey Armstronge6a99912023-09-15 14:47:51 -040039venv-abs-path := $(PWD)/$(venv-name)# #
40venv-activate-bin := $(venv-name)/bin# # no whitespace
Joey Armstrongf548adc2023-09-08 15:59:42 -040041venv-activate-script := $(venv-activate-bin)/activate# # dependency
Joey Armstrong0205d332023-04-11 17:29:23 -040042
43# Intent: activate= is a macro for accessing the virtualenv activation script#
44# Usage: $(activate) && python
45activate ?= set +u && source $(venv-activate-script) && set -u
46
47## -----------------------------------------------------------------------
48## Intent: Activate script path dependency
49## Usage:
50## o place on the right side of colon as a target dependency
51## o When the script does not exist install the virtual env and display.
52## -----------------------------------------------------------------------
53$(venv-activate-script):
54 @echo
Joey Armstronge6a99912023-09-15 14:47:51 -040055 @echo '============================='
56 @echo 'Installing python virtual env'
57 @echo '============================='
Joey Armstrong0205d332023-04-11 17:29:23 -040058 virtualenv -p python3 $(venv-name)
59 $(activate) && python -m pip install --upgrade pip
60 $(activate) && pip install --upgrade setuptools
Joey Armstrongf548adc2023-09-08 15:59:42 -040061 $(activate) && [[ -r requirements.txt ]] \
62 && { python -m pip install -r requirements.txt; } \
63 || { /bin/true; }
64
Joey Armstrong0205d332023-04-11 17:29:23 -040065 $(activate) && python --version
66
67## -----------------------------------------------------------------------
68## Intent: Explicit named installer target w/o dependencies.
69## Makefile targets should depend on venv-activate-script.
70## -----------------------------------------------------------------------
Joey Armstronge6a99912023-09-15 14:47:51 -040071venv-activate-patched := $(venv-activate-script).patched
72venv-activate-patched : $(venv-activate-patched)
73$(venv-activate-patched) : $(venv-activate-script)
74 $(call banner-enter,Target $@)
75 $(ONF_MAKEDIR)/virtualenv/python_310_migration.sh
76 touch $@
77 $(call banner-leave,Target $@)
78
79## -----------------------------------------------------------------------
80## Intent: Explicit named installer target w/o dependencies.
81## Makefile targets should depend on venv-activate-script.
82## -----------------------------------------------------------------------
83venv : $(venv-activate-script)
84venv-patched : $(venv-activate-patched)
Joey Armstrong0205d332023-04-11 17:29:23 -040085
86## -----------------------------------------------------------------------
87## Intent: Revert installation to a clean checkout
88## -----------------------------------------------------------------------
89sterile :: clean
90 $(RM) -r "$(venv-abs-path)"
91
92## -----------------------------------------------------------------------
93## -----------------------------------------------------------------------
94help ::
95 @echo
96 @echo '[VIRTUAL ENV]'
97 @echo ' venv Create a python virtual environment'
98 @echo ' venv-name= Subdir name for virtualenv install'
99 @echo ' venv-activate-script make macro name'
100 @echo ' $$(target) dependency install python virtualenv'
101 @echo ' source $$(macro) && cmd configure env and run cmd'
102
103$(if $(DEBUG),$(warning LEAVE))
104
105# [EOF]