From f6ee065193ca2c0b59e1e97aee808f3d72a85a59 Mon Sep 17 00:00:00 2001 From: Toan Quach Date: Thu, 30 May 2024 15:58:59 +0700 Subject: [PATCH] renamed reason to reasons --- taipy/core/_entity/_ready_to_run_property.py | 6 +++--- taipy/core/_entity/submittable.py | 6 +++--- taipy/core/reason/__init__.py | 2 +- taipy/core/reason/reason.py | 6 +++--- taipy/core/scenario/_scenario_manager.py | 6 +++--- taipy/core/sequence/_sequence_manager.py | 6 +++--- taipy/core/taipy.py | 6 +++--- taipy/core/task/_task_manager.py | 8 ++++---- .../_entity/test_ready_to_run_property.py | 20 +++++++++---------- tests/core/common/test_reason.py | 8 ++++---- tests/gui_core/test_context_is_submitable.py | 6 +++--- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/taipy/core/_entity/_ready_to_run_property.py b/taipy/core/_entity/_ready_to_run_property.py index 4e5e367ddb..6ad087b0df 100644 --- a/taipy/core/_entity/_ready_to_run_property.py +++ b/taipy/core/_entity/_ready_to_run_property.py @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Dict, Set, Union from ..notification import EventOperation, Notifier, _make_event -from ..reason.reason import Reason +from ..reason.reason import Reasons if TYPE_CHECKING: from ..data.data_node import DataNode, DataNodeId @@ -29,7 +29,7 @@ class _ReadyToRunProperty: # A nested dictionary of the submittable entities (Scenario, Sequence, Task) and # the data nodes that make it not ready_to_run with the reason(s) - _submittable_id_datanodes: Dict[Union["ScenarioId", "SequenceId", "TaskId"], Reason] = {} + _submittable_id_datanodes: Dict[Union["ScenarioId", "SequenceId", "TaskId"], Reasons] = {} @classmethod def _add(cls, dn: "DataNode", reason: str) -> None: @@ -81,7 +81,7 @@ def __add(cls, submittable: Union["Scenario", "Sequence", "Task"], datanode: "Da cls.__publish_submittable_property_event(submittable, False) if submittable.id not in cls._submittable_id_datanodes: - cls._submittable_id_datanodes[submittable.id] = Reason(submittable.id) + cls._submittable_id_datanodes[submittable.id] = Reasons(submittable.id) cls._submittable_id_datanodes[submittable.id]._add_reason(datanode.id, reason) @staticmethod diff --git a/taipy/core/_entity/submittable.py b/taipy/core/_entity/submittable.py index 9e782c576c..09b6fdfd85 100644 --- a/taipy/core/_entity/submittable.py +++ b/taipy/core/_entity/submittable.py @@ -20,7 +20,7 @@ from ..data.data_node import DataNode from ..job.job import Job from ..reason._reason_factory import _build_data_node_is_being_edited_reason, _build_data_node_is_not_written -from ..reason.reason import Reason +from ..reason.reason import Reasons from ..submission.submission import Submission from ..task.task import Task from ._dag import _DAG @@ -83,14 +83,14 @@ def get_intermediate(self) -> Set[DataNode]: all_data_nodes_in_dag = {node for node in dag.nodes if isinstance(node, DataNode)} return all_data_nodes_in_dag - self.__get_inputs(dag) - self.__get_outputs(dag) - def is_ready_to_run(self) -> Reason: + def is_ready_to_run(self) -> Reasons: """Indicate if the entity is ready to be run. Returns: A Reason object that can function as a Boolean value. which is True if the given entity is ready to be run or there is no reason to be blocked, False otherwise. """ - reason = Reason(self._submittable_id) + reason = Reasons(self._submittable_id) for node in self.get_inputs(): if node._edit_in_progress: diff --git a/taipy/core/reason/__init__.py b/taipy/core/reason/__init__.py index 40b66ee99c..347aaa33ff 100644 --- a/taipy/core/reason/__init__.py +++ b/taipy/core/reason/__init__.py @@ -9,4 +9,4 @@ # 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 .reason import Reason +from .reason import Reasons diff --git a/taipy/core/reason/reason.py b/taipy/core/reason/reason.py index 1a3bd1a170..471fdebc09 100644 --- a/taipy/core/reason/reason.py +++ b/taipy/core/reason/reason.py @@ -12,18 +12,18 @@ from typing import Dict, Set -class Reason: +class Reasons: def __init__(self, entity_id: str) -> None: self.entity_id: str = entity_id self._reasons: Dict[str, Set[str]] = {} - def _add_reason(self, entity_id: str, reason: str) -> "Reason": + def _add_reason(self, entity_id: str, reason: str) -> "Reasons": if entity_id not in self._reasons: self._reasons[entity_id] = set() self._reasons[entity_id].add(reason) return self - def _remove_reason(self, entity_id: str, reason: str) -> "Reason": + def _remove_reason(self, entity_id: str, reason: str) -> "Reasons": if entity_id in self._reasons and reason in self._reasons[entity_id]: self._reasons[entity_id].remove(reason) if len(self._reasons[entity_id]) == 0: diff --git a/taipy/core/scenario/_scenario_manager.py b/taipy/core/scenario/_scenario_manager.py index 6aeabbb29a..0b2cee2341 100644 --- a/taipy/core/scenario/_scenario_manager.py +++ b/taipy/core/scenario/_scenario_manager.py @@ -47,7 +47,7 @@ from ..job.job import Job from ..notification import EventEntityType, EventOperation, Notifier, _make_event from ..reason._reason_factory import _build_not_submittable_entity_reason -from ..reason.reason import Reason +from ..reason.reason import Reasons from ..submission._submission_manager_factory import _SubmissionManagerFactory from ..submission.submission import Submission from ..task._task_manager_factory import _TaskManagerFactory @@ -198,13 +198,13 @@ def _create( return scenario @classmethod - def _is_submittable(cls, scenario: Union[Scenario, ScenarioId]) -> Reason: + def _is_submittable(cls, scenario: Union[Scenario, ScenarioId]) -> Reasons: if isinstance(scenario, str): scenario = cls._get(scenario) if not isinstance(scenario, Scenario): scenario = str(scenario) - reason = Reason((scenario)) + reason = Reasons((scenario)) reason._add_reason(scenario, _build_not_submittable_entity_reason(scenario)) return reason diff --git a/taipy/core/sequence/_sequence_manager.py b/taipy/core/sequence/_sequence_manager.py index 923a6fb62d..78340d1b8f 100644 --- a/taipy/core/sequence/_sequence_manager.py +++ b/taipy/core/sequence/_sequence_manager.py @@ -32,7 +32,7 @@ from ..notification import Event, EventEntityType, EventOperation, Notifier from ..notification.event import _make_event from ..reason._reason_factory import _build_not_submittable_entity_reason -from ..reason.reason import Reason +from ..reason.reason import Reasons from ..scenario._scenario_manager_factory import _ScenarioManagerFactory from ..scenario.scenario import Scenario from ..scenario.scenario_id import ScenarioId @@ -344,13 +344,13 @@ def __remove_subscriber(cls, callback, params, sequence): Notifier.publish(_make_event(sequence, EventOperation.UPDATE, attribute_name="subscribers")) @classmethod - def _is_submittable(cls, sequence: Union[Sequence, SequenceId]) -> Reason: + def _is_submittable(cls, sequence: Union[Sequence, SequenceId]) -> Reasons: if isinstance(sequence, str): sequence = cls._get(sequence) if not isinstance(sequence, Sequence): sequence = str(sequence) - reason = Reason(sequence) + reason = Reasons(sequence) reason._add_reason(sequence, _build_not_submittable_entity_reason(sequence)) return reason diff --git a/taipy/core/taipy.py b/taipy/core/taipy.py index d907fa142b..72a3ac7124 100644 --- a/taipy/core/taipy.py +++ b/taipy/core/taipy.py @@ -52,7 +52,7 @@ from .job.job import Job from .job.job_id import JobId from .reason._reason_factory import _build_not_submittable_entity_reason -from .reason.reason import Reason +from .reason.reason import Reasons from .scenario._scenario_manager_factory import _ScenarioManagerFactory from .scenario.scenario import Scenario from .scenario.scenario_id import ScenarioId @@ -91,7 +91,7 @@ def set(entity: Union[DataNode, Task, Sequence, Scenario, Cycle, Submission]): return _SubmissionManagerFactory._build_manager()._set(entity) -def is_submittable(entity: Union[Scenario, ScenarioId, Sequence, SequenceId, Task, TaskId, str]) -> Reason: +def is_submittable(entity: Union[Scenario, ScenarioId, Sequence, SequenceId, Task, TaskId, str]) -> Reasons: """Indicate if an entity can be submitted. This function checks if the given entity can be submitted for execution. @@ -111,7 +111,7 @@ def is_submittable(entity: Union[Scenario, ScenarioId, Sequence, SequenceId, Tas return _TaskManagerFactory._build_manager()._is_submittable(entity) if isinstance(entity, str) and entity.startswith(Task._ID_PREFIX): return _TaskManagerFactory._build_manager()._is_submittable(TaskId(entity)) - return Reason(str(entity))._add_reason(str(entity), _build_not_submittable_entity_reason(str(entity))) + return Reasons(str(entity))._add_reason(str(entity), _build_not_submittable_entity_reason(str(entity))) def is_editable( diff --git a/taipy/core/task/_task_manager.py b/taipy/core/task/_task_manager.py index 186f0f6ff3..c117b89056 100644 --- a/taipy/core/task/_task_manager.py +++ b/taipy/core/task/_task_manager.py @@ -31,7 +31,7 @@ _build_data_node_is_not_written, _build_not_submittable_entity_reason, ) -from ..reason.reason import Reason +from ..reason.reason import Reasons from ..scenario.scenario_id import ScenarioId from ..sequence.sequence_id import SequenceId from ..submission.submission import Submission @@ -169,15 +169,15 @@ def _get_children_entity_ids(cls, task: Task) -> _EntityIds: return entity_ids @classmethod - def _is_submittable(cls, task: Union[Task, TaskId]) -> Reason: + def _is_submittable(cls, task: Union[Task, TaskId]) -> Reasons: if isinstance(task, str): task = cls._get(task) if not isinstance(task, Task): task = str(task) - reason = Reason(task) + reason = Reasons(task) reason._add_reason(task, _build_not_submittable_entity_reason(task)) else: - reason = Reason(task.id) + reason = Reasons(task.id) data_manager = _DataManagerFactory._build_manager() for node in task.input.values(): node = data_manager._get(node) diff --git a/tests/core/_entity/test_ready_to_run_property.py b/tests/core/_entity/test_ready_to_run_property.py index 12f96ea1ff..67d5634ec8 100644 --- a/tests/core/_entity/test_ready_to_run_property.py +++ b/tests/core/_entity/test_ready_to_run_property.py @@ -14,7 +14,7 @@ from taipy.config.common.frequency import Frequency from taipy.config.config import Config from taipy.core._entity._ready_to_run_property import _ReadyToRunProperty -from taipy.core.reason.reason import Reason +from taipy.core.reason.reason import Reasons from taipy.core.scenario._scenario_manager_factory import _ScenarioManagerFactory from taipy.core.sequence._sequence_manager_factory import _SequenceManagerFactory from taipy.core.task._task_manager_factory import _TaskManagerFactory @@ -33,7 +33,7 @@ def test_scenario_without_input_is_ready_to_run(): scenario = scenario_manager._create(scenario_config) assert scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes @@ -46,7 +46,7 @@ def test_scenario_submittable_with_inputs_is_ready_to_run(): scenario = scenario_manager._create(scenario_config) assert scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes @@ -61,7 +61,7 @@ def test_scenario_submittable_even_with_output_not_ready_to_run(): dn_3 = scenario.dn_3 assert not dn_3.is_ready_for_reading - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes @@ -78,7 +78,7 @@ def test_scenario_not_submittable_not_in_property_because_it_is_lazy(): assert dn_1.is_ready_for_reading assert not dn_2.is_ready_for_reading assert not scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) # Since it is a lazy property, the scenario and the datanodes is not yet in the dictionary assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes @@ -97,7 +97,7 @@ def test_scenario_not_submittable_if_one_input_edit_in_progress(): assert not dn_1.is_ready_for_reading assert not scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id in _ReadyToRunProperty._submittable_id_datanodes assert dn_1.id in _ReadyToRunProperty._submittable_id_datanodes[scenario.id]._reasons @@ -125,7 +125,7 @@ def test_scenario_not_submittable_for_multiple_reasons(): assert not dn_1.is_ready_for_reading assert not dn_2.is_ready_for_reading assert not scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id in _ReadyToRunProperty._submittable_id_datanodes assert dn_1.id in _ReadyToRunProperty._submittable_id_datanodes[scenario.id]._reasons @@ -156,7 +156,7 @@ def test_writing_input_remove_reasons(): assert not dn_1.is_ready_for_reading assert not scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) # Since it is a lazy property, the scenario is not yet in the dictionary assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes @@ -171,7 +171,7 @@ def test_writing_input_remove_reasons(): dn_1.write(10) assert scenario_manager._is_submittable(scenario) - assert isinstance(scenario_manager._is_submittable(scenario), Reason) + assert isinstance(scenario_manager._is_submittable(scenario), Reasons) assert scenario.id not in _ReadyToRunProperty._submittable_id_datanodes assert dn_1.id not in _ReadyToRunProperty._datanode_id_submittables @@ -197,7 +197,7 @@ def __assert_not_submittable_becomes_submittable_when_dn_edited(entity, manager, dn.write("ANY VALUE") assert manager._is_submittable(entity) - assert isinstance(manager._is_submittable(entity), Reason) + assert isinstance(manager._is_submittable(entity), Reasons) assert entity.id not in _ReadyToRunProperty._submittable_id_datanodes assert dn.id not in _ReadyToRunProperty._datanode_id_submittables diff --git a/tests/core/common/test_reason.py b/tests/core/common/test_reason.py index 7392b04961..4ce21cf8fa 100644 --- a/tests/core/common/test_reason.py +++ b/tests/core/common/test_reason.py @@ -9,11 +9,11 @@ # 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 taipy.core.reason.reason import Reason +from taipy.core.reason.reason import Reasons def test_create_reason(): - reason = Reason("entity_id") + reason = Reasons("entity_id") assert reason.entity_id == "entity_id" assert reason._reasons == {} assert reason @@ -22,7 +22,7 @@ def test_create_reason(): def test_add_and_remove_reason(): - reason = Reason("entity_id") + reason = Reasons("entity_id") reason._add_reason("entity_id_1", "Some reason") assert reason._reasons == {"entity_id_1": {"Some reason"}} assert not reason @@ -55,7 +55,7 @@ def test_add_and_remove_reason(): def test_get_reason_string_from_reason(): - reason = Reason("entity_id") + reason = Reasons("entity_id") reason._add_reason("entity_id_1", "Some reason") assert reason.reasons == "Some reason." diff --git a/tests/gui_core/test_context_is_submitable.py b/tests/gui_core/test_context_is_submitable.py index 620a11f65a..7e8a19a5f5 100644 --- a/tests/gui_core/test_context_is_submitable.py +++ b/tests/gui_core/test_context_is_submitable.py @@ -14,7 +14,7 @@ from taipy.config.common.scope import Scope from taipy.core import Job, JobId, Scenario, Task from taipy.core.data.pickle import PickleDataNode -from taipy.core.reason.reason import Reason +from taipy.core.reason.reason import Reasons from taipy.gui_core._context import _GuiCoreContext a_scenario = Scenario("scenario_config_id", None, {}, sequences={"sequence": {}}) @@ -25,13 +25,13 @@ def mock_is_submittable_reason(entity_id): - reason = Reason(entity_id) + reason = Reasons(entity_id) reason._add_reason(entity_id, "a reason") return reason def mock_has_no_reason(entity_id): - return Reason(entity_id) + return Reasons(entity_id) def mock_core_get(entity_id):