blob: 9fb5ad913347aff02df0283e9198018f5191f48f [file] [log] [blame]
Joey Armstrong28eddda2023-01-10 03:09:34 -05001# -*- makefile -*-
2## -----------------------------------------------------------------------
Joey Armstrongbeef4cd2023-01-18 09:59:58 -05003# Copyright 2017-2023 Open Networking Foundation
Joey Armstrong28eddda2023-01-10 03:09:34 -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## -----------------------------------------------------------------------
17
Joey Armstrong3f575f72023-01-15 23:49:19 -050018$(if $(DEBUG),$(warning ENTER))
Joey Armstrong28eddda2023-01-10 03:09:34 -050019
Joey Armstrong3f575f72023-01-15 23:49:19 -050020venv-name ?= .venv
21venv-abs-path := $(PWD)/$(venv-name)
22
23venv-activate-script := $(venv-name)/bin/activate# # dependency
24activate ?= source $(venv-activate-script)# # cmd invocation
25
26## -----------------------------------------------------------------------
27## Intent: Activate script path dependency
28## Usage:
29## o place on the right side of colon as a target dependency
30## o When the script does not exist install the virtual env and display.
31## -----------------------------------------------------------------------
32$(venv-activate-script):
33 virtualenv -p python3 $(venv-name)\
34 && source $(venv-name)/bin/activate\
35 && python -m pip install --upgrade pip\
36 && pip install --upgrade setuptools\
37 && { [[ -r requirements.txt ]] && python -m pip install -r requirements.txt; }\
38 && python --version
39
40## -----------------------------------------------------------------------
41## Intent: Explicit named installer target w/o dependencies.
42## Makefile targets should depend on venv-activate-script.
43## -----------------------------------------------------------------------
44venv: $(venv-activate-script)
45
46## -----------------------------------------------------------------------
47## Intent: Revert installation to a clean checkout
48## -----------------------------------------------------------------------
49sterile :: clean
50 $(RM) -r "$(venv-abs-path)"
51
52## -----------------------------------------------------------------------
53## -----------------------------------------------------------------------
54help ::
55 @echo
56 @echo '[VIRTUAL ENV]'
Joey Armstronga516c322023-01-25 17:40:42 -050057 @echo ' venv Create a python virtual environment'
58 @echo ' venv-name= Subdir name for virtualenv install'
59 @echo ' venv-activate-script make macro name'
60 @echo ' $$(target) dependency install python virtualenv'
61 @echo ' source $$(macro) && cmd configure env and run cmd'
Joey Armstrong3f575f72023-01-15 23:49:19 -050062
63$(if $(DEBUG),$(warning LEAVE))
Joey Armstrong28eddda2023-01-10 03:09:34 -050064
65# [EOF]