OS _ makefile - dwisianto/dwisianto GitHub Wiki

Env Vars

Makefile Location

Makefile and Env Variables

Makefile and Anaconda

# Oneshell means I can run multiple lines in a recipe in the same shell, so I don't have to
# chain commands together with semicolon
.ONESHELL:
# Need to specify bash in order for conda activate to work.
SHELL=/bin/bash
# Note that the extra activate is needed to ensure that the activate floats env to the front of PATH
CONDA_ACTIVATE=source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate

test:
    $(CONDA_ACTIVATE) eg_env
    echo $$(which python)

# format the file with black
lint:
    $(CONDA_ACTIVATE) eg_env
    black eg.py

# Run the file directly
run_py:
    $(CONDA_ACTIVATE) eg_env
    python eg.py

# Run the file from a shell script
run_sh:
    $(CONDA_ACTIVATE) eg_env
    bash eg.sh

eg_env.yml

name: eg_env
dependencies:
    - numpy
    - black

eg.sh

#!/bin/bash

echo "This is my test bash script"
echo "Activating conda environment"
eval "$($(which conda) 'shell.bash' 'hook')"
conda activate eg_env
echo "Running python script"
python eg.py

Makefile and Jupyter