Skip to content

Commit

Permalink
renamed reason to reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Toan Quach authored and Toan Quach committed May 30, 2024
1 parent 395f48e commit f6ee065
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions taipy/core/_entity/_ready_to_run_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions taipy/core/_entity/submittable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/reason/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions taipy/core/reason/reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions taipy/core/scenario/_scenario_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions taipy/core/sequence/_sequence_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions taipy/core/taipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions taipy/core/task/_task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions tests/core/_entity/test_ready_to_run_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/core/common/test_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."

Expand Down
6 changes: 3 additions & 3 deletions tests/gui_core/test_context_is_submitable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}})
Expand All @@ -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):
Expand Down

0 comments on commit f6ee065

Please sign in to comment.