From 2a1e936c699c2e7920c7654ad66967fead8ac1c0 Mon Sep 17 00:00:00 2001 From: Pablo Olivares Date: Wed, 20 Mar 2024 00:15:53 +0100 Subject: [PATCH] Added makefile advances #2 --- Makefile | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0d9e5e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +# Enhanced Makefile for managing the Conda environment tda-nn-separability + +# Parameters +ENV_NAME := tda-nn-separability +PYTHON_VERSION := 3.11 +ENV_FILE := environment.yaml + +# Default goal +.PHONY: all +all: init install export + +# Check if the conda command is available +CONDA := $(shell command -v conda 2> /dev/null) + +# Initialize the Conda environment +.PHONY: init +init: +ifndef CONDA + $(error "conda is not available, please install Miniconda or Anaconda.") +endif + @echo "Creating the Conda environment if it doesn't exist..." + @conda env list | grep -q '^$(ENV_NAME) ' || \ + conda create --yes --name $(ENV_NAME) python=$(PYTHON_VERSION) + +# Install packages from an environment file or manually specified +.PHONY: install +install: init + @echo "Installing necessary packages into the Conda environment..." + @if [ -f "$(ENV_FILE)" ]; then \ + echo "Using $(ENV_FILE) to install packages..."; \ + conda env update --name $(ENV_NAME) --file $(ENV_FILE) --prune; \ + else \ + echo "No $(ENV_FILE) found. Installing default packages..."; \ + conda run --name $(ENV_NAME) conda install --yes numpy pandas scipy matplotlib; \ + fi + +# Export the current environment to a YAML file, excluding build-specific fields +.PHONY: export +export: + @echo "Exporting the Conda environment to $(ENV_FILE)..." + @conda env export --name $(ENV_NAME) --no-builds | grep -v "^prefix: " > $(ENV_FILE) + +# Update all packages in the Conda environment +.PHONY: update +update: init + @echo "Updating all packages in the Conda environment..." + @conda run --name $(ENV_NAME) conda update --all --yes + +# Run tests using pytest within the Conda environment +.PHONY: test +test: init + @echo "Running tests..." + pytest tests -v + +# Clean up __pycache__ directories and *.pyc files +.PHONY: clean +clean: + @echo "Cleaning up __pycache__ directories and *.pyc files..." + @find . -type d -name "__pycache__" -exec rm -rf {} + > /dev/null 2>&1 + @find . -type f -name "*.pyc" -delete > /dev/null 2>&1 +