-
Notifications
You must be signed in to change notification settings - Fork 251
/
Makefile
executable file
·86 lines (77 loc) · 3.74 KB
/
Makefile
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
# SPDX-FileCopyrightText: : 2021-2024 The PyPSA-Eur Authors
#
# 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 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
# E.g. make install or make install name=myenv
install: _conda_check
$(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 -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 -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 -n $(or $(name), pypsa-eur)
$(CONDA_OR_MAMBA) run -n $(or $(name), pypsa-eur) pre-commit install
# Run default tests
test:
set -e
snakemake solve_elec_networks --configfile config/test/config.electricity.yaml --rerun-triggers=mtime
snakemake --configfile config/test/config.overnight.yaml --rerun-triggers=mtime
snakemake --configfile config/test/config.myopic.yaml --rerun-triggers=mtime
snakemake make_summary_perfect --configfile config/test/config.perfect.yaml --rerun-triggers=mtime
snakemake --configfile config/test/config.scenarios.yaml --rerun-triggers=mtime -n
echo "All tests completed successfully."
unit-test:
pytest test
# Cleans all output files from tests
clean-tests:
snakemake solve_elec_networks --configfile config/test/config.electricity.yaml --rerun-triggers=mtime --delete-all-output
snakemake --configfile config/test/config.overnight.yaml --rerun-triggers=mtime --delete-all-output
snakemake --configfile config/test/config.myopic.yaml --rerun-triggers=mtime --delete-all-output
snakemake make_summary_perfect --configfile config/test/config.perfect.yaml --rerun-triggers=mtime --delete-all-output
snakemake --configfile config/test/config.scenarios.yaml --rerun-triggers=mtime -n --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 config/config.yaml, logs, resources, benchmarks, results, and .snakemake directories (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; \
rm ./config/config.yaml || true; \
echo "Reset completed." \
) || echo "Reset cancelled."