Skip to content

Commit 79fb177

Browse files
authored
Migrate to repo-config (#488)
- Migrate to use `repo-config` - Fix pylint false positive for `pydantic.parse_raw_as` - Add more cross-linking to generated docs - Drop dependency on the `toml` package - Fix missing `import` in a code example - Fix some typing issues in `src/conftest.py` - Add explicit dependency to `types-protobuf`
2 parents 9671a6e + 4e9c324 commit 79fb177

21 files changed

+198
-480
lines changed

Diff for: .cookiecutter-replay.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"cookiecutter": {
3+
"type": "lib",
4+
"name": "sdk",
5+
"description": "A development kit to interact with the Frequenz development platform",
6+
"title": "Frequenz Python SDK",
7+
"keywords": "microgrid,actor,ml,machine-learning,ai",
8+
"github_org": "frequenz-floss",
9+
"license": "MIT",
10+
"author_name": "Frequenz Energy-as-a-Service GmbH",
11+
"author_email": "[email protected]",
12+
"python_package": "frequenz.sdk",
13+
"pypi_package_name": "frequenz-sdk",
14+
"github_repo_name": "frequenz-sdk-python",
15+
"default_codeowners": "@frequenz-floss/python-sdk-team",
16+
"_extensions": [
17+
"jinja2_time.TimeExtension",
18+
"local_extensions.default_codeowners",
19+
"local_extensions.github_repo_name",
20+
"local_extensions.keywords",
21+
"local_extensions.pypi_package_name",
22+
"local_extensions.python_package",
23+
"local_extensions.src_path",
24+
"local_extensions.title"
25+
],
26+
"_template": "gh:frequenz-floss/frequenz-repo-config-python"
27+
}
28+
}

Diff for: .github/RELEASE_NOTES.template.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Release Notes
1+
# Frequenz Python SDK Release Notes
22

33
## Summary
44

55
<!-- Here goes a general summary of what this release is about -->
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
1010

1111
## New Features
1212

Diff for: .github/labeler.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- "src/frequenz/sdk/_data_ingestion/**"
2121
- "src/frequenz/sdk/timeseries/**"
2222

23-
"part:docs":
23+
"part:docs":
2424
- "**/*.md"
2525
- "docs/**"
2626
- "examples/**"
@@ -40,12 +40,9 @@
4040
- "**/*.toml"
4141
- "**/*.yaml"
4242
- "**/*.yml"
43-
- "*requirements*.txt"
4443
- ".git*"
4544
- ".git*/**"
45+
- "docs/*.py"
4646
- CODEOWNERS
4747
- MANIFEST.in
48-
- docs/mkdocstrings_autoapi.py
4948
- noxfile.py
50-
- setup.cfg
51-
- setup.py

Diff for: .github/workflows/ci.yaml

+32-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
name: frequenz-sdk-python
1+
name: CI
22

33
on:
44
merge_group:
55
pull_request:
66
push:
7+
# We need to explicitly include tags because otherwise when adding
8+
# `branches-ignore` it will only trigger on branches.
79
tags:
810
- '*'
911
branches-ignore:
@@ -14,10 +16,15 @@ on:
1416
workflow_dispatch:
1517

1618
env:
19+
# Please make sure this version is included in the `matrix`, as the
20+
# `matrix` section can't use `env`, so it must be entered manually
1721
DEFAULT_PYTHON_VERSION: '3.11'
22+
# It would be nice to be able to also define a DEFAULT_UBUNTU_VERSION
23+
# but sadly `env` can't be used either in `runs-on`.
1824

1925
jobs:
20-
test:
26+
nox:
27+
name: Test with nox
2128
strategy:
2229
fail-fast: false
2330
matrix:
@@ -37,23 +44,19 @@ jobs:
3744
python-version: ${{ matrix.python }}
3845
cache: 'pip'
3946

40-
- uses: actions/cache@v3
41-
with:
42-
path: ~/.cache/pip
43-
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('minimum-requirements-ci.txt', 'pyproject.toml') }}
44-
restore-keys: |
45-
${{ runner.os }}-${{ matrix.python-version }}-pip-
46-
4747
- name: Install required Python packages
4848
run: |
4949
python -m pip install --upgrade pip
50-
python -m pip install nox toml
50+
python -m pip install -e .[dev-noxfile]
5151
52-
- name: run nox
52+
- name: Run nox
53+
# To speed things up a bit we use the speciall ci_checks_max session
54+
# that uses the same venv to run multiple linting sessions
5355
run: nox -e ci_checks_max pytest_min
5456
timeout-minutes: 10
5557

56-
build-dist:
58+
build:
59+
name: Build distribution packages
5760
runs-on: ubuntu-20.04
5861
steps:
5962
- name: Fetch sources
@@ -62,25 +65,26 @@ jobs:
6265
- name: Set up Python
6366
uses: actions/setup-python@v4
6467
with:
65-
python-version: '3.11'
68+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
6669
cache: 'pip'
6770

