Skip to content

Commit

Permalink
feat: prioritize mamba over conda, allow passing environment target n…
Browse files Browse the repository at this point in the history
…ame to installation (#1461)

* feat: prioritize mamba over conda, allow passing environment target name to installation

* add prio flag

---------

Co-authored-by: lkstrp <[email protected]>
  • Loading branch information
FabianHofmann and lkstrp authored Dec 19, 2024
1 parent e25c8ff commit 12d7107
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
53 changes: 35 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
======================================
Expand Down

0 comments on commit 12d7107

Please sign in to comment.