Skip to content

Commit d3fd230

Browse files
authored
Merge pull request #348 from PowerGridModel/feature/enable-uv
Enable UV in build and CI
2 parents 0b6a743 + 5c036c9 commit d3fd230

27 files changed

+3090
-183
lines changed

.github/workflows/build-test-release.yml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
65
name: Build and Test
76

87
on:
@@ -28,20 +27,16 @@ concurrency:
2827
cancel-in-progress: true
2928

3029
jobs:
31-
3230
build-python:
3331
runs-on: ubuntu-latest
3432
outputs:
3533
version: ${{ steps.version.outputs.version }}
3634
steps:
37-
3835
- name: Checkout source code
3936
uses: actions/checkout@v6
4037

41-
- name: Setup Python 3.13
42-
uses: actions/setup-python@v6
43-
with:
44-
python-version: "3.13"
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v7
4540

4641
- name: Set PyPI version
4742
uses: PowerGridModel/pgm-version-bump@main
@@ -51,8 +46,7 @@ jobs:
5146
- name: Build
5247
run: |
5348
cat PYPI_VERSION
54-
pip install build
55-
python -m build --outdir wheelhouse .
49+
uv build --sdist --no-create-gitignore --out-dir wheelhouse .
5650
5751
- name: Save version
5852
id: version
@@ -74,12 +68,11 @@ jobs:
7468
runs-on: ${{ matrix.os }}
7569

7670
steps:
77-
7871
- name: Checkout source code
7972
uses: actions/checkout@v6
8073

81-
- name: Setup Python ${{ matrix.python }}
82-
uses: actions/setup-python@v6
74+
- name: Install uv
75+
uses: astral-sh/setup-uv@v7
8376
with:
8477
python-version: ${{ matrix.python }}
8578

@@ -89,11 +82,14 @@ jobs:
8982
name: power-grid-model-io
9083
path: wheelhouse/
9184

85+
- name: Create environment
86+
run: uv venv
87+
9288
- name: Install built wheel file
93-
run: pip install power-grid-model-io[dev]==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
89+
run: uv pip install power-grid-model-io==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
9490

9591
- name: Unit test and coverage
96-
run: pytest --verbose
92+
run: uv run --only-group test --no-editable pytest --verbose
9793

9894
validation-tests:
9995
needs: build-python
@@ -105,12 +101,11 @@ jobs:
105101
runs-on: ${{ matrix.os }}
106102

107103
steps:
108-
109104
- name: Checkout source code
110105
uses: actions/checkout@v6
111106

112-
- name: Setup Python ${{ matrix.python }}
113-
uses: actions/setup-python@v6
107+
- name: Install uv
108+
uses: astral-sh/setup-uv@v7
114109
with:
115110
python-version: ${{ matrix.python }}
116111

@@ -120,11 +115,14 @@ jobs:
120115
name: power-grid-model-io
121116
path: wheelhouse/
122117

118+
- name: Create environment
119+
run: uv venv
120+
123121
- name: Install built wheel file
124-
run: pip install power-grid-model-io[dev]==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
122+
run: uv pip install power-grid-model-io==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
125123

126124
- name: Validation tests
127-
run: pytest tests/validation --no-cov --verbose
125+
run: uv run --only-group test --no-editable pytest tests/validation --no-cov --verbose
128126

129127
github-release:
130128
needs:
@@ -135,10 +133,8 @@ jobs:
135133
contents: write
136134
runs-on: ubuntu-latest
137135
steps:
138-
- name: Setup Python 3.13
139-
uses: actions/setup-python@v6
140-
with:
141-
python-version: "3.13"
136+
- name: Install uv
137+
uses: astral-sh/setup-uv@v7
142138

143139
- name: Load built wheel file
144140
uses: actions/download-artifact@v7

.github/workflows/check-code-quality.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,27 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@v6
2323

24-
- name: Set up Python
25-
uses: actions/setup-python@v6
26-
with:
27-
python-version: 3.11
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v7
2826

29-
- name: Upgrade pip
30-
run: pip install --upgrade pip
27+
- name: Install most linters from uv
28+
run: |
29+
uv sync --group lint
30+
31+
- name: Run mypy
32+
run: |
33+
uv run mypy .
3134
32-
- name: Install and run mypy
35+
- name: Run ruff
3336
run: |
34-
pip install mypy
35-
mypy src
37+
uv run ruff check .
38+
uv run ruff format .
3639
37-
- name: Install and run ruff
40+
- name: Install and run markdownlint
3841
run: |
39-
pip install ruff .
40-
ruff check .
41-
ruff format .
42+
npm install -g markdownlint-cli@0.47.0
43+
echo "Running markdownlint"
44+
markdownlint --fix .
4245
4346
- name: If needed raise error
4447
run: |

.github/workflows/check-pr-labels.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
65
name: Check PR Labels
76

