|
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, use the installed vivarium_build_utils package |
7 | | - MAKE_INCLUDES := $(shell python -c "from vivarium_build_utils.resources import get_makefiles_path; print(get_makefiles_path())") |
| 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 = gbd_mapping |
| 19 | +# Set the package name as the last part of this file's parent directory path |
| 20 | +PACKAGE_NAME = $(notdir $(CURDIR)) |
11 | 21 |
|
| 22 | +ifneq ($(MAKE_INCLUDES),) # not empty |
12 | 23 | # Include makefiles from vivarium_build_utils |
13 | 24 | include $(MAKE_INCLUDES)/base.mk |
14 | 25 | include $(MAKE_INCLUDES)/test.mk |
| 26 | +else # empty |
| 27 | +# Use this help message (since the vivarium_build_utils version is not available) |
| 28 | +help: |
| 29 | + @echo |
| 30 | + @echo "For Make's standard help, run 'make --help'." |
| 31 | + @echo |
| 32 | + @echo "Most of our Makefile targets are provided by the vivarium_build_utils" |
| 33 | + @echo "package. To access them, you need to create a development environment first." |
| 34 | + @echo |
| 35 | + @echo "make build-env" |
| 36 | + @echo |
| 37 | + @echo "USAGE:" |
| 38 | + @echo " make build-env name=<environment_name> [py=<python_version>]" |
| 39 | + @echo |
| 40 | + @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" |
| 47 | + @echo |
| 48 | + @echo "After creating the environment:" |
| 49 | + @echo " 1. Activate it: 'conda activate <environment_name>'" |
| 50 | + @echo " 2. Run 'make help' again to see all newly available targets" |
| 51 | + @echo |
| 52 | +endif |
| 53 | + |
| 54 | +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 |
| 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('.')))))")) |
| 62 | + conda create -n $(name) python=$(py) --yes |
| 63 | +# Bootstrap vivarium_build_utils into the new environment |
| 64 | + conda run -n $(name) pip install vivarium_build_utils |
| 65 | + conda run -n $(name) make install |
| 66 | + @echo |
| 67 | + @echo "Environment built ($(name))" |
| 68 | + @echo "Don't forget to activate it with: 'conda activate $(name)'" |
| 69 | + @echo |
0 commit comments