Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
Joey Armstrong | f2f0a3f | 2024-04-04 15:50:09 -0400 | [diff] [blame] | 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2017-2024 Open Networking Foundation Contributors |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 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 | # |
Joey Armstrong | f2f0a3f | 2024-04-04 15:50:09 -0400 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 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 | f2f0a3f | 2024-04-04 15:50:09 -0400 | [diff] [blame] | 17 | # SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | # ----------------------------------------------------------------------- |
Joey Armstrong | c86d035 | 2023-11-09 10:31:10 -0500 | [diff] [blame] | 21 | # Intent: |
| 22 | # This makefile defines dependencies that will install a python virtualenv |
| 23 | # beneath $(sandbox)/.venv/. The $(activate) macro is used to source |
| 24 | # .venv/bin/activate allowing command python and pip to be used. |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 25 | # ----------------------------------------------------------------------- |
| 26 | # Usage: |
Joey Armstrong | c86d035 | 2023-11-09 10:31:10 -0500 | [diff] [blame] | 27 | # include makefiles/virtualenv/include.mk |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 28 | # |
Joey Armstrong | c86d035 | 2023-11-09 10:31:10 -0500 | [diff] [blame] | 29 | # Makefile Target Dependencies: |
| 30 | # tgt : $(venv-activate-patched) # python 3.10+ local use |
| 31 | # tgt : $(venv-activate-script) # python < v3.8 |
| 32 | # |
| 33 | # Make definitions (convenience macros used for command access) |
| 34 | # PIP := $(activate) && pip # invoke pip from virtualenv |
| 35 | # PYTHON := $(activate) && python # invoke python from virtualenv |
| 36 | # |
| 37 | # Target declaration and command invocation: |
| 38 | # my-target : $(venv-activate-script) # dependency installs virtualenv |
| 39 | # <tab>$(PYTHON) --version # invoke python with arguments |
| 40 | # <tab>$(PYTHON) my-command.py |
| 41 | # <tab>$(activate) && pip install foobar |
| 42 | # |
| 43 | # % make my-target # Invoke make target from shell |
Joey Armstrong | e98239c | 2023-05-08 17:10:07 -0400 | [diff] [blame] | 44 | # ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 45 | |
| 46 | $(if $(DEBUG),$(warning ENTER)) |
| 47 | |
| 48 | ##-------------------## |
| 49 | ##---] GLOBALS [---## |
| 50 | ##-------------------## |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 51 | .PHONY: venv venv-patched |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 52 | |
| 53 | ##------------------## |
| 54 | ##---] LOCALS [---## |
| 55 | ##------------------## |
| 56 | venv-name ?= .venv# # default install directory |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 57 | venv-abs-path := $(sandbox-root)/$(venv-name)# # Install directory |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 58 | venv-activate-bin := $(venv-name)/bin# # no whitespace |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 59 | venv-activate-script := $(venv-activate-bin)/activate# # dependency |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 60 | |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 61 | ##--------------------## |
| 62 | ##---] INCLUDES [---## |
| 63 | ##--------------------## |
Joey Armstrong | a5d8679 | 2024-04-22 15:49:29 -0400 | [diff] [blame] | 64 | include $(onf-mk-dir)/virtualenv/requirements-txt.mk |
| 65 | include $(onf-mk-dir)/virtualenv/version.mk |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 66 | |
Joey Armstrong | c86d035 | 2023-11-09 10:31:10 -0500 | [diff] [blame] | 67 | # ------------------------------------------------------------------------ |
| 68 | # Intent: Define macro activate= to access virtualenv activation script. |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 69 | ## ----------------------------------------------------------------------- |
Joey Armstrong | c86d035 | 2023-11-09 10:31:10 -0500 | [diff] [blame] | 70 | # Usage: |
| 71 | # - $(activate) && python # Syntax inlined within a target |
| 72 | # - PYTHON := $(activate) && python # Define a named command macro |
| 73 | # ------------------------------------------------------------------------ |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 74 | activate ?= set +u && source $(venv-activate-script) && set -u |
| 75 | |
| 76 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 77 | ## Intent: Explicit named installer target w/o dependencies. |
| 78 | ## Makefile targets should depend on venv-activate-script. |
| 79 | ## ----------------------------------------------------------------------- |
| 80 | venv := $(null) |
| 81 | venv += $(venv-activate-script)# # virtualenv -p python3 |
| 82 | venv += $(venv-requirements-txt)# # pip install -r requirements.txt |
| 83 | venv: $(venv) |
| 84 | |
| 85 | venv-patched : $(venv-activate-patched) |
| 86 | |
| 87 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 88 | ## Intent: Activate script path dependency |
| 89 | ## Usage: |
| 90 | ## o place on the right side of colon as a target dependency |
| 91 | ## o When the script does not exist install the virtual env and display. |
| 92 | ## ----------------------------------------------------------------------- |
| 93 | $(venv-activate-script): |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 94 | |
| 95 | $(call banner-enter,(virtualenv -p python)) |
| 96 | |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 97 | virtualenv -p python3 $(venv-name) |
| 98 | $(activate) && python -m pip install --upgrade pip |
| 99 | $(activate) && pip install --upgrade setuptools |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 100 | |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 101 | $(HIDE)$(MAKE) --no-print-directory venv-requirements venv-version |
| 102 | |
| 103 | $(call banner-leave,(virtualenv -t python)) |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 104 | |
| 105 | ## ----------------------------------------------------------------------- |
| 106 | ## Intent: Explicit named installer target w/o dependencies. |
| 107 | ## Makefile targets should depend on venv-activate-script. |
| 108 | ## ----------------------------------------------------------------------- |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 109 | venv-activate-patched := $(venv-activate-script).patched |
| 110 | venv-activate-patched : $(venv-activate-patched) |
| 111 | $(venv-activate-patched) : $(venv-activate-script) |
| 112 | $(call banner-enter,Target $@) |
Joey Armstrong | a5d8679 | 2024-04-22 15:49:29 -0400 | [diff] [blame] | 113 | $(onf-mk-dir)/virtualenv/python_310_migration.sh |
Joey Armstrong | e6a9991 | 2023-09-15 14:47:51 -0400 | [diff] [blame] | 114 | touch $@ |
| 115 | $(call banner-leave,Target $@) |
| 116 | |
| 117 | ## ----------------------------------------------------------------------- |
| 118 | ## Intent: Explicit named installer target w/o dependencies. |
| 119 | ## Makefile targets should depend on venv-activate-script. |
| 120 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 121 | # venv : $(venv-activate-script) |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 122 | |
| 123 | ## ----------------------------------------------------------------------- |
| 124 | ## Intent: Revert installation to a clean checkout |
| 125 | ## ----------------------------------------------------------------------- |
| 126 | sterile :: clean |
| 127 | $(RM) -r "$(venv-abs-path)" |
| 128 | |
| 129 | ## ----------------------------------------------------------------------- |
| 130 | ## ----------------------------------------------------------------------- |
| 131 | help :: |
Joey Armstrong | 62ae139 | 2024-03-17 20:49:30 -0400 | [diff] [blame] | 132 | @printf ' %-33.33s %s\n' 'venv' \ |
| 133 | 'Create a python virtual environment' |
| 134 | @printf ' %-33.33s %s\n' 'venv-help' \ |
| 135 | 'Extended target help' |
| 136 | |
| 137 | ## ----------------------------------------------------------------------- |
| 138 | ## ----------------------------------------------------------------------- |
| 139 | venv-help :: |
| 140 | @printf ' %-33.33s %s\n' 'venv-patched' \ |
| 141 | 'venv patched for v3.10.6+ use' |
| 142 | |
| 143 | @printf ' %-33.33s %s\n' 'venv' \ |
| 144 | 'Create a python virtual environment' |
| 145 | @printf ' %-33.33s %s\n' ' venv-name' \ |
| 146 | 'virtualenv installation directory name' |
| 147 | |
Joey Armstrong | 3aabfdf | 2024-04-02 15:06:03 -0400 | [diff] [blame] | 148 | include $(onf-mk-dir)/virtualenv/todo.mk |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 149 | |
| 150 | $(if $(DEBUG),$(warning LEAVE)) |
| 151 | |
| 152 | # [EOF] |