Skip to content

Commit f944a50

Browse files
authored
Upload Packages to PyPI (#16)
2 parents c73b725 + 8ab19cc commit f944a50

11 files changed

+301
-132
lines changed

.github/ISSUE_TEMPLATE/bug.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ name: Report something is not working properly 🐛
55
description:
66
Use this if there is something that is not working properly. If you are not
77
sure or you need help making something work, please ask a question instead.
8-
labels: [ priority:❓, type:bug ]
8+
labels:
9+
- "priority:❓"
10+
- "type:bug"
911
body:
1012
- type: markdown
1113
attributes:

.github/ISSUE_TEMPLATE/feature.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
name: Request a feature or enhancement ✨
55
description: Use this if something is missing or could be done better or more easily.
6-
labels: [ part:❓, priority:❓, type:enhancement ]
6+
labels:
7+
- "part:❓"
8+
- "priority:❓"
9+
- "type:enhancement"
710
body:
811
- type: markdown
912
attributes:

.github/RELEASE_NOTES.template.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Release Notes
2+
3+
## Summary
4+
5+
<!-- Here goes a general summary of what this release is about -->
6+
7+
## Upgrading
8+
9+
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10+
11+
## New Features
12+
13+
<!-- Here goes the main new features and examples or instructions on how to use them -->
14+
15+
## Bug Fixes
16+
17+
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

.github/workflows/ci.yaml

+100-53
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,132 @@
11
name: frequenz-sdk-python
22

3-
on:
4-
push:
5-
branches: [ v0.x.x ]
6-
7-
pull_request:
8-
9-
env:
10-
REGISTRY: ghcr.io
3+
on: [pull_request, push, workflow_dispatch]
114

125
jobs:
136
test:
147
strategy:
158
fail-fast: false
169
matrix:
17-
python: [ "3.8", "3.9", "3.10" ]
18-
os: [ ubuntu-20.04 ]
19-
10+
os:
11+
- ubuntu-20.04
12+
python:
13+
- "3.8"
14+
- "3.9"
15+
- "3.10"
2016
runs-on: ${{ matrix.os }}
2117

2218
steps:
2319
- name: Fetch sources
24-
uses: actions/checkout@v2
25-
with:
26-
token: ${{ secrets.CI_ACCESS_TOKEN || github.token }}
27-
submodules: true
20+
uses: actions/checkout@v3
2821

2922
- name: Set up Python
30-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
3124
with:
3225
python-version: ${{ matrix.python }}
3326

34-
- uses: actions/cache@v2
27+
- uses: actions/cache@v3
3528
with:
3629
path: ~/.cache/pip
37-
key: ${{ runner.os }}-pip-${{ hashFiles('**/minimum-requirements-ci.txt') }}
30+
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('minimum-requirements-ci.txt', 'pyproject.toml') }}
3831
restore-keys: |
39-
${{ runner.os }}-pip-
32+
${{ runner.os }}-${{ matrix.python-version }}-pip-
4033
4134
- name: Install required Python packages
4235
run: |
4336
python -m pip install --upgrade pip
44-
python -m pip install nox wheel
37+
python -m pip install nox
4538
4639
- name: run nox
4740
run: nox -e ci_checks_max pytest_min
4841
timeout-minutes: 10
4942

50-
build-wheels:
43+
build-dist:
5144
runs-on: ubuntu-20.04
52-
needs: test
45+
steps:
46+
- name: Fetch sources
47+
uses: actions/checkout@v3
48+
49+
- name: Set up Python
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: "3.10"
53+
54+
- name: Install build dependencies
55+
run: |
56+
python -m pip install -U pip
57+
python -m pip install -U build
58+
59+
- name: Build the source and binary distribution
60+
run: python -m build
5361

