Skip to content

Commit

Permalink
Merge pull request #549 from camunda-community-hub/merge-zeebe-grpc
Browse files Browse the repository at this point in the history
feat: merge zeebe-grpc to pyzeebe
  • Loading branch information
dimastbk authored Dec 30, 2024
2 parents 6572346 + 79bd5ce commit 43dd741
Show file tree
Hide file tree
Showing 17 changed files with 4,832 additions and 369 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ repos:
entry: black
language: python
files: \.py$
exclude: ^(.*pb2.*|.*\.pyi)$
- repo: local
hooks:
- id: isort
name: isort
entry: isort
language: python
files: \.py$
exclude: ^(.*pb2.*|.*\.pyi)$
- repo: local
hooks:
- id: mypy
Expand All @@ -32,10 +34,11 @@ repos:
hooks:
- id: pyupgrade
args: [--py39-plus]
exclude: ^(.*pb2.*|.*\.pyi)$
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args:
- --fix
exclude: ^(tests/.*|examples/.*|docs/.*)$
exclude: ^(tests/.*|examples/.*|docs/.*|.*pb2.*|.*\.pyi)$
3 changes: 1 addition & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ Creating a client
Dependencies
============

* python 3.7+
* zeebe-grpc
* python 3.9+
* grpcio
* protobuf
* oauthlib
Expand Down
668 changes: 400 additions & 268 deletions poetry.lock

Large diffs are not rendered by default.

