Skip to content

Commit 9101ab4

Browse files
chore: V2 migrate to uv (cloudevents#239)
* Migrate project to rye and ruff for v2 Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Just run ruff Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Add the core package stub Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Move cloudevents to v1 Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Add extra rye configs. update locks to be OS-aware Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Migrate from rye to uv Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Use python 3.12 by default for linting Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Do not mention rye in docs Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use stricter mypy rules. exclude v1 Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Run isort, flake8 Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * fix isort Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Run ruff with isort Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Move mypy config to pyproject Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Exclude samples as well Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Exclude samples as well Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> * Fix mypy pre-commit setup Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> --------- Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c6c7e8c commit 9101ab4

Some content is hidden

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

85 files changed

+946
-488
lines changed

.github/workflows/main.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on: [ push, pull_request ]
44

55
jobs:
66

77
lint:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
11-
- name: Setup Python
12-
uses: actions/setup-python@v5
11+
- name: Install uv
12+
uses: astral-sh/setup-uv@v2
1313
with:
14-
python-version: '3.11'
15-
cache: 'pip'
16-
cache-dependency-path: 'requirements/*.txt'
17-
- name: Install dev dependencies
18-
run: python -m pip install -r requirements/dev.txt
19-
- name: Run linting
20-
run: python -m tox -e lint
14+
enable-cache: true
15+
cache-dependency-glob: "uv.lock"
16+
- name: Set up Python
17+
run: uv python install 3.12
18+
- name: Install the project
19+
run: uv sync --all-extras --dev
20+
- name: Lint
21+
run: uv run ruff check --select I
2122

2223
test:
2324
strategy:
2425
matrix:
25-
python: ['3.8', '3.9', '3.10', '3.11']
26-
os: [ubuntu-latest, windows-latest, macos-latest]
26+
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
27+
os: [ ubuntu-latest, windows-latest, macos-latest ]
2728
runs-on: ${{ matrix.os }}
2829
steps:
2930
- uses: actions/checkout@v4
30-
- name: Setup Python
31-
uses: actions/setup-python@v5
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v2
3233
with:
33-
python-version: ${{ matrix.python }}
34-
cache: 'pip'
35-
cache-dependency-path: 'requirements/*.txt'
36-
- name: Install dev dependencies
37-
run: python -m pip install -r requirements/dev.txt
34+
enable-cache: true
35+
cache-dependency-glob: "uv.lock"
36+
- name: Set up Python ${{ matrix.python-version }}
37+
run: uv python install ${{ matrix.python-version }}
38+
- name: Install the project
39+
run: uv sync --all-extras --dev
3840
- name: Run tests
39-
run: python -m tox -e py # Run tox using the version of Python in `PATH`
41+
run: uv run pytest tests

.pre-commit-config.yaml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: check-toml
8-
- repo: https://github.com/pycqa/isort
9-
rev: 5.13.2
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.6.8
1010
hooks:
11-
- id: isort
12-
args: [ "--profile", "black", "--filter-files" ]
13-
- repo: https://github.com/psf/black
14-
rev: 24.4.2
15-
hooks:
16-
- id: black
17-
language_version: python3.11
11+
# Run the linter.
12+
- id: ruff
13+
# Run the formatter.
14+
- id: ruff-format
1815
- repo: https://github.com/pre-commit/mirrors-mypy
19-
rev: v1.10.0
16+
rev: v1.11.2
2017
hooks:
2118
- id: mypy
22-
files: ^(cloudevents/)
23-
exclude: ^(cloudevents/tests/)
19+
files: ^(src/cloudevents/|tests/)
20+
exclude: ^(src/cloudevents/v1/)
2421
types: [ python ]
25-
args: [ ]
26-
additional_dependencies:
27-
- "pydantic~=2.7"
22+
args: [
23+
"--config-file=pyproject.toml",
24+
]

README.md

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Python SDK for [CloudEvents](https://github.com/cloudevents/spec)
1+
# Python SDK v2 for [CloudEvents](https://github.com/cloudevents/spec)
22

33
[![PyPI version](https://badge.fury.io/py/cloudevents.svg)](https://badge.fury.io/py/cloudevents)
44

@@ -10,12 +10,11 @@ will) break with every update.
1010
This SDK current supports the following versions of CloudEvents:
1111

1212
- v1.0
13-
- v0.3
1413

1514
## Python SDK
1615

17-
Package **cloudevents** provides primitives to work with CloudEvents specification:
18-
https://github.com/cloudevents/spec.
16+
Package [**cloudevents**](src/cloudevents) provides primitives to work with
17+
[CloudEvents specification](https://github.com/cloudevents/spec).
1918

2019
### Installing
2120

@@ -33,15 +32,15 @@ Below we will provide samples on how to send cloudevents using the popular
3332
### Binary HTTP CloudEvent
3433

3534
```python
36-
from cloudevents.http import CloudEvent
37-
from cloudevents.conversion import to_binary
35+
from cloudevents_v1.http import CloudEvent
36+
from cloudevents_v1.conversion import to_binary
3837
import requests
3938

4039
# Create a CloudEvent
4140
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
4241
attributes = {
43-
"type": "com.example.sampletype1",
44-
"source": "https://example.com/event-producer",
42+
"type": "com.example.sampletype1",
43+
"source": "https://example.com/event-producer",
4544
}
4645
data = {"message": "Hello World!"}
4746
event = CloudEvent(attributes, data)
@@ -56,15 +55,15 @@ requests.post("<some-url>", data=body, headers=headers)
5655
### Structured HTTP CloudEvent
5756

5857
```python
59-
from cloudevents.conversion import to_structured
60-
from cloudevents.http import CloudEvent
58+
from cloudevents_v1.conversion import to_structured
59+
from cloudevents_v1.http import CloudEvent
6160
import requests
6261

6362
# Create a CloudEvent
6463
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
6564
attributes = {
66-
"type": "com.example.sampletype2",
67-
"source": "https://example.com/event-producer",
65+
"type": "com.example.sampletype2",
66+
"source": "https://example.com/event-producer",
6867
}
6968
data = {"message": "Hello World!"}
7069
event = CloudEvent(attributes, data)
@@ -87,28 +86,28 @@ The code below shows how to consume a cloudevent using the popular python web fr
8786
```python
8887
from flask import Flask, request
8988

90-
from cloudevents.http import from_http
89+
from cloudevents_v1.http import from_http
9190

9291
app = Flask(__name__)
9392

9493

9594
# create an endpoint at http://localhost:/3000/
9695
@app.route("/", methods=["POST"])
9796
def home():
98-
# create a CloudEvent
99-
event = from_http(request.headers, request.get_data())
97+
# create a CloudEvent
98+
event = from_http(request.headers, request.get_data())
10099

101-
# you can access cloudevent fields as seen below
102-
print(
103-
f"Found {event['id']} from {event['source']} with type "
104-
f"{event['type']} and specversion {event['specversion']}"
105-
)
100+
# you can access cloudevent fields as seen below
101+
print(
102+
f"Found {event['id']} from {event['source']} with type "
103+
f"{event['type']} and specversion {event['specversion']}"
104+
)
106105

107-
return "", 204
106+
return "", 204
108107

109108

110109
if __name__ == "__main__":
111-
app.run(port=3000)
110+
app.run(port=3000)
112111
```
113112

114113
You can find a complete example of turning a CloudEvent into a HTTP request
@@ -162,18 +161,13 @@ with one of the project's SDKs, please send an email to
162161

163162
## Maintenance
164163

165-
We use [black][black] and [isort][isort] for autoformatting. We set up a [tox][tox]
166-
environment to reformat the codebase.
167-
168-
e.g.
169-
170-
```bash
171-
pip install tox
172-
tox -e reformat
173-
```
164+
We use [uv][uv] for dependency and package management, [ruff][ruff] and [isort][isort]
165+
for autoformatting and [pre-commit][pre-commit] to automate those with commit
166+
hooks.
174167

175168
For information on releasing version bumps see [RELEASING.md](RELEASING.md)
176169

177-
[black]: https://black.readthedocs.io/
170+
[uv]: https://docs.astral.sh/uv/
171+
[ruff]: https://docs.astral.sh/ruff
178172
[isort]: https://pycqa.github.io/isort/
179-
[tox]: https://tox.wiki/
173+
[pre-commit]: https://pre-commit.com

RELEASING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ This repository is configured to automatically publish the corresponding [PyPI
44
package](https://pypi.org/project/cloudevents/) and GitHub Tag via GitHub Actions.
55

66
To release a new CloudEvents SDK, contributors should bump `__version__` in
7-
[cloudevents](cloudevents/__init__.py) to reflect the new release version. On merge, the action
7+
[cloudevents](cloudevents_v1/__init__.py) to reflect the new release version. On merge, the action
88
will automatically build and release to PyPI using
99
[this PyPI GitHub Action](https://github.com/pypa/gh-action-pypi-publish). This
1010
action gets called on all pushes to main (such as a version branch being merged
1111
into main), but only releases a new version when the version number has changed. Note,
1212
this action assumes pushes to main are version updates. Consequently,
1313
[pypi-release.yml](.github/workflows/pypi-release.yml) will fail if you attempt to
1414
push to main without updating `__version__` in
15-
[cloudevents](cloudevents/__init__.py) so don't forget to do so.
15+
[cloudevents](cloudevents_v1/__init__.py) so don't forget to do so.
1616

1717
After a version update is merged, the script [pypi_packaging.py](pypi_packaging.py)
1818
will create a GitHub tag for the new cloudevents version using `__version__`.

mypy.ini

Lines changed: 0 additions & 16 deletions
This file was deleted.

pypi_packaging.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)