68-
- name: Install build dependencies
71+
- name: Install required Python packages
6972
run: |
7073
python -m pip install -U pip
7174
python -m pip install -U build
7275
7376
- name: Build the source and binary distribution
7477
run: python -m build
7578

76-
- name: Upload dist files
79+
- name: Upload distribution files
7780
uses: actions/upload-artifact@v3
7881
with:
79-
name: frequenz-sdk-python-dist
82+
name: dist-packages
8083
path: dist/
8184
if-no-files-found: error
8285

83-
test-generate-docs:
86+
test-docs:
87+
name: Test documentation website generation
8488
if: github.event_name != 'push'
8589
runs-on: ubuntu-20.04
8690
steps:
@@ -99,7 +103,7 @@ jobs:
99103
- name: Install build dependencies
100104
run: |
101105
python -m pip install -U pip
102-
python -m pip install .[docs-gen]
106+
python -m pip install .[dev-mkdocs]
103107
104108
- name: Generate the documentation
105109
env:
@@ -111,12 +115,13 @@ jobs:
111115
- name: Upload site
112116
uses: actions/upload-artifact@v3
113117
with:
114-
name: frequenz-channels-python-site
118+
name: docs-site
115119
path: site/
116120
if-no-files-found: error
117121

118122
publish-docs:
119-
needs: ["test", "build-dist"]
123+
name: Publish documentation website to GitHub pages
124+
needs: ["nox", "build"]
120125
if: github.event_name == 'push'
121126
runs-on: ubuntu-20.04
122127
permissions:
@@ -178,7 +183,7 @@ jobs:
178183
if: steps.mike-metadata.outputs.version
179184
run: |
180185
python -m pip install -U pip
181-
python -m pip install .[docs-gen]
186+
python -m pip install .[dev-mkdocs]
182187
183188
- name: Fetch the gh-pages branch
184189
if: steps.mike-metadata.outputs.version
@@ -193,6 +198,7 @@ jobs:
193198
mike deploy --push --update-aliases "$VERSION" $ALIASES
194199
195200
create-github-release:
201+
name: Create GitHub release
196202
needs: ["publish-docs"]
197203
# Create a release only on tags creation
198204
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
@@ -203,10 +209,10 @@ jobs:
203209
discussions: write
204210
runs-on: ubuntu-20.04
205211
steps:
206-
- name: Download dist files
212+
- name: Download distribution files
207213
uses: actions/download-artifact@v3
208214
with:
209-
name: frequenz-sdk-python-dist
215+
name: dist-packages
210216
path: dist
211217

212218
- name: Download RELEASE_NOTES.md
@@ -230,7 +236,6 @@ jobs:
230236
if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi
231237
gh release create \
232238
-R "$REPOSITORY" \
233-
--discussion-category announcements \
234239
--notes-file RELEASE_NOTES.md \
235240
--generate-notes \
236241
$extra_opts \
@@ -242,17 +247,18 @@ jobs:
242247
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
243248

244249
publish-to-pypi:
250+
name: Publish packages to PyPI
245251
needs: ["create-github-release"]
246252
runs-on: ubuntu-20.04
247253
permissions:
248254
# For trusted publishing. See:
249255
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
250256
id-token: write
251257
steps:
252-
- name: Download dist files
258+
- name: Download distribution files
253259
uses: actions/download-artifact@v3
254260
with:
255-
name: frequenz-sdk-python-dist
261+
name: dist-packages
256262
path: dist
257263

258264
- name: Publish the Python distribution to PyPI

Diff for: .github/workflows/labeler.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
name: Pull Request Labeler
22

3-
# XXX: !!! SECURITY WARNING !!!
4-
# pull_request_target has write access to the repo, and can read secrets. We
5-
# need to audit any external actions executed in this workflow and make sure no
6-
# checked out code is run (not even installing dependencies, as installing
7-
# dependencies usually can execute pre/post-install scripts). We should also
8-
# only use hashes to pick the action to execute (instead of tags or branches).
9-
# For more details read:
10-
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
113
on: [pull_request_target]
124

135
jobs:
@@ -18,7 +10,14 @@ jobs:
1810
runs-on: ubuntu-latest
1911
steps:
2012
- name: Labeler
21-
# Only use hashes, see the security comment above
13+
# XXX: !!! SECURITY WARNING !!!
14+
# pull_request_target has write access to the repo, and can read secrets. We
15+
# need to audit any external actions executed in this workflow and make sure no
16+
# checked out code is run (not even installing dependencies, as installing
17+
# dependencies usually can execute pre/post-install scripts). We should also
18+
# only use hashes to pick the action to execute (instead of tags or branches).
19+
# For more details read:
20+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
2221
uses: actions/labeler@0967ca812e7fdc8f5f71402a1b486d5bd061fe20 # 4.2.0
2322
with:
2423
repo-token: "${{ secrets.GITHUB_TOKEN }}"

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ venv/
114114
ENV/
115115
env.bak/
116116
venv.bak/
117+
# direnv https://github.com/direnv/direnv
118+
.envrc
119+
.direnv/
117120

