Skip to content

Event consumer API simplification into develop #2566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions taipy/core/common/_check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _check_dependency_is_installed(module_name: str, package_name: str) -> None:
class EnterpriseEditionUtils:
_TAIPY_ENTERPRISE_MODULE = "taipy.enterprise"
_TAIPY_ENTERPRISE_CORE_MODULE = _TAIPY_ENTERPRISE_MODULE + ".core"
_TAIPY_ENTERPRISE_EVENT_PACKAGE = _TAIPY_ENTERPRISE_MODULE + ".event"

@classmethod
def _using_enterprise(cls) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions taipy/core/data/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def storage_type(cls) -> str:
@_self_reload(DataNode._MANAGER_NAME)
def encoder(self) -> json.JSONEncoder:
"""The JSON encoder that is used to write into the JSON file."""
return self._encoder
return self._encoder # type: ignore[return-value]

@encoder.setter
def encoder(self, encoder: json.JSONEncoder) -> None:
Expand All @@ -123,7 +123,7 @@ def encoder(self, encoder: json.JSONEncoder) -> None:
@_self_reload(DataNode._MANAGER_NAME)
def decoder(self) -> json.JSONDecoder:
"""The JSON decoder that is used to read from the JSON file."""
return self._decoder
return self._decoder # type: ignore[return-value]

@decoder.setter
def decoder(self, decoder: json.JSONDecoder) -> None:
Expand Down
1 change: 0 additions & 1 deletion taipy/core/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from ._registration import _Registration
from ._topic import _Topic
from .core_event_consumer import CoreEventConsumerBase
from .event import Event, EventEntityType, EventOperation, _make_event
from .notifier import Notifier, _publish_event
from .registration_id import RegistrationId
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .event import Event


class CoreEventConsumerBase(threading.Thread):
class _CoreEventConsumerBase(threading.Thread):
"""Abstract base class for implementing a Core event consumer.

This class provides a framework for consuming events from a queue in a separate thread.
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/scenario/_scenario_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def _set_primary(cls, scenario: Scenario) -> None:

@classmethod
def _tag(cls, scenario: Scenario, tag: str) -> None:
tags = scenario.properties.get(cls._AUTHORIZED_TAGS_KEY, set())
tags = scenario.properties.get(cls._AUTHORIZED_TAGS_KEY, set()) # type: ignore[var-annotated]
if len(tags) > 0 and tag not in tags:
raise UnauthorizedTagError(f"Tag `{tag}` not authorized by scenario configuration `{scenario.config_id}`")
scenario._add_tag(tag)
Expand Down
13 changes: 13 additions & 0 deletions taipy/event/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from ..core.notification.event import Event, EventEntityType, EventOperation
from .event_consumer import EventConsumer
25 changes: 25 additions & 0 deletions taipy/event/_event_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
from dataclasses import dataclass, field
from typing import Callable, List, Optional

from taipy.core.notification import Event


@dataclass
class _Callback:
callback: Callable
args: Optional[List] = field(default_factory=list)
broadcast: Optional[bool] = False
filter: Optional[Callable[[Event], bool]] = None

def __hash__(self):
return hash(self.callback)
29 changes: 29 additions & 0 deletions taipy/event/_event_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021-2025 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
from abc import abstractmethod

from taipy.core.notification import Event


class _AbstractEventProcessor:
"""Abstract base class for implementing an event processor."""

@classmethod
@abstractmethod
def process_event(cls, event_consumer, event: Event):
raise NotImplementedError("Subclasses must implement this method.")

class _EventProcessor(_AbstractEventProcessor):

@classmethod
def process_event(cls, event_consumer, event: Event):
event_consumer._process_event(event)

Loading
Loading