forked from PyPSA/pypsa-eur
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·113 lines (98 loc) · 5.54 KB
/
Makefile
File metadata and controls
executable file
·113 lines (98 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>
#
# SPDX-License-Identifier: CC0-1.0
.ONESHELL:
.PHONY: _conda_check install install-pinned-linux install-pinned-windows install-pinned-macos install-lock-linux64 install-lock-linux-arm install-lock-windows install-lock-macos64 install-lock-macos-arm 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 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 \
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
# Install from conda-lock files (recommended)
install-lock-linux64: _conda_check
$(CONDA_OR_MAMBA) env create -f envs/linux-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
install-lock-windows: _conda_check
$(CONDA_OR_MAMBA) env create -f envs/win-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
install-lock-macos64: _conda_check
$(CONDA_OR_MAMBA) env create -f envs/osx-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
install-lock-macos-arm: _conda_check
$(CONDA_OR_MAMBA) env create -f envs/osx-arm64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
# Install pinned environment (deprecated, but maintained for backward compatibility)
install-pinned-linux: _conda_check
@echo "WARNING: The 'install-pinned-linux' target is deprecated and will be removed in a future release."
@echo "Please use 'install-lock-linux64' (for x86_64) or 'install-lock-linux-arm' (for ARM) instead"
@echo "Or directly use: conda env create -f envs/linux-64.lock.yaml"
$(CONDA_OR_MAMBA) env create -f envs/linux-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
install-pinned-windows: _conda_check
@echo "WARNING: The 'install-pinned-windows' target is deprecated and will be removed in a future release."
@echo "Please use 'install-lock-windows' instead"
@echo "Or directly use: conda env create -f envs/win-64.lock.yaml"
$(CONDA_OR_MAMBA) env create -f envs/win-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
install-pinned-macos: _conda_check
@echo "WARNING: The 'install-pinned-macos' target is deprecated and will be removed in a future release."
@echo "Please use 'install-lock-macos64' (for Intel) or 'install-lock-macos-arm' (for Apple Silicon) instead"
@echo "Or directly use: conda env create -f envs/osx-64.lock.yaml"
$(CONDA_OR_MAMBA) env create -f envs/osx-64.lock.yaml -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
# Run default tests
test:
set -e
snakemake -call solve_elec_networks --configfile config/test/config.electricity.yaml
snakemake -call --configfile config/test/config.overnight.yaml
snakemake -call --configfile config/test/config.myopic.yaml
snakemake -call make_summary_perfect --configfile config/test/config.perfect.yaml
snakemake -call resources/test-elec-clusters/networks/base_s_adm.nc --configfile config/test/config.clusters.yaml
snakemake -call --configfile config/test/config.scenarios.yaml -n
snakemake -call plot_power_networks_clustered --configfile config/test/config.tyndp.yaml
echo "All tests completed successfully."
unit-test:
pytest test
# Cleans all output files from tests
clean-tests:
snakemake -call solve_elec_networks --configfile config/test/config.electricity.yaml --delete-all-output
snakemake -call --configfile config/test/config.overnight.yaml --delete-all-output
snakemake -call --configfile config/test/config.myopic.yaml --delete-all-output
snakemake -call make_summary_perfect --configfile config/test/config.perfect.yaml --delete-all-output
snakemake -call resources/test-elec-clusters/networks/base_s_adm.nc --configfile config/test/config.clusters.yaml --delete-all-output
snakemake -call --configfile config/test/config.scenarios.yaml -n --delete-all-output
snakemake -call plot_power_networks_clustered --configfile config/test/config.tyndp.yaml --delete-all-output
# Removes all created files except for large cutout files (similar to fresh clone)
reset:
@echo "Do you really wanna continue? This will remove logs, resources, benchmarks, results, and .snakemake directories (config/config.yaml will not be deleted) (y/n): " && \
read ans && [ $${ans} = y ] && ( \
rm -r ./logs || true; \
rm -r ./resources || true; \
rm -r ./benchmarks || true; \
rm -r ./results || true; \
rm -r ./.snakemake || true; \
echo "Reset completed." \
) || echo "Reset cancelled."