118121
# Spyder project settings
119122
.spyderproject

Diff for: CONTRIBUTING.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to `frequenz-sdk`
1+
# Contributing to Frequenz Python SDK
22

33
## Build
44

@@ -28,7 +28,7 @@ If you don't want to install all the dependencies, you can also use `nox` to
2828
run the tests and other checks creating its own virtual environments:
2929

3030
```sh
31-
python -m pip install nox toml
31+
python -m pip install .[dev-noxfile]
3232
nox
3333
```
3434

@@ -41,23 +41,23 @@ For a better development test cycle you can install the runtime and test
4141
dependencies and run `pytest` manually.
4242

4343
```sh
44-
python -m pip install .[pytest] # included in .[dev] too
44+
python -m pip install .[dev-pytest] # included in .[dev] too
4545

4646
# And for example
47-
pytest tests/test_sdk.py
47+
pytest tests/test_*.py
4848
```
4949

5050
Or you can use `nox`:
5151

5252
```sh
53-
nox -R -s pytest -- test/test_sdk.py
53+
nox -R -s pytest -- test/test_*.py
5454
```
5555

5656
The same appliest to `pylint` or `mypy` for example:
5757

5858
```sh
59-
nox -R -s pylint -- test/test_sdk.py
60-
nox -R -s mypy -- test/test_sdk.py
59+
nox -R -s pylint -- test/test_*.py
60+
nox -R -s mypy -- test/test_*.py
6161
```
6262

6363
### Building the documentation
@@ -66,7 +66,7 @@ To build the documentation, first install the dependencies (if you didn't
6666
install all `dev` dependencies):
6767

6868
```sh
69-
python -m pip install -e .[docs-gen]
69+
python -m pip install -e .[dev-mkdocs]
7070
```
7171

7272
Then you can build the documentation (it will be written in the `site/`
@@ -122,28 +122,27 @@ These are the steps to create a new release:
122122
1. Get the latest head you want to create a release from.
123123

124124
2. Update the `RELEASE_NOTES.md` file if it is not complete, up to date, and
125-
clean from template comments (`<!-- ... ->`) and empty sections. Submit
126-
a pull request if an update is needed, wait until it is merged, and update
127-
the latest head you want to create a release from to get the new merged pull
125+
remove template comments (`<!-- ... ->`) and empty sections. Submit a pull
126+
request if an update is needed, wait until it is merged, and update the
127+
latest head you want to create a release from to get the new merged pull
128128
request.
129129

130130
3. Create a new signed tag using the release notes and
131131
a [semver](https://semver.org/) compatible version number with a `v` prefix,
132132
for example:
133133

134134
```sh
135-
git tag -s -F RELEASE_NOTES.md v0.0.1
135+
git tag -s --cleanup=whitespace -F RELEASE_NOTES.md v0.0.1
136136
```
137137

138138
4. Push the new tag.
139139

140140
5. A GitHub action will test the tag and if all goes well it will create
141141
a [GitHub
142142
Release](https://github.com/frequenz-floss/frequenz-sdk-python/releases),
143-
create a new
144-
[announcement](https://github.com/frequenz-floss/frequenz-sdk-python/discussions/categories/announcements)
145-
about the release, and upload a new package to
146-
[PyPI](https://pypi.org/project/frequenz-sdk/) automatically.
143+
and upload a new package to
144+
[PyPI](https://pypi.org/project/frequenz-sdk/)
145+
automatically.
147146

148147
6. Once this is done, reset the `RELEASE_NOTES.md` with the template:
149148

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Frequenz Energy-as-a-Service GmbH
3+
Copyright © 2022 Frequenz Energy-as-a-Service GmbH
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[![PyPI Package](https://img.shields.io/pypi/v/frequenz-sdk)](https://pypi.org/project/frequenz-sdk/)
55
[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-sdk-python/)
66

7+
## Introduction
8+
79
A development kit to interact with the Frequenz development platform.
810

911
## Quick Start

Diff for: RELEASE_NOTES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Release Notes
1+
# Frequenz Python SDK Release Notes
22

33
## Summary
44

Diff for: docs/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* [Home](index.md)
22
* [API Reference](reference/)
3-
* [Development](CONTRIBUTING.md)
3+
* [Contributing](CONTRIBUTING.md)

0 commit comments

Comments
 (0)