Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading