From 12d7107c54a2036f920d8b45cfaaed1f85abf7c7 Mon Sep 17 00:00:00 2001 From: Fabian Hofmann Date: Thu, 19 Dec 2024 17:55:15 +0100 Subject: [PATCH] feat: prioritize mamba over conda, allow passing environment target name to installation (#1461) * feat: prioritize mamba over conda, allow passing environment target name to installation * add prio flag --------- Co-authored-by: lkstrp --- Makefile | 53 ++++++++++++++++++++++++++++--------------- doc/release_notes.rst | 4 ++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index c8763702d..9d2f5fea5 100755 --- a/Makefile +++ b/Makefile @@ -2,37 +2,54 @@ # # SPDX-License-Identifier: CC0-1.0 +.ONESHELL: + .PHONY: _conda_check install install-pinned-linux install-pinned-windows install-pinned-macos test checks clean-tests reset # Helper: Check if conda or mamba is installed and set CONDA_OR_MAMBA variable +# mamba is preferred over conda if both are installed, unless PYPSA_PREFER_CONDA is set to true _conda_check: - @# Check if conda or mamba is installed and set CONDA_OR_MAMBA variable - @if command -v conda &> /dev/null; then \ - echo "Conda detected, using Conda..."; \ - $(eval CONDA_OR_MAMBA := conda) \ - elif command -v mamba &> /dev/null; then \ - echo "Conda not found, but Mamba detected. Using Mamba..."; \ - $(eval CONDA_OR_MAMBA := mamba) \ + @# Check prefer_conda environment variable + @if [ "$$PYPSA_PREFER_CONDA" = "true" ]; then \ + if command -v conda &> /dev/null; then \ + echo "Conda preferred and detected. Using Conda..."; \ + $(eval CONDA_OR_MAMBA := conda) \ + elif command -v mamba &> /dev/null; then \ + echo "Conda preferred but not found. Using Mamba..."; \ + $(eval CONDA_OR_MAMBA := mamba) \ + else \ + echo "Neither Conda nor Mamba is installed. Please install one of them and retry."; \ + exit 1; \ + fi \ else \ - echo "Neither Conda nor Mamba is installed. Please install one of them and retry."; \ - exit 1; \ + if command -v mamba &> /dev/null; then \ + echo "Mamba detected, using Mamba..."; \ + $(eval CONDA_OR_MAMBA := mamba) \ + elif command -v conda &> /dev/null; then \ + echo "Mamba not found, but Conda detected. Using Conda..."; \ + $(eval CONDA_OR_MAMBA := conda) \ + else \ + echo "Neither Conda nor Mamba is installed. Please install one of them and retry."; \ + exit 1; \ + fi \ fi # Install environment +# E.g. make install or make install name=myenv install: _conda_check - @$(CONDA_OR_MAMBA) env create -f envs/environment.yaml - @$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install - + $(CONDA_OR_MAMBA) env create -f envs/environment.yaml -n $(or $(name), pypsa-eur) + $(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install # Install pinned environment install-pinned-linux: _conda_check - @$(CONDA_OR_MAMBA) env create -f envs/pinned-linux.yaml - @$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install + $(CONDA_OR_MAMBA) env create -f envs/pinned-linux.yaml -n $(or $(name), pypsa-eur) + $(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install install-pinned-windows: _conda_check - @$(CONDA_OR_MAMBA) env create -f envs/pinned-windows.yaml - @$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install + $(CONDA_OR_MAMBA) env create -f envs/pinned-windows.yaml -n $(or $(name), pypsa-eur) + $(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install install-pinned-macos: _conda_check - @$(CONDA_OR_MAMBA) env create -f envs/pinned-macos.yaml - @$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install + $(CONDA_OR_MAMBA) env create -f envs/pinned-macos.yaml -n $(or $(name), pypsa-eur) + $(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install + # Run default tests test: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 749b96b0b..20ed8929a 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -109,6 +109,10 @@ Upcoming Release * Bugfix: Align the naming convention for the CO2 network configuration (from `co2network` to `co2_network`). This may be a small breaking change. +* Feature: The installation via `make install` now prioritizes mamba over conda for faster installation. Conda is still used as a fallback. The command `make install` now also supports passing the name of the environment, e.g. `make install name=my-project`. + + + PyPSA-Eur 0.13.0 (13th September 2024) ======================================