62+
- name: Upload dist files
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: frequenz-sdk-python-dist
66+
path: dist/
67+
if-no-files-found: error
68+
69+
create-github-release:
70+
needs: ["test", "build-dist"]
71+
# Create a release only on tags creation
72+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
73+
permissions:
74+
# We need write permissions on contents to create GitHub releases and on
75+
# discussions to create the release announcement in the discussion forums
76+
contents: write
77+
discussions: write
78+
runs-on: ubuntu-20.04
5479
steps:
55-
- name: Fetch sources
56-
uses: actions/checkout@v2
57-
with:
58-
token: ${{ secrets.CI_ACCESS_TOKEN || github.token }}
59-
submodules: true
60-
61-
- name: Set up Python
62-
uses: actions/setup-python@v2
63-
with:
64-
python-version: 3.8
65-
66-
- uses: actions/cache@v2
67-
with:
68-
path: ~/.cache/pip
69-
key: ${{ runner.os }}-pip-${{ hashFiles('**/minimum-requirements-ci.txt') }}
70-
restore-keys: |
71-
${{ runner.os }}-pip-
72-
73-
- name: Install required Python packages
74-
run: |
75-
python -m pip install --upgrade pip
76-
python -m pip install wheel
77-
78-
- name: make wheel
79-
run: python -m pip wheel --no-deps -w dist .
80-
81-
- name: upload wheels
82-
uses: actions/upload-artifact@v2
83-
with:
84-
name: frequenz-sdk-python-wheels
85-
path: dist/*.whl
80+
- name: Download dist files
81+
uses: actions/download-artifact@v3
82+
with:
83+
name: frequenz-sdk-python-dist
84+
path: dist
85+
86+
- name: Download RELEASE_NOTES.md
87+
run: |
88+
set -ux
89+
gh api \
90+
-X GET \
91+
-f ref=$REF \
92+
-H "Accept: application/vnd.github.raw" \
93+
"/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \
94+
> RELEASE_NOTES.md
95+
env:
96+
REF: ${{ github.ref }}
97+
REPOSITORY: ${{ github.repository }}
98+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
100+
- name: Create GitHub release
101+
run: |
102+
set -ux
103+
extra_opts=
104+
if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi
105+
gh release create \
106+
-R "$REPOSITORY" \
107+
--discussion-category announcements \
108+
--notes-file RELEASE_NOTES.md \
109+
--generate-notes \
110+
$extra_opts \
111+
$REF_NAME \
112+
dist/*
113+
env:
114+
REF_NAME: ${{ github.ref_name }}
115+
REPOSITORY: ${{ github.repository }}
116+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
118+
publish-to-pypi:
119+
needs: ["create-github-release"]
120+
runs-on: ubuntu-20.04
121+
steps:
122+
- name: Download dist files
123+
uses: actions/download-artifact@v3
124+
with:
125+
name: frequenz-sdk-python-dist
126+
path: dist
127+
128+
- name: Publish the Python distribution to PyPI
129+
uses: pypa/gh-action-pypi-publish@release/v1
130+
with:
131+
password: ${{ secrets.PYPI_API_TOKEN }}
132+
skip_existing: true

CONTRIBUTING.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Contributing to `frequenz-sdk`
2+
3+
## Build
4+
5+
You can use `build` to simply build the source and binary distribution:
6+
7+
```sh
8+
python -m pip install build
9+
python -m build
10+
```
11+
12+
## Local development
13+
14+
You can use editable installs to develop the project locally (it will install
15+
all the dependencies too):
16+
17+
```sh
18+
python -m pip install -e .
19+
```
20+
21+
You can also use `nox` to run the tests and other checks:
22+
23+
```sh
24+
python -m pip install nox
25+
nox
26+
```
27+
28+
You can also use `nox -R` to reuse the current testing environment to speed up
29+
test at the expense of a higher chance to end up with a dirty test environment.
30+
31+
### Running tests individually
32+
33+
For a better development test cycle you can install the runtime and test
34+
dependencies and run `pytest` manually.
35+
36+
```sh
37+
python -m pip install .
38+
python -m pip install pytest pytest-asyncio
39+
40+
# And for example
41+
pytest tests/test_sdk.py
42+
```
43+
44+
## Releasing
45+
46+
These are the steps to create a new release:
47+
48+
1. Get the latest head you want to create a release from.
49+
50+
2. Update the `RELEASE_NOTES.md` file if it is not complete, up to date, and
51+
clean from template comments (`<!-- ... ->`) and empty sections. Submit
52+
a pull request if an update is needed, wait until it is merged, and update
53+
the latest head you want to create a release from to get the new merged pull
54+
request.
55+
56+
3. Create a new signed tag using the release notes and
57+
a [semver](https://semver.org/) compatible version number with a `v` prefix,
58+
for example:
59+
60+
```sh
61+
git tag -s -F RELEASE_NOTES.md v0.0.1
62+
```
63+
64+
4. Push the new tag.
65+
66+
5. A GitHub action will test the tag and if all goes well it will create
67+
a [GitHub
68+
Release](https://github.com/frequenz-floss/frequenz-sdk-python/releases),
69+
create a new
70+
[announcement](https://github.com/frequenz-floss/frequenz-sdk-python/discussions/categories/announcements)
71+
about the release, and upload a new package to
72+
[PyPI](https://pypi.org/project/frequenz-sdk/) automatically.
73+
74+
6. Once this is done, reset the `RELEASE_NOTES.md` with the template:
75+
76+
```sh
77+
cp .github/RELEASE_NOTES.template.md RELEASE_NOTES.md
78+
```
79+
80+
Commit the new release notes and create a PR (this step should be automated
81+
eventually too).
82+
83+
7. Celebrate!

MANIFEST.in

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exclude .darglint
2+
exclude .gitignore
3+
exclude CODEOWNERS
4+
exclude minimum-requirements-ci.txt
5+
exclude noxfile.py
6+
recursive-exclude .github *
7+
recursive-exclude benchmarks *
8+
recursive-exclude examples *
9+
recursive-exclude tests *

README.md

+5-36
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,13 @@
22

33
A development kit to interact with the Frequenz development platform.
44

5-
## Testing locally
6-
7-
### Prerequisites
8-
9-
#### Python version
5+
## Supported Python versions
106

117
* For x86_64 Python 3.8 - 3.10 are supported (tested).
128
* For arm64 only Python 3.8 is supported (due to some dependencies that only support 3.8).
139

14-
#### Development setup
15-
16-
You need to install the following development dependencies to be able to get
17-
and build all dependencies:
18-
19-
```sh
20-
python -m pip install grpcio-tools mypy-protobuf nox wheel
21-
```
22-
23-
### Running the whole test suite
24-
25-
Run the following command to run tests:
26-
27-
```sh
28-
nox
29-
```
30-
31-
You can also use `nox -R` to reuse the current testing environment to speed up
32-
test at the expense of a higher chance to end up with a dirty test environment.
33-
34-
### Running tests individually
35-
36-
For a better development test cycle you can install the runtime and test
37-
dependencies and run `pytest` manually.
38-
39-
```sh
40-
python -m pip install .
41-
python -m pip install pytest pytest-asyncio
10+
## Contributing
4211

43-
# And for example
44-
pytest tests/test_sdk.py
45-
```
12+
If you want to know how to build this project and contribute to it, please
13+
check out the [Contributing
14+
Guide](https://github.com/frequenz-floss/frequenz-sdk-python/CONTRIBUTING.md).

RELEASE_NOTES.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `frequenz-sdk` Release Notes
2+
3+
## Summary
4+
5+
This is the first public open source release based on the internal SDK version v0.10.0. There are no breaking changes in this release, only changes to the project structure, metadata, and automation. Packages are also now uploaded to PyPI as [`frequenz-sdk`](https://pypi.org/project/frequenz-sdk/), so this project now can be installed normally via `pip`:
6+
7+
```sh
8+
python -m pip install frequenz-sdk
9+
```
10+
11+
The GitHub issues were also improved, adding templates for [reporting issues](https://github.com/frequenz-floss/frequenz-sdk-python/issues/new?assignees=&labels=priority%3A%E2%9D%93%2C+type%3Abug&template=bug.yml) and [requesting features](https://github.com/frequenz-floss/frequenz-sdk-python/issues/new?assignees=&labels=part%3A%E2%9D%93%2C+priority%3A%E2%9D%93%2C+type%3Aenhancement&template=feature.yml). Users are also pointed to the [Discussion forums](https://github.com/frequenz-floss/frequenz-sdk-python/issues/new/choose) when trying to open an issue if they have questions instead. Also many labels are assigned automatically on issue and pull request creation.
12+
13+
## Upgrading
14+
15+
Even if there are no breaking changes, you might see this error in your local
16+
environment when upgrading:
17+
18+
ERROR: Project file:///home/luca/devel/frequenz-sdk-python has
19+
a 'pyproject.toml' and its build backend is missing the 'build_editable'
20+
hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be
21+
installed in editable mode. Consider using a build backend that supports PEP
22+
660.
23+
24+
If so, you should probably update the dependencies in you virtual environment
25+
(for example `python -m pip install -U -e .`)

0 commit comments

Comments
 (0)