Skip to content

Commit 7df96ce

Browse files
committed
Merge branch 'improve-transport-sector' of github.com:PyPSA/pypsa-de into improve-transport-sector
2 parents 243ba97 + 6af37e4 commit 7df96ce

File tree

80 files changed

+4813
-2347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4813
-2347
lines changed

.github/workflows/push-images.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
IMAGE_NAME: pypsa/eur-dev-env
12-
BASE_ENV: envs/linux-pinned.yaml
12+
BASE_ENV: envs/linux-64.lock.yaml
1313

1414
jobs:
1515
push-image:
@@ -32,7 +32,7 @@ jobs:
3232
username: ${{ github.repository_owner }}
3333
password: ${{ secrets.REGISTRY_TOKEN }}
3434

35-
- name: 'Build new image' # only build if the pinned envs file was modified
35+
- name: 'Build new image' # only build if the locked envs file was modified
3636
if: env.hash_last_changed == github.sha || github.event_name == 'workflow_dispatch'
3737
run: |
3838
docker build . --file docker/dev-env/Dockerfile --tag ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}

.github/workflows/test.yaml

Lines changed: 9 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,25 @@ jobs:
4040
- name: Setup env file path (ubuntu)
4141
if: matrix.os == 'ubuntu'
4242
run: |
43-
echo "env_file=envs/linux-pinned.yaml" >> $GITHUB_ENV
43+
echo "env_file=envs/linux-64.lock.yaml" >> $GITHUB_ENV
4444
4545
- name: Setup env file path (macos and windows)
4646
if: matrix.os != 'ubuntu'
4747
run: |
48-
echo "env_file=envs/${{ matrix.os }}-pinned.yaml" >> $GITHUB_ENV
48+
if [[ "${{ matrix.os }}" == "macos" ]]; then
49+
echo "env_file=envs/osx-arm64.lock.yaml" >> $GITHUB_ENV
50+
else
51+
echo "env_file=envs/win-64.lock.yaml" >> $GITHUB_ENV
52+
fi
4953
5054
- name: Use base env file if it was changed
5155
run: |
5256
git fetch origin master
5357
if git diff --name-only origin/master | grep '${{ env.BASE_ENV }}'; then
54-
echo "Base env ${{ env.BASE_ENV }} changed. Using it instead of pinned envs."
58+
echo "Base env ${{ env.BASE_ENV }} changed. Using it instead of locked envs."
5559
echo "env_file=${{ env.BASE_ENV }}" >> $GITHUB_ENV
5660
else
57-
echo "Base env ${{ env.BASE_ENV }} not changed. Using pinned envs."
61+
echo "Base env ${{ env.BASE_ENV }} not changed. Using locked envs."
5862
fi
5963
6064
- name: Setup cache keys
@@ -66,6 +70,7 @@ jobs:
6670
path: |
6771
data
6872
cutouts
73+
resources/ariadne_database.csv
6974
key: data-cutouts-${{ env.WEEK }}
7075

