Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 1 | # -*- 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 Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
Joey Armstrong | e98239c | 2023-05-08 17:10:07 -0400 | [diff] [blame] | 17 | # https://gerrit.opencord.org/plugins/gitiles/onf-make |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 18 | # 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 Armstrong | e98239c | 2023-05-08 17:10:07 -0400 | [diff] [blame] | 26 | # ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 27 | |
| 28 | $(if $(DEBUG),$(warning ENTER)) |
| 29 | |
| 30 | ##-------------------## |
| 31 | ##---] GLOBALS [---## |
| 32 | ##-------------------## |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 33 | .PHONY: venv venv-patched |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 34 | |
| 35 | ##------------------## |
| 36 | ##---] LOCALS [---## |
| 37 | ##------------------## |
| 38 | venv-name ?= .venv# # default install directory |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 39 | venv-abs-path := $(PWD)/$(venv-name)# # |
| 40 | venv-activate-bin := $(venv-name)/bin# # no whitespace |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 41 | venv-activate-script := $(venv-activate-bin)/activate# # dependency |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 42 | |
| 43 | # Intent: activate= is a macro for accessing the virtualenv activation script# |
| 44 | # Usage: $(activate) && python |
| 45 | activate ?= 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 Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 55 | @echo '=============================' |
| 56 | @echo 'Installing python virtual env' |
| 57 | @echo '=============================' |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 58 | virtualenv -p python3 $(venv-name) |
| 59 | $(activate) && python -m pip install --upgrade pip |
| 60 | $(activate) && pip install --upgrade setuptools |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 61 | $(activate) && [[ -r requirements.txt ]] \ |
| 62 | && { python -m pip install -r requirements.txt; } \ |
| 63 | || { /bin/true; } |
| 64 | |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 65 | $(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 Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 71 | venv-activate-patched := $(venv-activate-script).patched |
| 72 | venv-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 | ## ----------------------------------------------------------------------- |
| 83 | venv : $(venv-activate-script) |
| 84 | venv-patched : $(venv-activate-patched) |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 85 | |
| 86 | ## ----------------------------------------------------------------------- |
| 87 | ## Intent: Revert installation to a clean checkout |
| 88 | ## ----------------------------------------------------------------------- |
| 89 | sterile :: clean |
| 90 | $(RM) -r "$(venv-abs-path)" |
| 91 | |
| 92 | ## ----------------------------------------------------------------------- |
| 93 | ## ----------------------------------------------------------------------- |
| 94 | help :: |
| 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] |