87
on:
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Refresh lock and linter Dependencies
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
create-pr:
11+
type: boolean
12+
description: "Whether to create a pull request with the changes"
13+
required: false
14+
default: false
15+
workflow_dispatch:
16+
inputs:
17+
create-pr:
18+
type: boolean
19+
description: "Whether to create a pull request with the changes"
20+
required: false
21+
default: false
22+
schedule:
23+
- cron: "0 2 * * 0" # Every Sunday at 2:00 UTC
24+
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}-linter-dependencies
28+
cancel-in-progress: true
29+
30+
31+
jobs:
32+
refresh-lock-and-linter-dependencies:
33+
name: Refresh lock and linter Dependencies
34+
runs-on: ubuntu-latest
35+
permissions:
36+
contents: write
37+
pull-requests: write
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v6
42+
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v7
45+
46+
- name: upgrade uv lock
47+
run: uv lock --upgrade
48+
49+
- name: Install linters from uv
50+
run: |
51+
uv sync --only-group lint
52+
53+
- name: retrieve versions
54+
id: versions
55+
run: |
56+
grab_installed_version() {
57+
local pkg="$1"
58+
local version
59+
version=$(uv pip freeze | grep -i "^$pkg==" | head -n1 | cut -d= -f3)
60+
echo "${pkg}=$version" >> "$GITHUB_OUTPUT"
61+
}
62+
grab_installed_version "ruff"
63+
grab_installed_version "clang-format"
64+
grab_installed_version "mypy"
65+
grab_installed_version "gersemi"
66+
67+
- name: Update .pre-commit-config.yaml
68+
uses: cuchi/jinja2-action@v1.3.0
69+
with:
70+
template: .pre-commit-config.yaml.jinja
71+
output_file: .pre-commit-config.yaml
72+
variables: |
73+
ruff=${{ steps.versions.outputs.ruff }}
74+
clang_format=${{ steps.versions.outputs.clang-format }}
75+
mypy=${{ steps.versions.outputs.mypy }}
76+
gersemi=${{ steps.versions.outputs.gersemi }}
77+
78+
- name: show changed files
79+
run: |
80+
git status
81+
git diff .pre-commit-config.yaml
82+
83+
- name: try to install pre-commit
84+
run: |
85+
source .venv/bin/activate
86+
pre-commit install
87+
pre-commit install-hooks
88+
pre-commit uninstall
89+
90+
- name: generate GitHub App token
91+
uses: actions/create-github-app-token@v2
92+
id: generate-token
93+
with:
94+
app-id: ${{ secrets.CI_BOT_APP_ID }}
95+
private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }}
96+
97+
- name: create pull request
98+
if: ${{ inputs.create-pr || github.event_name == 'schedule' }}
99+
uses: peter-evans/create-pull-request@v8
100+
with:
101+
commit-message: "Refresh lock and linter dependencies"
102+
branch: "dependencies/refresh-lock-and-linter"
103+
title: "Refresh lock and linter dependencies"
104+
body: "This PR refreshes the lock file and updates linter dependencies to their latest versions."
105+
labels: "dependencies"
106+
signoff: true
107+
sign-commits: true
108+
delete-branch: true
109+
base: ${{ github.head_ref }}
110+
token: ${{ steps.generate-token.outputs.token }}

.github/workflows/sonar.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,13 @@ jobs:
3030
with:
3131
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
3232

33-
- name: Set up Python
34-
uses: actions/setup-python@v6
35-
with:
36-
python-version: "3.13"
37-
38-
- name: Install in develop mode
39-
run: |
40-
pip install -e .[dev]
33+
- name: Install uv
34+
uses: astral-sh/setup-uv@v7
4135

4236
- name: Test and Coverage
4337
run: |
44-
pytest
38+
uv sync --no-default-groups --group test
39+
uv run pytest
4540
4641
# Fix relative paths in coverage file
4742
# Known bug: https://community.sonarsource.com/t/sonar-on-github-actions-with-python-coverage-source-issue/36057
@@ -52,4 +47,4 @@ jobs:
5247
uses: SonarSource/sonarqube-scan-action@v7
5348
env:
5449
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.markdownlint.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md001.md
6+
MD001: false
7+
8+
# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md013.md
9+
line-length:
10+
line_length: 120
11+
code_blocks: false
12+
tables: false
13+
stern: true
14+
15+
# MD024/no-duplicate-heading : Multiple headings with the same content : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md024.md
16+
MD024: false

.pre-commit-config.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55
repos:
6-
- repo: https://github.com/fsfe/reuse-tool
7-
rev: v5.0.2
6+
- repo: https://github.com/fsfe/reuse-tool # outside pypi
7+
rev: v6.2.0
88
hooks:
99
- id: reuse
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
1111
# Ruff version.
12-
rev: v0.11.12
12+
rev: v0.14.9
1313
hooks:
1414
# Run the linter.
1515
- id: ruff-check
@@ -19,16 +19,23 @@ repos:
1919
- id: ruff-format
2020
name: ruff-format
2121
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.16.0
22+
rev: v1.19.0
2323
hooks:
2424
- id: mypy
25-
additional_dependencies: [numpy, pandas]
25+
additional_dependencies:
26+
- numpy
27+
- types-pyyaml
28+
- types-requests
2629
- repo: local
2730
hooks:
2831
- id: pytest
2932
name: pytest
30-
entry: pytest
33+
entry: uv run pytest
3134
language: system
3235
pass_filenames: false
3336
always_run: true
34-
args: [ "--cov-fail-under=98" ]
37+
- repo: https://github.com/igorshubovych/markdownlint-cli # outside pypi
38+
rev: v0.47.0
39+
hooks:
40+
- id: markdownlint
41+
args: ["--fix"]

0 commit comments

Comments
 (0)