blob: 0667f6883e0347d5fc4b532328504b50ec7e5800 [file] [log] [blame]
Joey Armstrong62ae1392024-03-17 20:49:30 -04001# -*- makefile -*-
2## -----------------------------------------------------------------------
3# Copyright 2017-2024 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# https://gerrit.opencord.org/plugins/gitiles/onf-make
18# ONF.makefile.version = 1.2
19# -----------------------------------------------------------------------
20
21$(if $(DEBUG),$(warning ENTER))
22
23##-------------------##
24##---] GLOBALS [---##
25##-------------------##
26.PHONY: venv
27
28##------------------##
29##---] LOCALS [---##
30##------------------##
31venv-name ?= .venv# # default install directory
32venv-abs-path := $(PWD)/$(venv-name)
33venv-activate-bin := $(venv-name)/bin
34venv-activate-script := $(venv-activate-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
40venv-version : venv-requirements
41venv-requirements : venv-install
42venv-install : $(venv-activate-script)
43
44## -----------------------------------------------------------------------
45## Intent: Activate script path dependency
46## Usage:
47## o place on the right side of colon as a target dependency
48## o When the script does not exist install the virtual env and display.
49## -----------------------------------------------------------------------
50$(venv-activate-script) :
51
52 $(call banner-enter,(virtualenv -p python))
53 virtualenv -p python3 $(venv-name)
54 $(activate) && python -m pip install --upgrade pip
55 $(activate) && pip install --upgrade setuptools
56
57 @$(MAKE) --no-print-directory venv-requirements venv-version
58 $(call banner-leave,(virtualenv -t python))
59
60## ----------------------------------------------------------------------
61## Intent: pip install with dependencies
62## ----------------------------------------------------------------------
63# venv-requirements-txt := .venv/makedep/requirements.txt.ts
64# venv-requirements : $(venv-requirements-txt)
65# venv-install : $(venv-activate-script)
66# venv-requirements : venv-install
67
68$(venv-requirements-txt) : requirements.txt
69
70 $(activate) && python -m pip install -r requirements.txt
71 @mkdir -p $(dir $@)
72 @touch $@
73
74## ----------------------------------------------------------------------
75## ----------------------------------------------------------------------
76venv-version :
77 $(activate) && python --version
78
79## -----------------------------------------------------------------------
80## Intent: Activate script path dependency
81## Usage:
82## o place on the right side of colon as a target dependency
83## o When the script does not exist install the virtual env and display.
84## ----------------------------------------------------------------------
85$(venv-activate-script)-orig :
86 @echo
87 @echo "============================="
88 @echo "Installing python virtual env"
89 @echo "============================="
90 virtualenv -p python3 $(venv-name)
91 $(activate) && python -m pip install --upgrade pip
92 $(activate) && pip install --upgrade setuptools
93 $(activate) && [[ -r requirements.txt ]] \
94 && { python -m pip install -r requirements.txt; } \
95 || { /bin/true; }
96
97 $(activate) && python --version
98
99## -----------------------------------------------------------------------
100## Intent: Explicit named installer target w/o dependencies.
101## Makefile targets should depend on venv-activate-script.
102## -----------------------------------------------------------------------
103venv-activate-patched := $(venv-activate-script).patched
104venv-activate-patched : $(venv-activate-patched)
105$(venv-activate-patched) : $(venv-activate-script)
106 $(call banner-enter,Target $@)
107 $(onf-mk-top)/../patches/python_310_migration.sh --venv "$(venv-name)" 'apply'
108 touch $@
109 $(call banner-leave,Target $@)
110
111## -----------------------------------------------------------------------
112## Intent: Explicit named installer target w/o dependencies.
113## Makefile targets should depend on venv-activate-script.
114## -----------------------------------------------------------------------
115venv += $(venv-activate-script)
116venv += $(venv-requirements-txt)
117venv: $(venv)
118
119## -----------------------------------------------------------------------
120## Intent: Revert installation to a clean checkout
121## -----------------------------------------------------------------------
122sterile :: clean
123 $(RM) -r "$(venv-abs-path)"
124
125## -----------------------------------------------------------------------
126## -----------------------------------------------------------------------
127help ::
128 @echo
129 @echo '[VIRTUAL ENV]'
130 @echo ' venv Create a python virtual environment'
131 @echo ' venv-name= Subdir name for virtualenv install'
132 @echo ' venv-activate-script make macro name'
133 @echo ' $$(target) dependency install python virtualenv'
134 @echo ' source $$(macro) && cmd configure env and run cmd'
135
136$(if $(DEBUG),$(warning LEAVE))
137
138# [EOF]