|
1 | 1 | # Check if we're running in Jenkins |
2 | 2 | ifdef JENKINS_URL |
3 | | - # Files are already in workspace from shared library |
| 3 | +# Files are already in workspace from shared library |
4 | 4 | MAKE_INCLUDES := . |
5 | 5 | else |
6 | | - # For local dev, search in parent directory |
7 | | - MAKE_INCLUDES := ../vivarium_build_utils/resources/makefiles |
| 6 | +# For local dev, use the installed vivarium_build_utils package if it exists |
| 7 | +# First, check if we can import vivarium_build_utils and assign 'yes' or 'no'. |
| 8 | +# We do this by importing the package in python and redirecting stderr to the null device. |
| 9 | +# If the import is successful (&&), it will print 'yes', otherwise (||) it will print 'no'. |
| 10 | + VIVARIUM_BUILD_UTILS_AVAILABLE := $(shell python -c "import vivarium_build_utils" 2>/dev/null && echo "yes" || echo "no") |
| 11 | +# If vivarium_build_utils is available, get the makefiles path or else set it to empty |
| 12 | + ifeq ($(VIVARIUM_BUILD_UTILS_AVAILABLE),yes) |
| 13 | + MAKE_INCLUDES := $(shell python -c "from vivarium_build_utils.resources import get_makefiles_path; print(get_makefiles_path())") |
| 14 | + else |
| 15 | + MAKE_INCLUDES := |
| 16 | + endif |
8 | 17 | endif |
9 | 18 |
|
10 | | -PACKAGE_NAME = vivarium_gates_nutrition_optimization_child |
| 19 | +# Set the package name as the last part of this file's parent directory path |
| 20 | +PACKAGE_NAME = $(notdir $(CURDIR)) |
11 | 21 |
|
| 22 | +# Helper function for validating enum arguments |
| 23 | +validate_arg = $(if $(filter-out $(2),$(1)),$(error Error: '$(3)' must be one of: $(2), got '$(1)')) |
| 24 | + |
| 25 | +ifneq ($(MAKE_INCLUDES),) # not empty |
12 | 26 | # Include makefiles from vivarium_build_utils |
13 | 27 | include $(MAKE_INCLUDES)/base.mk |
14 | 28 | include $(MAKE_INCLUDES)/test.mk |
| 29 | +else # empty |
| 30 | +# Use this help message (since the vivarium_build_utils version is not available) |
| 31 | +help: |
| 32 | + @echo |
| 33 | + @echo "For Make's standard help, run 'make --help'." |
| 34 | + @echo |
| 35 | + @echo "Most of our Makefile targets are provided by the vivarium_build_utils" |
| 36 | + @echo "package. To access them, you need to create a development environment first." |
| 37 | + @echo |
| 38 | + @echo "make build-env" |
| 39 | + @echo |
| 40 | + @echo "USAGE:" |
| 41 | + @echo " make build-env [type=<environment type>] [name=<environment name>] [py=<python version>] [include_timestamp=<yes|no>] [lfs=<yes|no>]" |
| 42 | + @echo |
| 43 | + @echo "ARGUMENTS:" |
| 44 | + @echo " type [optional]" |
| 45 | + @echo " Type of conda environment. Either 'simulation' (default) or 'artifact'" |
| 46 | + @echo " name [optional]" |
| 47 | + @echo " Name of the conda environment to create (defaults to <PACKAGE_NAME>_<TYPE>)" |
| 48 | + @echo " include_timestamp [optional]" |
| 49 | + @echo " Whether to append a timestamp to the environment name. Either 'yes' or 'no' (default)" |
| 50 | + @echo " lfs [optional]" |
| 51 | + @echo " Whether to install git-lfs in the environment. Either 'yes' or 'no' (default)" |
| 52 | + @echo " py [optional]" |
| 53 | + @echo " Python version (defaults to latest supported)" |
| 54 | + @echo |
| 55 | + @echo "After creating the environment:" |
| 56 | + @echo " 1. Activate it: 'conda activate <environment_name>'" |
| 57 | + @echo " 2. Run 'make help' again to see all newly available targets" |
| 58 | + @echo |
| 59 | +endif |
| 60 | + |
| 61 | +build-env: # Create a new environment with installed packages |
| 62 | +# Validate arguments - exit if unsupported arguments are passed |
| 63 | + @allowed="type name lfs py include_timestamp"; \ |
| 64 | + for arg in $(filter-out build-env,$(MAKECMDGOALS)) $(MAKEFLAGS); do \ |
| 65 | + case $$arg in \ |
| 66 | + *=*) \ |
| 67 | + arg_name=$${arg%%=*}; \ |
| 68 | + if ! echo " $$allowed " | grep -q " $$arg_name "; then \ |
| 69 | + allowed_list=$$(echo $$allowed | sed 's/ /, /g'); \ |
| 70 | + echo "Error: Invalid argument '$$arg_name'. Allowed arguments are: $$allowed_list" >&2; \ |
| 71 | + exit 1; \ |
| 72 | + fi \ |
| 73 | + ;; \ |
| 74 | + esac; \ |
| 75 | + done |
| 76 | + |
| 77 | +# Handle arguments and set defaults |
| 78 | +# type |
| 79 | + @$(eval type ?= simulation) |
| 80 | + @$(call validate_arg,$(type),simulation artifact,type) |
| 81 | +# name |
| 82 | + @$(eval name ?= $(PACKAGE_NAME)_$(type)) |
| 83 | +# timestamp |
| 84 | + @$(eval include_timestamp ?= no) |
| 85 | + @$(call validate_arg,$(include_timestamp),yes no,include_timestamp) |
| 86 | + @$(if $(filter yes,$(include_timestamp)),$(eval override name := $(name)_$(shell date +%Y%m%d_%H%M%S)),) |
| 87 | +# lfs |
| 88 | + @$(eval lfs ?= no) |
| 89 | + @$(call validate_arg,$(lfs),yes no,lfs) |
| 90 | +# python version |
| 91 | + @$(eval py ?= $(shell python -c "import json; versions = json.load(open('python_versions.json')); print(max(versions, key=lambda x: tuple(map(int, x.split('.')))))")) |
| 92 | + |
| 93 | + conda create -n $(name) python=$(py) --yes |
| 94 | +# Bootstrap vivarium_build_utils into the new environment |
| 95 | + conda run -n $(name) pip install vivarium_build_utils |
| 96 | +# Install packages based on type |
| 97 | + @if [ "$(type)" = "simulation" ]; then \ |
| 98 | + conda run -n $(name) make install ENV_REQS=dev; \ |
| 99 | + conda install -n $(name) redis -c anaconda -y; \ |
| 100 | + elif [ "$(type)" = "artifact" ]; then \ |
| 101 | + conda run -n $(name) make install ENV_REQS=data; \ |
| 102 | + fi |
| 103 | + @if [ "$(lfs)" = "yes" ]; then \ |
| 104 | + conda run -n $(name) conda install -c conda-forge git-lfs --yes; \ |
| 105 | + conda run -n $(name) git lfs install; \ |
| 106 | + fi |
| 107 | + |
| 108 | + @echo |
| 109 | + @echo "Finished building environment" |
| 110 | + @echo " name: $(name)" |
| 111 | + @echo " type: $(type)" |
| 112 | + @echo " git-lfs installed: $(lfs)" |
| 113 | + @echo " python version: $(py)" |
| 114 | + @echo |
| 115 | + @echo "Don't forget to activate it with: 'conda activate $(name)'" |
| 116 | + @echo |
0 commit comments