test: use makefile (#1315)

* test: use makefile

* more make commands
This commit is contained in:
Lukas Trippe 2024-09-23 10:13:20 +02:00 committed by GitHub
parent a6ac2b4865
commit 6387c46c2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 16 deletions

View File

@ -99,7 +99,7 @@ jobs:
- name: Run snakemake test workflows - name: Run snakemake test workflows
run: | run: |
./test.sh make test
- name: Upload artifacts - name: Upload artifacts
if: matrix.os == 'ubuntu' && matrix.inhouse == 'stable-inhouse-deps' if: matrix.os == 'ubuntu' && matrix.inhouse == 'stable-inhouse-deps'

View File

@ -23,7 +23,7 @@ jobs:
- name: Update environment.fixed.yaml - name: Update environment.fixed.yaml
run: | run: |
conda env export --name pypsa-eur --no-builds > envs/environment.fixed.yaml conda env export --name pypsa-eur-fixed --no-builds > envs/environment.fixed.yaml
- name: Add SPDX header - name: Add SPDX header
run: | run: |

59
Makefile Executable file
View File

@ -0,0 +1,59 @@
# SPDX-FileCopyrightText: : 2021-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: CC0-1.0
.PHONY: _conda_check install install-fixed test clean-tests reset
# Helper: Check if conda or mamba is installed and set CONDA_OR_MAMBA variable
_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) \
else \
echo "Neither Conda nor Mamba is installed. Please install one of them and retry."; \
exit 1; \
fi
# Install the environment
install: _conda_check
@$(CONDA_OR_MAMBA) env create -f envs/environment.yaml
@$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install
# Install fixed environment
install-fixed: _conda_check
@$(CONDA_OR_MAMBA) env create -f envs/environment.fixed.yaml
@$(CONDA_OR_MAMBA) run -n pypsa-eur pre-commit install
# Run default tests
test:
set -e
snakemake -call solve_elec_networks --configfile config/test/config.electricity.yaml --rerun-triggers=mtime
snakemake -call all --configfile config/test/config.overnight.yaml --rerun-triggers=mtime
snakemake -call all --configfile config/test/config.myopic.yaml --rerun-triggers=mtime
snakemake -call make_summary_perfect --configfile config/test/config.perfect.yaml --rerun-triggers=mtime
snakemake -call all --configfile config/test/config.scenarios.yaml --rerun-triggers=mtime -n
echo "All tests completed successfully."
# Cleans all output files from tests
clean-tests:
snakemake -call solve_elec_networks --configfile config/test/config.electricity.yaml --rerun-triggers=mtime --delete-all-output
snakemake -call all --configfile config/test/config.overnight.yaml --rerun-triggers=mtime --delete-all-output
snakemake -call all --configfile config/test/config.myopic.yaml --rerun-triggers=mtime --delete-all-output
snakemake -call make_summary_perfect --configfile config/test/config.perfect.yaml --rerun-triggers=mtime --delete-all-output
snakemake -call all --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 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; \
echo "Reset completed." \
) || echo "Reset cancelled."

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors # SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
name: pypsa-eur name: pypsa-eur-fixed
channels: channels:
- conda-forge - conda-forge
- bioconda - bioconda

13
test.sh
View File

@ -1,13 +0,0 @@
# SPDX-FileCopyrightText: : 2021-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: CC0-1.0
set -x && \
snakemake -call solve_elec_networks --configfile config/test/config.electricity.yaml --rerun-triggers=mtime && \
snakemake -call all --configfile config/test/config.overnight.yaml --rerun-triggers=mtime && \
snakemake -call all --configfile config/test/config.myopic.yaml --rerun-triggers=mtime && \
snakemake -call make_summary_perfect --configfile config/test/config.perfect.yaml --rerun-triggers=mtime && \
snakemake -call all --configfile config/test/config.scenarios.yaml --rerun-triggers=mtime -n && \
set +x