Skip to content

Commit e71a3cc

Browse files
update makefile to modern version (#16)
1 parent 530ac27 commit e71a3cc

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
**v0.3.1 - 01/26/2026**
1+
**v0.3.1 - 01/27/2026**
22

3-
- Adjust the parameters for run_benchmark command.
3+
- Adjust the parameters for run_benchmark command
4+
- Update makefile
45

56
**v0.3.0 - 01/22/2026**
67

Makefile

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ endif
1919
# Set the package name as the last part of this file's parent directory path
2020
PACKAGE_NAME = $(notdir $(CURDIR))
2121

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+
2225
ifneq ($(MAKE_INCLUDES),) # not empty
2326
# Include makefiles from vivarium_build_utils
2427
include $(MAKE_INCLUDES)/base.mk
@@ -35,15 +38,19 @@ help:
3538
@echo "make build-env"
3639
@echo
3740
@echo "USAGE:"
38-
@echo " make build-env name=<environment_name> [py=<python_version>]"
41+
@echo " make build-env [type=<environment type>] [name=<environment name>] [py=<python version>] [include_timestamp=<yes|no>] [lfs=<yes|no>]"
3942
@echo
4043
@echo "ARGUMENTS:"
41-
@echo " name [required] Name of the conda environment to create"
42-
@echo " py [optional] Python version (defaults to latest supported)"
43-
@echo
44-
@echo "EXAMPLE:"
45-
@echo " make build-env name=vivarium_dev"
46-
@echo " make build-env name=vivarium_dev py=3.9"
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)"
4754
@echo
4855
@echo "After creating the environment:"
4956
@echo " 1. Activate it: 'conda activate <environment_name>'"
@@ -52,18 +59,58 @@ help:
5259
endif
5360

5461
build-env: # Create a new environment with installed packages
55-
ifndef name
56-
@echo "Error: name is required and must be passed in as a keyword argument."
57-
@echo "Usage: make build-env name=<ENV_NAME> py=<PYTHON_VERSION>"
58-
@exit 1
59-
endif
60-
# Check if py is set, otherwise use the latest supported version
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
6191
@$(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+
6293
conda create -n $(name) python=$(py) --yes
6394
# Bootstrap vivarium_build_utils into the new environment
6495
conda run -n $(name) pip install vivarium_build_utils
65-
conda run -n $(name) make install
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)"
66114
@echo
67-
@echo "Environment built ($(name))"
68115
@echo "Don't forget to activate it with: 'conda activate $(name)'"
69116
@echo

0 commit comments

Comments
 (0)