Skip to content

Commit a3464ce

Browse files
erkistelmsdata
andauthored
Align with Go SDK (#11)
* DRAFT: Align with Go SDK Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix subject content mapping. Add schema validation to tests. Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Clean up old files (to be reintroduced later) Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Add readme Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix Github workflow syntax Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Add Makefile Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix dev install: Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix humps dependency Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix humps dependency Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Add submodule init to Github workflow Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> * Fix codecov.yml EOF Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> --------- Signed-off-by: Erik Sternerson <[email protected]> Signed-off-by: erkist <[email protected]> Co-authored-by: elmsdata <[email protected]>
1 parent d715d23 commit a3464ce

File tree

105 files changed

+3451
-4219
lines changed

Some content is hidden

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

105 files changed

+3451
-4219
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10+
with:
11+
submodules: recursive
1012
- name: Setup Python
1113
uses: actions/setup-python@v4
1214
with:
@@ -25,12 +27,14 @@ jobs:
2527
python: ['3.7', '3.8', '3.9', '3.x']
2628
steps:
2729
- uses: actions/checkout@v3
30+
with:
31+
submodules: recursive
2832
- name: Setup Python ${{ matrix.python }}
2933
uses: actions/setup-python@v4
3034
with:
3135
python-version: ${{ matrix.python }}
3236
- name: Install dependencies
33-
run: make package-install
37+
run: make dev-install
3438
- name: Run tests
3539
run: make test
3640
- name: Run tests and collect coverage

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/tests/spec"]
2+
path = src/tests/spec
3+
url = https://github.com/cdevents/spec

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include header.mk
22

3-
PACKAGES = core
3+
PACKAGES = src
44
export ABS_ROOT_PATH=$(shell pwd)
55

66
.PHONY: packages $(PACKAGES)
@@ -13,6 +13,7 @@ $(PACKAGES):
1313
# the sets of directories to do various things in
1414
INITPACKAGES = $(PACKAGES:%=init-%)
1515
INSTALLPACKAGES = $(PACKAGES:%=package-install-%)
16+
DEVINSTALLPACKAGES = $(PACKAGES:%=dev-install-%)
1617
CLEANPACKAGES = $(PACKAGES:%=clean-%)
1718
TESTPACKAGES = $(PACKAGES:%=test-%)
1819
LINTPACKAGES = $(PACKAGES:%=lint-%)
@@ -26,6 +27,10 @@ package-install: $(INSTALLPACKAGES) ## Installs all packages without dev depende
2627
$(INSTALLPACKAGES):
2728
$(MAKE) -C $(@:package-install-%=%) package-install
2829

30+
dev-install: $(DEVINSTALLPACKAGES) ## Installs all packages without dev dependencies
31+
$(DEVINSTALLPACKAGES):
32+
$(MAKE) -C $(@:dev-install-%=%) dev-install
33+
2934
test: $(TESTPACKAGES) ## Run tests on all packages
3035
$(TESTPACKAGES):
3136
$(MAKE) -C $(@:test-%=%) test
@@ -62,6 +67,7 @@ docker-shell: ## Opens a bash
6267
.PHONY: packages $(PACKAGES)
6368
.PHONY: packages $(INITPACKAGES)
6469
.PHONY: packages $(INSTALLPACKAGES)
70+
.PHONY: packages $(DEVINSTALLPACKAGES)
6571
.PHONY: packages $(TESTPACKAGES)
6672
.PHONY: packages $(CLEANPACKAGES)
6773
.PHONY: packages $(BUMPVERSIONPACKAGES)

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,68 @@
22

33
Python SDK for CDEvents
44

5-
update ...
5+
The SDK can be used to create CDEvents in CloudEvents form, for use with the
6+
[CloudEvents Python SDK](https://github.com/cloudevents/sdk-python).
7+
8+
## Disclaimer 🚧
9+
10+
This SDK is work in work in progress, it will be maintained in sync with the
11+
specification and it now covers all events from the specification.
12+
13+
## Get started
14+
15+
Clone the repo and install the Python SDK as a package:
16+
17+
```golang
18+
cd src && pip install .
19+
```
20+
21+
And import the module in your code
22+
23+
```golang
24+
import cdevents
25+
```
26+
27+
## Create your first CDEvent
28+
29+
To create a CDEvent, for instance a [*pipelineRun queued*](https://cdevents.dev/docs/core/#pipelinerun-queued) one:
30+
31+
```python
32+
import cdevents
33+
34+
event = cdevents.new_pipelinerun_queued_event(
35+
context_id="my-context-id",
36+
context_source="my/first/cdevent/program",
37+
context_timestamp=datetime.datetime.now(),
38+
subject_id="myPipelineRun1",
39+
custom_data={"hello_message": "hi!"},
40+
custom_data_content_type="application/json",
41+
pipeline_name="myPipeline",
42+
url="https://example.com/myPipeline",
43+
)
44+
```
45+
46+
## Send your first CDEvent as CloudEvent
47+
48+
To send a CDEvent as CloudEvent:
49+
50+
```python
51+
import cdevents
52+
53+
# Create a CloudEvent from the CDEvent
54+
cloudevent = cdevents.to_cloudevent(event)
55+
56+
# Creates the HTTP request representation of the CloudEvent in structured content mode
57+
headers, body = to_structured(event)
58+
59+
# POST
60+
requests.post("<some-url>", data=body, headers=headers)
61+
62+
```
63+
64+
See the [CloudEvents](https://github.com/cloudevents/sdk-python) docs as well.
65+
66+
## References
67+
68+
- [CDEvents](https://cdevents.dev)
69+
- [CDFoundation SIG Events Vocabulary Draft](https://github.com/cdfoundation/sig-events/tree/main/vocabulary-draft)

core/Makefile

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

core/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/cdevents/core/__init__.py

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

core/cdevents/core/artifact.py

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

core/cdevents/core/branch.py

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

core/cdevents/core/build.py

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

0 commit comments

Comments
 (0)