From 8f1a6b15eecd651c7c9fd2edd26da8df77f3c02e Mon Sep 17 00:00:00 2001 From: Lukas Trippe Date: Tue, 1 Oct 2024 09:18:53 +0200 Subject: [PATCH 1/2] test: log env diff (#1338) --- .github/workflows/test.yaml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4308276fb..0649ec7a5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,6 +21,7 @@ concurrency: env: ENV_FILE: envs/environment.yaml + ENV_FIXED_FILE: envs/environment.fixed.yaml jobs: run-tests: @@ -62,16 +63,39 @@ jobs: uses: actions/cache@v4 with: path: ${{ env.CONDA }}/envs - key: conda-${{ runner.os }}-${{ runner.arch }}-${{ env.today }}-${hashFiles('${{ env.ENV_FILE }}')} + key: conda-${{ runner.os }}-${{ runner.arch }}-${{ env.today }}-${{ hashFiles(format('{0}', env.ENV_FILE)) }} id: cache-env - name: Update environment if: steps.cache-env.outputs.cache-hit != 'true' run: conda env update -n pypsa-eur -f ${{ env.ENV_FILE }} + - name: Log env diff to environment.fixed.yaml + if: ${{ matrix.os == 'ubuntu' }} + run: | + # Get fixed environment of current env + conda env export --name ${{ github.event.repository.name }} --no-builds | sed 's/^name: ${{ github.event.repository.name }}$/name: ${{ github.event.repository.name }}-fixed/' > current-env.yaml + + # Add SPDX header + SPDX_HEADER="# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors\n# SPDX-License-Identifier: CC0-1.0\n" + echo -e "$SPDX_HEADER" | cat - current-env.yaml > temp && mv temp current-env.yaml + + # Format with pre-commit (it differs from the conda output) + pip install pre-commit + pre-commit run --files current-env.yaml || true + + # Get diff + diff ${{ env.ENV_FIXED_FILE }} current-env.yaml > diff.txt || true + + # Format + { echo -e "**Environment diff**\n\`\`\` diff\n"; cat diff.txt; echo -e "\n\`\`\`"; } > temp && mv temp diff.txt + + # Write to summary + cat diff.txt >> $GITHUB_STEP_SUMMARY + shell: bash + - name: Run snakemake test workflows run: | - conda activate pypsa-eur make test - name: Upload artifacts @@ -137,7 +161,7 @@ jobs: uses: actions/cache@v4 with: path: ${{ env.CONDA }}/envs - key: conda-${{ runner.os }}-${{ runner.arch }}-${{ matrix.inhouse }}-${{ env.today }}-${hashFiles('${{ env.ENV_FILE }}')} + key: conda-${{ runner.os }}-${{ runner.arch }}-${{ matrix.inhouse }}-${{ env.today }}-${{ hashFiles(format('{0}', env.ENV_FILE)) }} id: cache-env - name: Update environment @@ -152,7 +176,6 @@ jobs: - name: Run snakemake test workflows if: env.pinned == 'false' run: | - conda activate pypsa-eur make test - name: Upload artifacts From dc6ea50bf62bce04a5257823a7416a09a9a54f80 Mon Sep 17 00:00:00 2001 From: Davide Fioriti <67809479+davide-f@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:09:50 +0200 Subject: [PATCH 2/2] Update mock_snakemake --- scripts/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 3f6eac405..195dd4bfe 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -434,7 +434,7 @@ def mock_snakemake( import os import snakemake as sm - from pypsa.descriptors import Dict + from pypsa.definitions.structures import Dict from snakemake.api import Workflow from snakemake.common import SNAKEFILE_CHOICES from snakemake.script import Snakemake