7176
- uses: conda-incubator/setup-miniconda@v3
@@ -87,19 +92,6 @@ jobs:
8792
conda env update -n pypsa-de -f ${{ env.env_file }}
8893
echo "Run conda list" && conda list
8994
90-
- name: Setup ixmp4 access
91-
run: |
92-
mkdir -p ~/.local/share/ixmp4/
93-
cat > ~/.local/share/ixmp4/credentials.toml << 'EOL'
94-
${{ secrets.IXMP4_ACCESS }}
95-
EOL
96-
shell: bash
97-
98-
# - name: Run pylint check on scripts
99-
# # check for undefined variables to reuse functions across scripts
100-
# run: |
101-
# pylint --disable=all --enable=E0601,E0606 --output-format=parseable scripts/add_* scripts/prepare_* scripts/solve_*
102-
10395
- name: Run snakemake test workflows
10496
run: |
10597
make test
@@ -118,104 +110,3 @@ jobs:
118110
.snakemake/log
119111
results
120112
retention-days: 3
121-
122-
run-tests-on-dev-deps:
123-
name: Inhouse
124-
runs-on: ubuntu-latest
125-
strategy:
126-
fail-fast: false
127-
matrix:
128-
inhouse:
129-
- pypsa
130-
- atlite
131-
- powerplantmatching
132-
- linopy
133-
134-
defaults:
135-
run:
136-
shell: bash -l {0}
137-
138-
steps:
139-
- uses: actions/checkout@v4
140-
141-
- name: Use base env file if it was changed
142-
run: |
143-
git fetch origin master
144-
if git diff --name-only origin/master | grep '${{ env.BASE_ENV }}'; then
145-
echo "Base env ${{ env.BASE_ENV }} changed. Using it instead of pinned envs."
146-
echo "env_file=${{ env.BASE_ENV }}" >> $GITHUB_ENV
147-
else
148-
echo "Base env ${{ env.BASE_ENV }} not changed. Using pinned envs."
149-
echo "env_file=envs/linux-pinned.yaml" >> $GITHUB_ENV
150-
fi
151-
152-
# Only run checks if package is not pinned
153-
- name: Check if inhouse package is pinned
154-
run: |
155-
grep_line=$(grep -- '- ${{ matrix.inhouse }}' ${{ env.BASE_ENV }})
156-
if [[ $grep_line == *"<"* || $grep_line == *"=="* ]]; then
157-
echo "pinned=true" >> $GITHUB_ENV
158-
else
159-
echo "pinned=false" >> $GITHUB_ENV
160-
fi
161-
162-
- name: Setup cache keys
163-
if: env.pinned == 'false'
164-
run: |
165-
echo "WEEK=$(date +'%Y%U')" >> $GITHUB_ENV # data and cutouts
166-
167-
- uses: actions/cache@v4
168-
if: env.pinned == 'false'
169-
with:
170-
path: |
171-
data
172-
cutouts
173-
key: data-cutouts-${{ env.WEEK }}
174-
175-
- uses: conda-incubator/setup-miniconda@v3
176-
if: env.pinned == 'false'
177-
with:
178-
activate-environment: pypsa-de
179-
180-
- name: Cache Conda env
181-
if: env.pinned == 'false'
182-
uses: actions/cache@v4
183-
with:
184-
path: ${{ env.CONDA }}/envs
185-
key: conda-${{ runner.os }}-${{ runner.arch }}-${{ matrix.inhouse }}-${{ hashFiles(format('{0}', env.env_file)) }}
186-
id: cache-env
187-
188-
- name: Update environment
189-
if: env.pinned == 'false' && steps.cache-env.outputs.cache-hit != 'true'
190-
run: |
191-
conda env update -n pypsa-de -f ${{ env.env_file }}
192-
echo "Run conda list" && conda list
193-
194-
- name: Setup ixmp4 access
195-
run: |
196-
mkdir -p ~/.local/share/ixmp4/
197-
cat > ~/.local/share/ixmp4/credentials.toml << 'EOL'
198-
${{ secrets.IXMP4_ACCESS }}
199-
EOL
200-
shell: bash
201-
202-
- name: Install inhouse packages from master
203-
if: env.pinned == 'false'
204-
run: |
205-
python -m pip install git+https://github.com/PyPSA/${{ matrix.inhouse }}.git@master
206-
207-
- name: Run snakemake test workflows
208-
if: env.pinned == 'false'
209-
run: |
210-
make test
211-
212-
- name: Upload artifacts
213-
if: env.pinned == 'false' && always()
214-
uses: actions/upload-artifact@v4
215-
with:
216-
name: results-inhouse-${{ matrix.inhouse }}
217-
path: |
218-
logs
219-
.snakemake/log
220-
results
221-
retention-days: 3
Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
name: Update pinned envs
2-
1+
name: Update locked envs
32
on:
43
push:
54
paths:
@@ -12,22 +11,13 @@ env:
1211
BASE_ENV: envs/environment.yaml
1312

1413
jobs:
15-
update-pinned-environment:
14+
update-locked-environment:
1615
if: ${{ github.ref == 'refs/heads/main' }}
1716
name: Update pinned envs
18-
runs-on: ${{ matrix.os }}-latest
19-
strategy:
20-
fail-fast: false
21-
matrix:
22-
os: [ubuntu, macos, windows]
23-
include:
24-
- os: ubuntu
25-
suffix: "linux"
26-
- os: macos
27-
suffix: "macos"
28-
- os: windows
29-
suffix: "windows"
30-
17+
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
shell: bash -l {0}
3121
steps:
3222
- uses: actions/checkout@v4
3323

@@ -39,53 +29,72 @@ jobs:
3929
channel-priority: strict
4030
environment-file: ${{ env.BASE_ENV }}
4131

