Skip to content

Commit

Permalink
test: use makefile (#1315)
Browse files Browse the repository at this point in the history
* test: use makefile

* more make commands
  • Loading branch information
lkstrp authored Sep 23, 2024
1 parent a6ac2b4 commit 6387c46
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Run snakemake test workflows
run: |
./test.sh
make test
- name: Upload artifacts
if: matrix.os == 'ubuntu' && matrix.inhouse == 'stable-inhouse-deps'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-fixed-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Update environment.fixed.yaml
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
run: |
Expand Down
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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."
2 changes: 1 addition & 1 deletion envs/environment.fixed.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
# SPDX-License-Identifier: CC0-1.0

name: pypsa-eur
name: pypsa-eur-fixed
channels:
- conda-forge
- bioconda
Expand Down
13 changes: 0 additions & 13 deletions test.sh

This file was deleted.

0 comments on commit 6387c46

Please sign in to comment.