Skip to content
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

Better linting for scenarios and data nodes #2304

Open
1 of 7 tasks
FlorianJacta opened this issue Dec 6, 2024 · 0 comments
Open
1 of 7 tasks

Better linting for scenarios and data nodes #2304

FlorianJacta opened this issue Dec 6, 2024 · 0 comments
Labels
Core Related to Taipy Core ✨New feature 🟨 Priority: Medium Not blocking but should be addressed

Comments

@FlorianJacta
Copy link
Member

FlorianJacta commented Dec 6, 2024

Description

Right now, using Taipy Core with the configuration, we do not get Intellisense linting when coding with the scenario.

We don't know what is inside our scenario, which tasks, and which data nodes, and we have lost a way to have accessible documentation.

This issue is connected with issue: #2024

Solution Proposed

We could propose to have an export to Python file.

Config.export("config/CoreModels.py")

This will create a Python file with what is inside the scenario:

from taipy import Scenario, DataNode, Task

class DefaultScenario(Scenario):

    pass

class ScenarioScenario(Scenario):
    warehouse_vars: DataNode
    nb_of_warehouses: DataNode
    flow_vars: DataNode
    customers: DataNode
    UPS_problem: DataNode
    metrics: DataNode
    fixed_warehouses: DataNode
    total_demand: DataNode
    results: DataNode
    warehouses_results: DataNode
    warehouses: DataNode
    fix_warehouses: DataNode
    fixed_warehouse_ids: DataNode
    rates: DataNode
    active_warehouses: DataNode
    list_warehouses_open: DataNode

    process_data: Task
    get_solution: Task
    create_and_solve_model: Task
    pass

If I combine if with my state class that I manually created. (This should be great if this is done automatically)

from taipy.gui import State
from taipy.core import DataNode
from configuration.CoreModels import ScenarioScenario

import pandas as pd


class State(State):
    warehouses: pd.DataFrame
    customers: pd.DataFrame
    results: pd.DataFrame
    list_warehouses_open: list

    scenario: ScenarioScenario
    data_node: DataNode
    results_dn: DataNode
    nb_of_warehouses: int
    fix_warehouses: bool
    fixed_warehouses: list
    metrics: dict

    scenario_1: ScenarioScenario
    scenario_2: ScenarioScenario

    metrics_1: dict
    metrics_2: dict

I can now code easily. I know all my state variables. I know what is inside my scenario, the attributes, functions, data nodes, tasks, and also what is inside my data nodes.

image

image

If you want to test this out; this is the code I created. You only need to put if after the configuration where you should use Config.export("config.toml") for example.

def export_as_py(filename: str):
    with open(filename, "w") as f:
        # Write the necessary imports
        f.write("from taipy import Scenario, DataNode, Task\n\n")

        # Iterate over each scenario configuration in Config
        for scenario_key, scenario_config in Config.scenarios.items():
            # Create a class name. For example, if scenario_key is "my_scenario",
            # class might be "My_scenarioScenario". Adjust naming as desired.
            class_name = f"{scenario_key.lower().capitalize()}Scenario"

            f.write(f"class {class_name}(Scenario):\n")

            # Iterate over all data nodes for the current scenario
            for dn_config in scenario_config.data_nodes:
                # Use the id of the data node as the attribute name
                dn_name = dn_config.id
                f.write(f"    {dn_name}: DataNode\n")

            f.write("\n")

            for task_config in scenario_config.tasks:
                # Use the id of the task as the attribute name
                task_name = task_config.id
                f.write(f"    {task_name}: Task\n")

            # Add a blank line after each class for readability
            f.write("    pass\n")
            f.write("\n")

# Config.export("configuration/CoreModels.py")
export_as_py("configuration/CoreModels.py")

Impact of Solution

This is just a proposition. I don't know how easy it is to introduce inside the developer workflow.

Acceptance Criteria

  • If applicable, a new demo code is provided to show the new feature in action.
  • Integration tests exhibiting how the functionality works are added.
  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.
  • Related issue(s) in taipy-doc are created for documentation and Release Notes are updated.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@FlorianJacta FlorianJacta added Core Related to Taipy Core 🟨 Priority: Medium Not blocking but should be addressed ✨New feature labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to Taipy Core ✨New feature 🟨 Priority: Medium Not blocking but should be addressed
Projects
None yet
Development

No branches or pull requests

1 participant