@@ -35,15 +35,13 @@ help:
3535 @echo " make build-env"
3636 @echo
3737 @echo " USAGE:"
38- @echo " make build-env name=<environment_name> [py=<python_version >]"
38+ @echo " make build-env [ name=<environment name>] [py=<python version >]"
3939 @echo
4040 @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"
41+ @echo " name [optional]"
42+ @echo " Name of the conda environment to create (defaults to <PACKAGE_NAME>)"
43+ @echo " py [optional]"
44+ @echo " Python version (defaults to latest supported)"
4745 @echo
4846 @echo " After creating the environment:"
4947 @echo " 1. Activate it: 'conda activate <environment_name>'"
@@ -52,18 +50,43 @@ help:
5250endif
5351
5452build-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
61- @$(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('.')))))"))
53+ # Validate arguments - exit if unsupported arguments are passed
54+ @allowed="name py"; \
55+ for arg in $(filter-out build-env,$(MAKECMDGOALS)) $(MAKEFLAGS); do \
56+ case $$arg in \
57+ *=*) \
58+ arg_name=$${arg%%=*}; \
59+ if ! echo " $$allowed " | grep -q " $$arg_name "; then \
60+ allowed_list=$$(echo $$allowed | sed 's/ /, /g'); \
61+ echo "Error: Invalid argument '$$arg_name'. Allowed arguments are: $$allowed_list" >&2; \
62+ exit 1; \
63+ fi \
64+ ;; \
65+ esac; \
66+ done
67+
68+ # Handle arguments and set defaults
69+ # name
70+ @$(eval name ?= $(PACKAGE_NAME))
71+ # python version - validate if specified, else get default from json file
72+ @supported_versions=$$(python -c "import json; print(' '.join(json.load(open('python_versions.json'))))" 2>/dev/null || echo ""); \
73+ if [ -n "$(py)" ] && ! echo "$$supported_versions" | grep -q "$(py)"; then \
74+ echo "Error: Python version '$(py)' is not supported. Available: $$(echo $$supported_versions | sed 's/ /, /g')" >&2; \
75+ exit 1; \
76+ fi
77+ @$(eval py ?= $(shell python -c "import json; print(max(json.load(open('python_versions.json')), key=lambda x: tuple(map(int, x.split('.')))))"))
78+
79+
6280 conda create -n $(name) python=$(py) --yes
6381# Bootstrap vivarium_build_utils into the new environment
6482 conda run -n $(name) pip install vivarium_build_utils
6583 conda run -n $(name) make install
84+
85+ @echo
86+ @echo "Finished building environment"
87+ @echo " name: $(name)"
88+ @echo " python version: $(py)"
6689 @echo
67- @echo "Environment built ($(name)) "
68- @echo "Don't forget to activate it with: ' conda activate $(name)' "
90+ @echo "Don't forget to activate it with: "
91+ @echo "conda activate $(name)"
6992 @echo
0 commit comments