33 changes: 26 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ packages = [

[tool.poetry.dependencies]
python = "^3.9"
anyio = "^4.6.0"
grpcio = "^1.66"
protobuf = "^5.28"
oauthlib = "^3.1.0"
requests-oauthlib = ">=1.3.0,<3.0.0"
zeebe-grpc = "^8.4.0"
typing-extensions = "^4.11.0"
anyio = "^4.6.0"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.4,<9.0"
Expand All @@ -41,40 +42,55 @@ coveralls = "^3.3.1"
responses = ">=0.23.2,<0.26.0"
sphinx-rtd-theme = ">=3.0.0,<3.1.0"
sphinx = ">=6,<8"
grpcio-tools = "^1.66"
mypy-protobuf = "^3.6"

[tool.poetry.group.stubs.dependencies]
types-oauthlib = "^3.1.0"
types-requests-oauthlib = ">=1.3.0,<3.0.0"
types-protobuf = "^5.29.1.20241207"

[tool.mypy]
python_version = "3.9"
packages = ["pyzeebe"]
strict = true

[[tool.mypy.overrides]]
module = [
"grpc",
"zeebe_grpc.gateway_pb2",
"zeebe_grpc.gateway_pb2_grpc",
]
module = "grpc"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pyzeebe.proto.*"
disable_error_code = ["import-untyped", "unused-ignore"] # "type-arg"

[tool.pylint.master]
max-line-length = 120
disable = ["C0114", "C0115", "C0116"]

[tool.black]
line-length = 120
extend-exclude = '''
(
.*_pb2.py # exclude autogenerated Protocol Buffer files anywhere in the project
| .*_pb2_grpc.py
)
'''

[tool.isort]
profile = "black"
extend_skip_glob = ["*_pb2.py", "*_pb2_grpc.py", "*.pyi"]

[tool.pytest.ini_options]
asyncio_mode = "auto"
markers = [
"e2e: end to end tests",
]

[tool.coverage.run]
omit = [
"pyzeebe/proto/*"
]

[tool.ruff]
target-version = "py39"

Expand All @@ -94,6 +110,9 @@ ignore = [
"E501", # line too long, handled by black
]

[tool.ruff.lint.per-file-ignores]
"update_proto.py" = ["T201"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
117 changes: 65 additions & 52 deletions pyzeebe/grpc_internals/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,40 @@

@dataclass(frozen=True)
class CreateProcessInstanceResponse:
#: the key of the process definition which was used to create the process instance
process_definition_key: int
#: the BPMN process ID of the process definition which was used to create the process
#: instance
"""the key of the process definition which was used to create the process instance"""
bpmn_process_id: str
#: the version of the process definition which was used to create the process instance
"""the BPMN process ID of the process definition which was used to create the process
instance
"""
version: int
#: the unique identifier of the created process instance; to be used wherever a request
#: needs a process instance key (e.g. CancelProcessInstanceRequest)
"""the version of the process definition which was used to create the process instance"""
process_instance_key: int
#: the tenant ID of the created process instance
"""the unique identifier of the created process instance; to be used wherever a request
needs a process instance key (e.g. CancelProcessInstanceRequest)
"""
tenant_id: str | None
"""the tenant ID of the created process instance"""


@dataclass(frozen=True)
class CreateProcessInstanceWithResultResponse:
#: the key of the process definition which was used to create the process instance
process_definition_key: int
#: the BPMN process ID of the process definition which was used to create the process
#: instance
"""the key of the process definition which was used to create the process instance"""
bpmn_process_id: str
#: the version of the process definition which was used to create the process instance
"""the BPMN process ID of the process definition which was used to create the process
instance
"""
version: int
#: the unique identifier of the created process instance; to be used wherever a request
#: needs a process instance key (e.g. CancelProcessInstanceRequest)
"""the version of the process definition which was used to create the process instance"""
process_instance_key: int
#: consisting of all visible variables to the root scope
"""the unique identifier of the created process instance; to be used wherever a request
needs a process instance key (e.g. CancelProcessInstanceRequest)
"""
variables: Variables
#: the tenant ID of the process definition
"""consisting of all visible variables to the root scope"""
tenant_id: str | None
"""the tenant ID of the created process instance"""


@dataclass(frozen=True)
Expand All @@ -48,85 +52,94 @@ class CancelProcessInstanceResponse:
class DeployResourceResponse:
@dataclass(frozen=True)
class ProcessMetadata:
#: the bpmn process ID, as parsed during deployment; together with the version forms a
#: unique identifier for a specific process definition
bpmn_process_id: str
#: the assigned process version
"""the bpmn process ID, as parsed during deployment; together with the version forms a
unique identifier for a specific process definition
"""
version: int
#: the assigned key, which acts as a unique identifier for this process
"""the assigned process version"""
process_definition_key: int
#: the resource name from which this process was parsed
"""the assigned key, which acts as a unique identifier for this process"""
resource_name: str
#: the tenant ID of the deployed process
"""the resource name from which this process was parsed"""
tenant_id: str | None
"""the tenant ID of the deployed process"""

@dataclass(frozen=True)
class DecisionMetadata:
#: the dmn decision ID, as parsed during deployment; together with the
#: versions forms a unique identifier for a specific decision
dmn_decision_id: str
#: the dmn name of the decision, as parsed during deployment
"""the dmn decision ID, as parsed during deployment; together with the
versions forms a unique identifier for a specific decision
"""
dmn_decision_name: str
#: the assigned decision version
"""the dmn name of the decision, as parsed during deployment"""
version: int
#: the assigned decision key, which acts as a unique identifier for this
#: decision
"""the assigned decision version"""
decision_key: int
#: the dmn ID of the decision requirements graph that this decision is part
#: of, as parsed during deployment
"""the assigned decision key, which acts as a unique identifier for this
decision
"""
dmn_decision_requirements_id: str
#: the assigned key of the decision requirements graph that this decision is
#: part of
"""the dmn ID of the decision requirements graph that this decision is part
of, as parsed during deployment
"""
decision_requirements_key: int
#: the tenant ID of the deployed decision
"""the assigned key of the decision requirements graph that this decision is
part of
"""
tenant_id: str | None
"""the tenant ID of the deployed decision"""

@dataclass(frozen=True)
class DecisionRequirementsMetadata:
#: the dmn decision requirements ID, as parsed during deployment; together
#: with the versions forms a unique identifier for a specific decision
dmn_decision_requirements_id: str
#: the dmn name of the decision requirements, as parsed during deployment
"""the dmn decision requirements ID, as parsed during deployment; together
with the versions forms a unique identifier for a specific decision
"""
dmn_decision_requirements_name: str
#: the assigned decision requirements version
"""the dmn name of the decision requirements, as parsed during deployment"""
version: int
#: the assigned decision requirements key, which acts as a unique identifier
#: for this decision requirements
"""the assigned decision requirements version"""
decision_requirements_key: int
#: the resource name from which this decision
#: requirements was parsed
"""the assigned decision requirements key, which acts as a unique identifier
for this decision requirements
"""
resource_name: str
#: the tenant ID of the deployed decision requirements
"""the resource name from which this decision
requirements was parsed
"""
tenant_id: str | None
"""the tenant ID of the deployed decision requirements"""

@dataclass(frozen=True)
class FormMetadata:
#: the form ID, as parsed during deployment; together with the
#: versions forms a unique identifier for a specific form
form_id: str
#: the assigned form version
"""the form ID, as parsed during deployment; together with the
versions forms a unique identifier for a specific form
"""
version: int
#: the assigned key, which acts as a unique identifier for this form
"""the assigned form version"""
form_key: int
#: the resource name
"""the assigned key, which acts as a unique identifier for this form"""
resource_name: str
#: the tenant ID of the deployed form
"""the resource name"""
tenant_id: str | None
"""the tenant ID of the deployed form"""

#: the unique key identifying the deployment
key: int
#: a list of deployed resources, e.g. processes
"""the unique key identifying the deployment"""
deployments: list[ProcessMetadata | DecisionMetadata | DecisionRequirementsMetadata | FormMetadata]
#: the tenant ID of the deployed resources
"""a list of deployed resources, e.g. processes"""
tenant_id: str | None
"""the tenant ID of the deployed resources"""


@dataclass(frozen=True)
class PublishMessageResponse:
#: the unique ID of the message that was published
key: int
#: the tenant ID of the message
"""the unique ID of the message that was published"""
tenant_id: str | None
"""the tenant ID of the message"""


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion pyzeebe/grpc_internals/zeebe_adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import NoReturn

import grpc
from zeebe_grpc.gateway_pb2_grpc import GatewayStub

from pyzeebe.errors import (
UnknownGrpcStatusCodeError,
Expand All @@ -13,6 +12,7 @@
)
from pyzeebe.errors.pyzeebe_errors import PyZeebeError
from pyzeebe.grpc_internals.grpc_utils import is_error_status
from pyzeebe.proto.gateway_pb2_grpc import GatewayStub

logger = logging.getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions pyzeebe/grpc_internals/zeebe_job_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from collections.abc import AsyncGenerator, Iterable

import grpc
from zeebe_grpc.gateway_pb2 import (
ActivatedJob,
ActivateJobsRequest,
CompleteJobRequest,
FailJobRequest,
ThrowErrorRequest,
)

from pyzeebe.errors import (
ActivateJobsRequestInvalidError,
Expand All @@ -22,6 +15,13 @@
from pyzeebe.grpc_internals.grpc_utils import is_error_status
from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase
from pyzeebe.job.job import Job
from pyzeebe.proto.gateway_pb2 import (
ActivatedJob,
ActivateJobsRequest,
CompleteJobRequest,
FailJobRequest,
ThrowErrorRequest,
)
from pyzeebe.types import Variables

from .types import CompleteJobResponse, FailJobResponse, ThrowErrorResponse
Expand Down
6 changes: 3 additions & 3 deletions pyzeebe/grpc_internals/zeebe_message_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import json

import grpc
from zeebe_grpc.gateway_pb2 import PublishMessageRequest

from pyzeebe.errors import MessageAlreadyExistsError
from pyzeebe.grpc_internals.grpc_utils import is_error_status
from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase
from pyzeebe.proto.gateway_pb2 import PublishMessageRequest
from pyzeebe.types import Variables

from .types import PublishMessageResponse
Expand All @@ -28,10 +28,10 @@ async def publish_message(
PublishMessageRequest(
name=name,
correlationKey=correlation_key,
messageId=message_id,
messageId=message_id, # type: ignore[arg-type]
timeToLive=time_to_live_in_milliseconds,
variables=json.dumps(variables),
tenantId=tenant_id,
tenantId=tenant_id, # type: ignore[arg-type]
)
)
except grpc.aio.AioRpcError as grpc_error:
Expand Down
Loading

0 comments on commit 43dd741

Please sign in to comment.