42-
- name: Update pinned environment per OS
32+
- name: Install conda-lock
4333
run: |
44-
conda env export --name ${{ github.event.repository.name }} --no-builds -c conda-forge -c bioconda --override-channels > envs/${{ matrix.suffix }}-pinned.yaml
34+
conda install -c conda-forge conda-lock
4535
46-
# - name: Add SPDX header
47-
# if: ${{ matrix.suffix != 'windows' }}
48-
# run: |
49-
# SPDX_HEADER="# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>\n# SPDX-License-Identifier: CC0-1.0\n"
50-
# echo -e "$SPDX_HEADER" | cat - envs/${{ matrix.suffix }}-pinned.yaml > temp && mv temp envs/${{ matrix.suffix }}-pinned.yaml
36+
- name: Generate lockfiles for all platforms
37+
run: |
38+
conda-lock -f ${{ env.BASE_ENV }} \
39+
-p linux-64 -p osx-64 -p win-64 -p osx-arm64 \
40+
-k env --filename-template "envs/{platform}.lock"
5141
52-
# - name: Add SPDX header (windows)
53-
# if: ${{ matrix.suffix == 'windows' }}
54-
# run: |
55-
# $SPDX_HEADER = "# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>`r`n# SPDX-License-Identifier: CC0-1.0`r`n`r`n"
56-
# $CurrentContent = Get-Content "envs/${{ matrix.suffix }}-pinned.yaml" -Raw
57-
# $NewContent = $SPDX_HEADER + $CurrentContent
58-
# $NewContent | Set-Content "envs/${{ matrix.suffix }}-pinned.yaml"
42+
# Rename to .yaml extension
43+
for file in envs/*.lock.yml; do
44+
mv "$file" "${file%.yml}.yaml"
45+
done
46+
- name: Add SPDX headers to lock files
47+
run: |
48+
SPDX_HEADER="# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>\n# SPDX-License-Identifier: CC0-1.0\n"
49+
50+
# Add header to all generated lock files
51+
for file in envs/*.lock.yaml; do
52+
echo "Adding header to $file"
53+
echo -e "$SPDX_HEADER" | cat - "$file" > temp && mv temp "$file"
54+
done
5955
60-
- name: Cache environment files
56+
- name: Insert environment name in lock files
57+
run: |
58+
for file in envs/*.lock.yaml; do
59+
if [ -f "$file" ]; then
60+
echo "Processing $file"
61+
if ! grep -q "name: pypsa-de" "$file"; then
62+
# Insert name: pypsa-de before channels section
63+
sed -i '7a name: pypsa-de' "$file"
64+
else
65+
echo "name: pypsa-de already exists in $file"
66+
fi
67+
fi
68+
done
69+
70+
71+
- name: Upload artifacts
6172
uses: actions/upload-artifact@v4
6273
with:
63-
name: ${{ matrix.suffix }}-pinned
64-
path: envs/${{ matrix.suffix }}-pinned.yaml
74+
name: lockfiles
75+
path: envs/*.lock.yaml
6576

6677
create-pull-request:
67-
needs: update-pinned-environment
78+
needs: update-locked-environment
6879
runs-on: ubuntu-latest
6980
steps:
7081
- uses: actions/checkout@v4
7182
- name: Download all artifacts
7283
uses: actions/download-artifact@v4
73-
74-
- name: Prepare files for commit
75-
run: |
76-
mkdir -p envs
77-
mv linux-pinned/* envs/linux-pinned.yaml
78-
mv macos-pinned/* envs/macos-pinned.yaml
79-
mv windows-pinned/* envs/windows-pinned.yaml
84+
with:
85+
name: lockfiles
86+
path: envs/
8087

8188
- name: Create Pull Request
8289
uses: peter-evans/create-pull-request@v7
8390
with:
8491
token: ${{ secrets.GITHUB_TOKEN }}
85-
branch: update-pinned-environment
86-
title: "[github-actions.ci] Update pinned envs"
92+
branch: update-locked-environment
93+
title: "[github-actions.ci] Update locked envs"
8794
body: |
88-
Automatically generated PR to update pinned environment files for Windows, macOS, and Linux.
95+
Automatically generated PR to update locked environment files for Windows, macOS, and Linux.
96+
97+
These files were generated using conda-lock for improved dependency resolution and reproducibility.
8998
9099
**Note: Do not merge without manual test execution. Either update the branch to trigger tests, or use `workflow_dispatch` to run tests manually. Unlike standard PRs, tests will not run automatically.**
91-
commit-message: "Update pinned environment files for all platforms"
100+
commit-message: "Update locked environment files for all platforms"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ cutouts
8787
local
8888
# private dev folder
8989
dev/*
90+
91+
# ai coding tools
92+
CLAUDE.md
93+
.claude/
94+
.github/copilot-instructions.md

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
exclude: "^LICENSES"
2+
13
ci:
24
autoupdate_schedule: quarterly
35

4-
exclude: "^LICENSES"
5-
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
88
rev: v5.0.0
@@ -14,7 +14,7 @@ repos:
1414
# Run ruff to lint and format
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
1616
# Ruff version.
17-
rev: v0.11.8
17+
rev: v0.12.2
1818
hooks:
1919
# Run the linter.
2020
- id: ruff
@@ -27,7 +27,7 @@ repos:
2727
rev: v2.4.1
2828
hooks:
2929
- id: codespell
30-
args: ['--ignore-regex="(\b[A-Z]+\b)"', '--ignore-words-list=fom,appartment,bage,ore,setis,tabacco,berfore,vor,pris,GuD,Dezember,Juni,Juli,Produktion,WorstCase'] # Ignore capital case words, e.g. country codes
30+
args: ['--ignore-regex="(\b[A-Z]+\b)"', '--ignore-words-list=fom,appartment,bage,ore,setis,tabacco,berfore,vor,pris,bund,GuD,Dezember,Juni,Juli,Produktion,WorstCase'] # Ignore capital case words, e.g. country codes
3131
types_or: [python, rst, markdown]
3232
files: ^(scripts|doc)/
3333

@@ -40,10 +40,10 @@ repos:
4040

4141
# YAML formatting
4242
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
43-
rev: v2.14.0
43+
rev: v2.15.0
4444
hooks:
4545
- id: pretty-format-yaml
46-
exclude: pinned\.yaml$
46+
exclude: (pinned\.yaml|\.lock\.yaml)$
4747
args: [--autofix, --indent, "2", --preserve-quotes]
4848

4949
# Format Snakemake rule / workflow files

0 commit comments

Comments
 (0)