crossplane-function-sdk-python 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,4 +15,4 @@
15
15
  """The version of function-sdk-python."""
16
16
 
17
17
  # This is set at build time, using "hatch version"
18
- __version__ = "0.4.0"
18
+ __version__ = "0.5.0"
@@ -17,12 +17,39 @@
17
17
  import dataclasses
18
18
  import datetime
19
19
 
20
+ import pydantic
20
21
  from google.protobuf import struct_pb2 as structpb
21
22
 
23
+ import crossplane.function.proto.v1.run_function_pb2 as fnv1
24
+
22
25
  # TODO(negz): Do we really need dict_to_struct and struct_to_dict? They don't do
23
26
  # much, but are perhaps useful for discoverability/"documentation" purposes.
24
27
 
25
28
 
29
+ def update(r: fnv1.Resource, source: dict | structpb.Struct | pydantic.BaseModel):
30
+ """Update a composite or composed resource.
31
+
32
+ Use update to add or update the supplied resource. If the resource doesn't
33
+ exist, it'll be added. If the resource does exist, it'll be updated. The
34
+ update method semantics are the same as a dictionary's update method. Fields
35
+ that don't exist will be added. Fields that exist will be overwritten.
36
+
37
+ The source can be a dictionary, a protobuf Struct, or a Pydantic model.
38
+ """
39
+ match source:
40
+ case pydantic.BaseModel():
41
+ r.resource.update(source.model_dump(exclude_defaults=True, warnings=False))
42
+ case structpb.Struct():
43
+ # TODO(negz): Use struct_to_dict and update to match other semantics?
44
+ r.resource.MergeFrom(source)
45
+ case dict():
46
+ r.resource.update(source)
47
+ case _:
48
+ t = type(source)
49
+ msg = f"Unsupported type: {t}"
50
+ raise TypeError(msg)
51
+
52
+
26
53
  def dict_to_struct(d: dict) -> structpb.Struct:
27
54
  """Create a Struct well-known type from the supplied dict.
28
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: crossplane-function-sdk-python
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: The Python SDK for Crossplane composition functions
5
5
  Project-URL: Documentation, https://github.com/crossplane/function-sdk-python#readme
6
6
  Project-URL: Issues, https://github.com/crossplane/function-sdk-python/issues
@@ -15,6 +15,7 @@ Requires-Python: >=3.11
15
15
  Requires-Dist: grpcio-reflection==1.*
16
16
  Requires-Dist: grpcio==1.*
17
17
  Requires-Dist: protobuf==5.27.2
18
+ Requires-Dist: pydantic==2.*
18
19
  Requires-Dist: structlog==24.*
19
20
  Description-Content-Type: text/markdown
20
21
 
@@ -54,11 +55,11 @@ Some useful commands:
54
55
  # Generate gRPC stubs.
55
56
  hatch run generate:protoc
56
57
 
57
- # Lint the code.
58
- hatch run lint:check
58
+ # Format and lint the code.
59
+ hatch fmt
59
60
 
60
61
  # Run unit tests.
61
- hatch run test:unit
62
+ hatch test
62
63
 
63
64
  # Build an sdist and wheel.
64
65
  hatch build
@@ -1,6 +1,6 @@
1
- crossplane/function/__version__.py,sha256=UmYGftOClDeeEqm_1NAJL-F44l3lUDF3p6gNQUY3O6E,704
1
+ crossplane/function/__version__.py,sha256=EpOLy6RQc6F3rnJZbtuQ57CcZ6WoDo9E8EbbFaW0a8Y,704
2
2
  crossplane/function/logging.py,sha256=Zawqq36FBzjkVg4bJ3VGK12-so7N8yAMoSPrhdwpBSA,2503
3
- crossplane/function/resource.py,sha256=wsPYkPKjO63Gz2HNyHoE2fe-TGXmFg0MjAborujymIA,3861
3
+ crossplane/function/resource.py,sha256=Nv_ARRqhMheoGAErKPsty5unyn3P2TOvHM-UVBM6RPY,4946
4
4
  crossplane/function/response.py,sha256=5TDz2vXcvH2cMuDojN1YFrr0Vsyvz1XCzNEBwxruFf4,2354
5
5
  crossplane/function/runtime.py,sha256=DoCLFildkwBgB-y-qlHcoSXStDRcJ426_V81C3QvVOE,4864
6
6
  crossplane/function/proto/v1/run_function.proto,sha256=83RIkEQWuMfXC5HPaPpJqXXDxYMR3VlG4xhmtutle5k,12032
@@ -11,7 +11,7 @@ crossplane/function/proto/v1beta1/run_function.proto,sha256=xep0DvulCjo8LUf-2fOb
11
11
  crossplane/function/proto/v1beta1/run_function_pb2.py,sha256=LmKTg848G5Ud8GI2AIK2jjLj19nnjthRsQwECZgE4ls,10907
12
12
  crossplane/function/proto/v1beta1/run_function_pb2.pyi,sha256=IYcl0F9Chx_jN6AP9FI0yZCqidpbiFCK0ANU6AlKfXY,10624
13
13
  crossplane/function/proto/v1beta1/run_function_pb2_grpc.py,sha256=Abx0c4U82vIsWyeIKwS1vfEshP74N6gjB-hx0DM1lFk,4082
14
- crossplane_function_sdk_python-0.4.0.dist-info/METADATA,sha256=VS0q5hBjxru_-tiQyLIMbPI6fKCYPl_Mx34YsBWhsnI,3192
15
- crossplane_function_sdk_python-0.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
16
- crossplane_function_sdk_python-0.4.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- crossplane_function_sdk_python-0.4.0.dist-info/RECORD,,
14
+ crossplane_function_sdk_python-0.5.0.dist-info/METADATA,sha256=te7cF_WoCSW0aLS5Vu5dBrwy62qaHD03psv3yXw3hME,3212
15
+ crossplane_function_sdk_python-0.5.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
16
+ crossplane_function_sdk_python-0.5.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ crossplane_function_sdk_python-0.5.0.dist-info/RECORD,,