#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Data set  data = {"Opps": ["Hot leads", "Doc sent", "Quote", "Closed Won"], "Visits": [316, 238, 125, 83]}    page = """  # Funnel Chart - Simple    <|{data}|chart|type=funnel|x=Visits|y=Opps|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = [      {          "Temperatures": [              [17.2, 27.4, 28.6, 21.5],              [5.6, 15.1, 20.2, 8.1],              [26.6, 22.8, 21.8, 24.0],              [22.3, 15.5, 13.4, 19.6],              [3.9, 18.9, 25.7, 9.8],          ],          "Cities": ["Hanoi", "Paris", "Rio", "Sydney", "Washington"],      },      {"Seasons": ["Winter", "Spring", "Summer", "Autumn"]},  ]    page = """  # Heatmap - Unbalanced    <|{data}|chart|type=heatmap|z=0/Temperatures|x=1/Seasons|y=0/Cities|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Sample small plot definition  trace = {      "r": [1, 2, 3, 4, 1],      "theta": [0, 40, 80, 120, 160],  }    # The same data is used in both traces  data = [trace, trace]    # Naming the subplot is mandatory to get them both in  # the same chart  options = [      {          "subplot": "polar",      },      {"subplot": "polar2"},  ]    layout = {      # Hide the legend      "showlegend": False,      # Restrict the angular values for second trace      "polar2": {"sector": [30, 130]},  }    md = """  # Polar - Sectors    <|{data}|chart|type=scatterpolar|layout={layout}|options={options}|>  """    Gui(md).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # You may need to install the yfinance package as well.  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "x": [1, 2, 3],      "y": [1, 2, 3],      "Colors": ["blue", "green", "red"],      "Sizes": [20, 40, 30],      "Opacities": [1, 0.4, 1],  }    marker = {"color": "Colors", "size": "Sizes", "opacity": "Opacities"}    page = """  # Bubble - Simple    <|{data}|chart|mode=markers|x=x|y=y|marker={marker}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Source: www.statista.com (Most used programming languages in 2022)  data = {      # List of programming languages      "Language": ["JavaScript", "HTML/CSS", "SQL", "Python", "Typescript", "Java", "Bash/Shell"],      # Percentage of usage, per language      "%": [65.36, 55.08, 49.43, 48.07, 34.83, 33.27, 29.07],  }    # Close the shape for a nice-looking stroke  # If the first point is *not* appended to the end of the list,  # then the shape does not look as it is closed.  data["%"].append(data["%"][0])  data["Language"].append(data["Language"][0])    layout = {      "polar": {          "radialaxis": {              # Force the radial range to 0-100              "range": [0, 100],          }      },      # Hide legend      "showlegend": False,  }    options = {      # Fill the trace      "fill": "toself"  }    md = """  # Radar - Simple    <|{data}|chart|type=scatterpolar|r=%|theta=Language|options={options}|layout={layout}|>  """    Gui(md).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Initial data set. y = count_of(x)  samples = {"x": ["Apples", "Apples", "Apples", "Oranges", "Bananas", "Oranges"], "y": [5, 10, 3, 8, 5, 2]}    # Create a data set array to allow for two traces  data = [samples, samples]    # Gather those settings in a single dictionary  properties = {      # 'x' of the first trace is the 'x' data from the first element of data      "x[1]": "0/x",      # 'y' of the first trace is the 'y' data from the first element of data      "y[1]": "0/y",      # 'x' of the second trace is the 'x' data from the second element of data      "x[2]": "1/x",      # 'y' of the second trace is the 'y' data from the second element of data      "y[2]": "1/y",      # Data set colors      "color": ["#cd5c5c", "#505070"],      # Data set names (for the legend)      "name": ["Count", "Sum"],      # Configure the binning functions      "options": [          # First trace: count the bins          {"histfunc": "count"},          # Second trace: sum the bin occurences          {"histfunc": "sum"},      ],      # Set x axis name      "layout": {"xaxis": {"title": "Fruit"}},  }    page = """  # Histogram - Binning function    <|{data}|chart|type=histogram|properties={properties}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Skill categories  skills = ["HTML", "CSS", "Java", "Python", "PHP", "JavaScript", "Photoshop"]  data = [      # Proportion of skills used for Backend development      {"Backend": [10, 10, 80, 70, 90, 30, 0], "Skills": skills},      # Proportion of skills used for Frontend development      {"Frontend": [90, 90, 0, 10, 20, 80, 60], "Skills": skills},  ]    # Append first elements to all arrays for a nice stroke  skills.append(skills[0])  data[0]["Backend"].append(data[0]["Backend"][0])  data[1]["Frontend"].append(data[1]["Frontend"][0])    layout = {      # Force the radial axis displayed range      "polar": {"radialaxis": {"range": [0, 100]}}  }    # Fill the trace  options = {"fill": "toself"}    # Reflected in the legend  names = ["Backend", "Frontend"]    # To shorten the chart control definition  r = ["0/Backend", "1/Frontend"]  theta = ["0/Skills", "1/Skills"]    page = """  # Radar - Multiple    <|{data}|chart|type=scatterpolar|name={names}|r={r}|theta={theta}|options={options}|layout={layout}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # x values are [-10..10]  x_range = range(-10, 11)    # The data set holds the _x_ series and two distinct series for _y_  data = {      "x": x_range,      # y1 = x*x      "y1": [x * x for x in x_range],      # y2 = 2-x*x/50      "y2": [(100 - x * x) / 50 for x in x_range],  }    layout = {      "yaxis2": {          # Second axis overlays with the first y axis          "overlaying": "y",          # Place the second axis on the right          "side": "right",          # and give it a title          "title": "Second y axis",      },      "legend": {          # Place the legend above chart          "yanchor": "bottom"      },  }    page = """  # Basics - Multiple axis    Shared axis:  <|{data}|chart|x=x|y[1]=y1|y[2]=y2|height=300px|>    With two axis:  <|{data}|chart|x=x|y[1]=y1|y[2]=y2|yaxis[2]=y2|layout={layout}|height=300px|>    """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Source https://www.fao.org/faostat/en/#data/SDGB  data = {      "Country": [          "Rest of the world",          "Russian Federation",          "Brazil",          "Canada",          "United States of America",          "China",          "Australia",          "Democratic Republic of the Congo",          "Indonesia",          "Peru",      ],      "Area": [1445674.66, 815312, 496620, 346928, 309795, 219978, 134005, 126155, 92133.2, 72330.4],  }    page = """  # Pie - Simple    <|{data}|chart|type=pie|values=Area|label=Country|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # You may need to install the scikit-learn package as well.  # -----------------------------------------------------------------------------------------  from os.path import exists    from sklearn.datasets import make_regression  from sklearn.linear_model import LinearRegression  from taipy.gui import Gui    # Let scikit-learn generate a random regression problem  n_samples = 300  X, y, coef = make_regression(n_samples=n_samples, n_features=1, n_informative=1, n_targets=1, noise=25, coef=True)    model = LinearRegression().fit(X, y)    x_data = X.flatten()  y_data = y.flatten()  predict = model.predict(X)    data = {"x": x_data, "y": y_data, "Regression": predict}    page = """  # Scatter - Regression    <|{data}|chart|x=x|y[1]=y|mode[1]=markers|y[2]=Regression|mode[2]=line|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "Temperatures": [          [17.2, 27.4, 28.6, 21.5],          [5.6, 15.1, 20.2, 8.1],          [26.6, 22.8, 21.8, 24.0],          [22.3, 15.5, 13.4, 19.6],      ],      "Cities": ["Hanoi", "Paris", "Rio", "Sydney"],      "Seasons": ["Winter", "Spring", "Summer", "Autumn"],  }    layout = {      # This array contains the information we want to display in the cells      # These are filled later      "annotations": [],      # No ticks on the x axis, show labels on top the of the chart      "xaxis": {"ticks": "", "side": "top"},      # No ticks on the y axis      # Add a space character for a small margin with the text      "yaxis": {"ticks": "", "ticksuffix": " "},  }    seasons = data["Seasons"]  cities = data["Cities"]  # Iterate over all cities  for city in range(len(cities)):      # Iterate over all seasons      for season in range(len(seasons)):          temperature = data["Temperatures"][city][season]          # Create the annotation          annotation = {              # The name of the season              "x": seasons[season],              # The name of the city              "y": cities[city],              # The temperature, as a formatted string              "text": f"{temperature}\N{DEGREE SIGN}C",              # Change the text color depending on the temperature              # so it results in a better contrast              "font": {"color": "white" if temperature < 14 else "black"},              # Remove the annotation arrow              "showarrow": False,          }          # Add the annotation to the layout's annotations array          layout["annotations"].append(annotation)    page = """  ## Heatmap - Annotated    <|{data}|chart|type=heatmap|z=Temperatures|x=Seasons|y=Cities|layout={layout}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "Types": ["Website visit", "Downloads", "Prospects", "Invoice sent", "Closed"],      "Visits_us": [13873, 10533, 5443, 2703, 908],      "Visits_eu": [7063, 4533, 3443, 1003, 1208],      "Visits_ap": [6873, 2533, 3443, 1703, 508],  }    # Columns for each trace  x = ["Visits_us", "Visits_eu", "Visits_ap"]    # Legend text for each trace  names = ["US", "EU", "AP"]    page = """  # Funnel - Multiple traces    <|{data}|chart|type=funnel|x={x}|y=Types|name={names}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "Temperatures": [          [17.2, 27.4, 28.6, 21.5],          [5.6, 15.1, 20.2, 8.1],          [26.6, 22.8, 21.8, 24.0],          [22.3, 15.5, 13.4, 19.6],      ],      "Cities": ["Hanoi", "Paris", "Rio", "Sydney"],      "Seasons": ["Winter", "Spring", "Summer", "Autumn"],  }    page = """  # Heatmap - Basic    <|{data}|chart|type=heatmap|z=Temperatures|x=Seasons|y=Cities|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  # Face-to-face bar charts example  import numpy  from taipy.gui import Gui    n_years = 10    proportions_female = numpy.zeros(n_years)  proportions_male = numpy.zeros(n_years)    # Prepare the data set with random variations  proportions_female[0] = 0.4  proportions_male[0] = proportions_female[0] * (1 + numpy.random.normal(0, 0.1))    for i in range(1, n_years):      mean_i = (0.5 - proportions_female[i - 1]) / 5      new_value = proportions_female[i - 1] + numpy.random.normal(mean_i, 0.1)        new_value = min(max(0, new_value), 1)      proportions_female[i] = new_value      proportions_male[i] = proportions_female[i] * (1 + numpy.random.normal(0, 0.1))      data = {      "Hobbies": [          "Archery",          "Tennis",          "Football",          "Basket",          "Volley",          "Golf",          "Video-Games",          "Reading",          "Singing",          "Music",      ],      "Female": proportions_female,      # Negate these values so they appear to the left side      "Male": -proportions_male,  }    properties = {      # Shared y values      "y": "Hobbies",      # Bars for the female data set      "x[1]": "Female",      "color[1]": "#c26391",      # Bars for the male data set      "x[2]": "Male",      "color[2]": "#5c91de",      # Both data sets are represented with an horizontal orientation      "orientation": "h",      #      "layout": {          # This makes left and right bars aligned on the same y value          "barmode": "overlay",          # Set a relevant title for the x axis          "xaxis": {"title": "Gender"},          # Hide the legend          "showlegend": False,          "margin": {"l": 100},      },  }    page = """  # Bar - Facing    <|{data}|chart|type=bar|properties={properties}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import random    from taipy.gui import Gui    # Random data set  data = [random.random() for i in range(100)]    # Normalize to show bin probabilities  options = {"histnorm": "probability"}    page = """  # Histogram - Normalized    <|{data}|chart|type=histogram|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # You may need to install the scikit-learn package as well.  # -----------------------------------------------------------------------------------------  import numpy  import pandas  from sklearn.datasets import make_classification  from taipy.gui import Gui    # Let scikit-learn generate a random 2-class classification problem  features, label = make_classification(n_samples=1000, n_features=2, n_informative=2, n_redundant=0)    random_data = pandas.DataFrame({"x": features[:, 0], "y": features[:, 1], "label": label})    data_x = random_data["x"]  class_A = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 0 else numpy.nan for i in range(len(random_data))]  class_B = [random_data.loc[i, "y"] if random_data.loc[i, "label"] == 1 else numpy.nan for i in range(len(random_data))]    data = {"x": random_data["x"], "Class A": class_A, "Class B": class_B}    page = """  # Scatter - Classification    <|{data}|chart|mode=markers|x=x|y[1]=Class A|y[2]=Class B|width=60%|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from itertools import accumulate    import numpy as np  from taipy.gui import Gui    grid_size = 10  data = [      {          # z is set to:          # - 0 if row+col is a multiple of 4          # - 1 if row+col is a multiple of 2          # - 0.5 otherwise          "z": [              [0.0 if (row + col) % 4 == 0 else 1 if (row + col) % 2 == 0 else 0.5 for col in range(grid_size)]              for row in range(grid_size)          ]      },      {          # A series of coordinates, growing exponentially          "x": [0] + list(accumulate(np.logspace(0, 1, grid_size))),          # A series of coordinates, shrinking exponentially          "y": [0] + list(accumulate(np.logspace(1, 0, grid_size))),      },  ]    # Axis template used in the layout object  axis_template = {      # Don't show any line or tick or label      "showgrid": False,      "zeroline": False,      "ticks": "",      "showticklabels": False,      "visible": False,  }    layout = {"xaxis": axis_template, "yaxis": axis_template}    options = {      # Remove the color scale display      "showscale": False  }    page = """  ## Heatmap - Unequal block sizes    <|{data}|chart|type=heatmap|z=0/z|x=1/x|y=1/y|layout={layout}|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # 9-hole course  n_holes = 9    # Data set  # Each entry holds an array of values. One for each hole, plus one for th  data = {      # ["Hole1", "Hole2", ..., "Hole9"]      "Hole": [f"Hole{h}" for h in range(1, n_holes + 1)] + ["Score"],      # Par for each hole      "Par": [3, 4, 4, 5, 3, 5, 4, 5, 3] + [None],      # Score for each hole      "Score": [4, 4, 5, 4, 4, 5, 4, 5, 4] + [None],      # Represented as relative values except for the last one      "M": n_holes * ["relative"] + ["total"],  }    # Compute difference (Score-Par)  data["Diff"] = [data["Score"][i] - data["Par"][i] for i in range(0, n_holes)] + [None]    # Show positive values in red, and negative values in green  options = {"decreasing": {"marker": {"color": "green"}}, "increasing": {"marker": {"color": "red"}}}    page = """  # Waterfall - Styling    <|{data}|chart|type=waterfall|x=Hole|y=Diff|measure=M|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import random    from taipy.gui import Gui    # Common axis for all data: [1..10]  x = list(range(1, 11))  # Sample data  samples = [5, 7, 8, 4, 5, 9, 8, 8, 6, 5]    # Generate error data  # Error that adds to the input data  error_plus = [3 * random.random() + 0.5 for _ in x]  # Error substracted from to the input data  error_minus = [3 * random.random() + 0.5 for _ in x]    # Upper bound (y + error_plus)  error_upper = [y + e for (y, e) in zip(samples, error_plus)]  # Lower bound (y - error_minus)  error_lower = [y - e for (y, e) in zip(samples, error_minus)]    data = [      # Trace for samples      {"x": x, "y": samples},      # Trace for error range      {          # Roundtrip around the error bounds: onward then return          "x": x + list(reversed(x)),          # The two error bounds, with lower bound reversed          "y": error_upper + list(reversed(error_lower)),      },  ]    properties = {      # Error data      "x[1]": "1/x",      "y[1]": "1/y",      "options[1]": {          # Shows as filled area          "fill": "toself",          "fillcolor": "rgba(70,70,240,0.6)",          "showlegend": False,      },      # Don't show surrounding stroke      "color[1]": "transparent",      # Raw data (displayed on top of the error band)      "x[2]": "0/x",      "y[2]": "0/y",      "color[2]": "rgb(140,50,50)",      # Shown in the legend      "name[2]": "Input",  }    page = """  # Continuous Error - Simple    <|{data}|chart|properties={properties}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "Products": [          "Nail polish",          "Eyebrow pencil",          "Rouge",          "Lipstick",          "Eyeshadows",          "Eyeliner",          "Foundation",          "Lip gloss",          "Mascara",      ],      "USA": [12814, 13012, 11624, 8814, 12998, 12321, 10342, 22998, 11261],      "China": [3054, 5067, 7004, 9054, 12043, 15067, 10119, 12043, 10419],      "EU": [4376, 3987, 3574, 4376, 4572, 3417, 5231, 4572, 6134],      "Africa": [4229, 3932, 5221, 9256, 3308, 5432, 13701, 4008, 18712],  }    # Order the different traces  ys = ["USA", "China", "EU", "Africa"]    options = [      # For the USA      {"stackgroup": "one", "groupnorm": "percent"},      # For China      {"stackgroup": "one"},      # For the EU      {"stackgroup": "one"},      # For Africa      {"stackgroup": "one"},  ]    layout = {      # Show all values when hovering on a data point      "hovermode": "x unified"  }    page = """  # Filled Area - Stacked Normalized    <|{data}|chart|mode=none|x=Products|y={ys}|options={options}|layout={layout}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import math    from taipy.gui import Gui    # One data point for each degree  theta = range(0, 360)      # Create a rose-like shaped radius-array  def create_rose(n_petals):      return [math.cos(math.radians(n_petals * angle)) for angle in theta]      data = {"theta": theta, "r1": create_rose(2), "r2": create_rose(3), "r3": create_rose(4)}    # We want three traces in the same chart  r = ["r1", "r2", "r3"]    layout = {      # Hide the legend      "showlegend": False,      "polar": {          # Hide the angular axis          "angularaxis": {"visible": False},          # Hide the radial axis          "radialaxis": {"visible": False},      },  }    page = """  # Polar - Multiple    <|{data}|chart|type=scatterpolar|mode=lines|r={r}|theta=theta|layout={layout}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # You may need to install the yfinance package as well.  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "x": [1, 2, 3, 4, 5],      "y": [10, 7, 4, 1, 5],      "Sizes": [20, 30, 40, 50, 30],      "Symbols": ["circle-open", "triangle-up", "hexagram", "star-diamond", "circle-cross"],  }    marker = {      "color": "#77A",      "size": "Sizes",      "symbol": "Symbols",  }    page = """  # Bubble - Symbols    <|{data}|chart|mode=markers|x=x|y=y|marker={marker}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # You may need to install the yfinance package as well.  # -----------------------------------------------------------------------------------------  import yfinance  from taipy.gui import Gui    # Extraction of a few days of stock historical data for AAPL using  # the yfinance package (see https://pypi.org/project/yfinance/).  # The returned value is a Pandas DataFrame.  ticker = yfinance.Ticker("AAPL")  stock = ticker.history(interval="1d", start="2018-08-18", end="2018-09-10")  # Copy the DataFrame index to a new column  stock["Date"] = stock.index    options = {      # Candlesticks that show decreasing values are orange      "decreasing": {"line": {"color": "orange"}},      # Candlesticks that show decreasing values are blue      "increasing": {"line": {"color": "blue"}},  }    layout = {      "xaxis": {          # Hide the range slider          "rangeslider": {"visible": False}      }  }    page = """  # Candlestick - Styling    <|{stock}|chart|type=candlestick|x=Date|open=Open|close=Close|low=Low|high=High|options={options}|layout={layout}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    data = {      "Types": ["Website visit", "Downloads", "Prospects", "Invoice sent", "Closed"],      "Visits": [13873, 10533, 5443, 2703, 908],  }    marker = {      # Boxes are filled with a blue gradient color      "color": ["hsl(210,50%,50%)", "hsl(210,60%,60%)", "hsl(210,70%,70%)", "hsl(210,80%,80%)", "hsl(210,90%,90%)"],      # Lines get thicker, with an orange-to-green gradient color      "line": {"width": [1, 1, 2, 3, 4], "color": ["f5720a", "f39c1d", "f0cc3d", "aadb12", "8cb709"]},  }    options = {      # Lines connecting boxes are thick, dotted and green      "connector": {"line": {"color": "green", "dash": "dot", "width": 4}}  }    page = """  # Funnel Chart - Custom markers    <|{data}|chart|type=funnel|x=Visits|y=Types|marker={marker}|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import random    from taipy.gui import Gui    # Random data set  data = [random.random() for i in range(500)]    options = {      # Enable the cumulative histogram      "cumulative": {"enabled": True}  }    page = """  # Histogram - Cumulative    <|{data}|chart|type=histogram|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Create a star shape  data = {"r": [3, 1] * 5 + [3], "theta": list(range(0, 360, 36)) + [0]}    options = [      # First plot is filled with a yellow-ish color      {"subplot": "polar", "fill": "toself", "fillcolor": "#E4FF87"},      # Second plot is filled with a blue-ish color      {"fill": "toself", "subplot": "polar2", "fillcolor": "#709BFF"},  ]    layout = {      "polar": {          # This actually is the default value          "angularaxis": {              "direction": "counterclockwise",          },      },      "polar2": {          "angularaxis": {              # Rotate the axis 180° (0 is on the left)              "rotation": 180,              # Orient the axis clockwise              "direction": "clockwise",              # Show the angles as radians              "thetaunit": "radians",          },      },      # Hide the legend      "showlegend": False,  }    page = """  # Polar Charts - Direction    <|{data}|chart|type=scatterpolar|layout={layout}|options={options}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    value = "XS"    page = """  # Slider - List of values    <|{value}|slider|lov=XXS;XS;S;M;L;XL;XXL|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import io  from decimal import Decimal, getcontext    from taipy.gui import Gui, download    # Initial precision  precision = 10      def pi(precision: int) -> list[int]:      """Compute Pi to the required precision.        Adapted from https://docs.python.org/3/library/decimal.html      """      saved_precision = getcontext().prec  # Save precision      getcontext().prec = precision      three = Decimal(3)  # substitute "three=3.0" for regular floats      lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24      while s != lasts:          lasts = s          n, na = n + na, na + 8          d, da = d + da, da + 32          t = (t * n) / d          s += t      digits = []      while s != 0:          integral = int(s)          digits.append(integral)          s = (s - integral) * 10      getcontext().prec = saved_precision      return digits      # Generate the digits, save them in a CSV file content, and trigger a download action  # so the user can retrieve them  def download_pi(state):      digits = pi(state.precision)      buffer = io.StringIO()      buffer.write("index,digit\n")      for i, d in enumerate(digits):          buffer.write(f"{i},{d}\n")      download(state, content=bytes(buffer.getvalue(), "UTF-8"), name="pi.csv")      page = """  # File Download - Dynamic content    Precision:    <|{precision}|slider|min=2|max=10000|>    <|{None}|file_download|on_action=download_pi|label=Download Pi digits|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    value = 9    page = """  # Slider - Custom range    <|{value}|slider|min=1|max=10|>    Value: <|{value}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from datetime import date, timedelta    from taipy.gui import Gui    # Create the list of dates (all year 2000)  all_dates = {}  all_dates_str = []  start_date = date(2000, 1, 1)  end_date = date(2001, 1, 1)  a_date = start_date  while a_date < end_date:      date_str = a_date.strftime("%Y/%m/%d")      all_dates_str.append(date_str)      all_dates[date_str] = a_date      a_date += timedelta(days=1)    # Initial selection: first and last day  dates = [all_dates_str[1], all_dates_str[-1]]  # These two variables are used in text controls  start_sel = all_dates[dates[0]]  end_sel = all_dates[dates[1]]      def on_change(state, _, var_value):      # Update the text controls      state.start_sel = all_dates[var_value[0]]      state.end_sel = all_dates[var_value[1]]      page = """  # Slider - Date range    <|{dates}|slider|lov={all_dates_str}|>    Start: <|{start_sel}|text|format=d MMM|>    End: <|{end_sel}|text|format=d MMM|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  import os  from decimal import Decimal, getcontext  from tempfile import NamedTemporaryFile    from taipy.gui import Gui, download    # Initial precision  precision = 10  # Stores the path to the temporary file  temp_path = None      def pi(precision: int) -> list[int]:      """Compute Pi to the required precision.        Adapted from https://docs.python.org/3/library/decimal.html      """      saved_precision = getcontext().prec  # Save precision      getcontext().prec = precision      three = Decimal(3)  # substitute "three=3.0" for regular floats      lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24      while s != lasts:          lasts = s          n, na = n + na, na + 8          d, da = d + da, da + 32          t = (t * n) / d          s += t      digits = []      while s != 0:          integral = int(s)          digits.append(integral)          s = (s - integral) * 10      getcontext().prec = saved_precision      return digits      # Remove the temporary file  def clean_up(state):      os.remove(state.temp_path)      # Generate the digits, save them in a CSV temporary file, then trigger a download action  # for that file.  def download_pi(state):      digits = pi(state.precision)      with NamedTemporaryFile("r+t", suffix=".csv", delete=False) as temp_file:          state.temp_path = temp_file.name          temp_file.write("index,digit\n")          for i, d in enumerate(digits):              temp_file.write(f"{i},{d}\n")      download(state, content=temp_file.name, name="pi.csv", on_action=clean_up)      page = """  # File Download - Dynamic content    Precision:    <|{precision}|slider|min=2|max=10000|>    <|{None}|file_download|on_action=download_pi|label=Download Pi digits|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    value = 50    page = """  # Slider - Simple    <|{value}|slider|>    Value: <|{value}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    value = 40    page = """  # Slider - Vertical    <|{value}|slider|orientation=v|>    Value: <|{value}|>  """    Gui(page).run()


#  # 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.  # -----------------------------------------------------------------------------------------  # To execute this script, make sure that the taipy-gui package is installed in your  # Python environment and run:  #     python <script>  # -----------------------------------------------------------------------------------------  from taipy.gui import Gui    # Initial values  values = [20, 40, 80]    page = """  # Slider - Range    <|{values}|slider|>    Selection: <|{values}|>  """    Gui(page).run()


#  # 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.


import os  import sys    from taipy._cli._base_cli import _CLI  from taipy.core._core_cli import _CoreCLI  from taipy.core._entity._migrate_cli import _MigrateCLI  from taipy.core._version._cli._version_cli import _VersionCLI  from taipy.gui._gui_cli import _GuiCLI    from ._cli._help_cli import _HelpCLI  from ._cli._run_cli import _RunCLI  from ._cli._scaffold_cli import _ScaffoldCLI  from .version import _get_version      def _entrypoint():      # Add the current working directory to path to execute version command on FS repo      sys.path.append(os.path.normpath(os.getcwd()))        _CLI._parser.add_argument("-v", "--version", action="store_true", help="Print the current Taipy version and exit.")        _RunCLI.create_parser()      _GuiCLI.create_run_parser()      _CoreCLI.create_run_parser()        _VersionCLI.create_parser()      _ScaffoldCLI.create_parser()      _MigrateCLI.create_parser()      _HelpCLI.create_parser()        args = _CLI._parse()      if args.version:          print(f"Taipy {_get_version()}")          sys.exit(0)        _RunCLI.parse_arguments()      _HelpCLI.parse_arguments()      _VersionCLI.parse_arguments()      _MigrateCLI.parse_arguments()      _ScaffoldCLI.parse_arguments()        _CLI._remove_argument("help")      _CLI._parser.print_help()


import json  import os      def _get_version():      with open(f"{os.path.dirname(os.path.abspath(__file__))}{os.sep}version.json") as version_file:          version = json.load(version_file)          version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'          if vext := version.get("ext"):              version_string = f"{version_string}.{vext}"      return version_string


from importlib.util import find_spec    if find_spec("taipy"):      if find_spec("taipy.config"):          from taipy.config._init import *  # type: ignore        if find_spec("taipy.gui"):          from taipy.gui._init import *  # type: ignore        if find_spec("taipy.core"):          from taipy.core._init import *  # type: ignore        if find_spec("taipy.rest"):          from taipy.rest._init import *  # type: ignore        if find_spec("taipy.gui_core"):          from taipy.gui_core._init import *  # type: ignore        if find_spec("taipy.enterprise"):          from taipy.enterprise._init import *  # type: ignore        if find_spec("taipy._run"):          from taipy._run import _run as run  # type: ignore


import sys  import typing as t    from flask import Flask    from taipy.core import Core  from taipy.gui import Gui  from taipy.rest import Rest    if sys.version_info >= (3, 10):      from typing import TypeGuard    _AppType = t.Union[Gui, Rest, Core]  _AppTypeT = t.TypeVar("_AppTypeT", Gui, Rest, Core)      def _run(*services: _AppType, **kwargs) -> t.Optional[Flask]:      """Run one or multiple Taipy services.        A Taipy service is an instance of a class that runs code as a Web application.        Parameters:          *services (Union[`Gui^`, `Rest^`, `Core^`]): Services to run, as separate arguments.
              If several services are provided, all the services run simultaneously.
              If this is empty or set to None, this method does nothing.          **kwargs: Other parameters to provide to the services.      """        gui = __get_app(services, Gui)      rest = __get_app(services, Rest)      core = __get_app(services, Core)        if gui and core:          from taipy.core._core_cli import _CoreCLI          from taipy.gui._gui_cli import _GuiCLI            _CoreCLI.create_parser()          _GuiCLI.create_parser()        if rest or core:          if not core:              core = Core()          core.run()        if not rest and not gui:          return None        if gui and rest:          gui._set_flask(rest._app)  # type: ignore          return gui.run(**kwargs)      else:          app = rest or gui          assert app is not None  # Avoid pyright typing error          return app.run(**kwargs)      # Avoid black adding too many empty lines  # fmt: off  if sys.version_info >= (3, 10):      def __get_app(apps: t.Tuple[_AppType, ...], type_: t.Type[_AppTypeT]) -> t.Optional[_AppType]:          def filter_isinstance(tl: _AppType) -> TypeGuard[_AppTypeT]:              return isinstance(tl, type_)            return next(filter(filter_isinstance, apps), None)  else:      def __get_app(apps: t.Tuple[_AppType, ...], type_: t.Type[_AppTypeT]) -> t.Optional[_AppType]:          return next(filter(lambda a: isinstance(a, type_), apps), None)  # fmt: on


from ._core import Core  from ._entity.submittable import Submittable  from .cycle.cycle import Cycle  from .cycle.cycle_id import CycleId  from .data.data_node import DataNode  from .data.data_node_id import DataNodeId  from .job.job import Job  from .job.job_id import JobId  from .job.status import Status  from .scenario.scenario import Scenario  from .scenario.scenario_id import ScenarioId  from .sequence.sequence import Sequence  from .sequence.sequence_id import SequenceId  from .taipy import (      cancel_job,      clean_all_entities_by_version,      compare_scenarios,      create_global_data_node,      create_scenario,      delete,      delete_job,      delete_jobs,      exists,      export_scenario,      get,      get_cycles,      get_cycles_scenarios,      get_data_nodes,      get_entities_by_config_id,      get_jobs,      get_latest_job,      get_parents,      get_primary,      get_primary_scenarios,      get_scenarios,      get_sequences,      get_tasks,      is_deletable,      is_editable,      is_promotable,      is_readable,      is_submittable,      set,      set_primary,      submit,      subscribe_scenario,      subscribe_sequence,      tag,      unsubscribe_scenario,      unsubscribe_sequence,      untag,  )  from .task.task import Task  from .task.task_id import TaskId


"""# Taipy Core    The Taipy Core package is a Python library designed to build powerful, customized, data-driven back-end  applications. It provides the tools to help Python developers transform their algorithms into a  complete back-end application.  More details on the [Taipy Core](../../core/index.md) functionalities are available in the user manual.    To build a Taipy Core application, the first step consists of setting up the Taipy configuration to design  your application's characteristics and behaviors.  Import `Config^` from the `taipy.config^` module, then use the various methods of the `Config^` singleton class to  configure your core application. In particular, configure the  [data nodes](../../core/config/data-node-config.md), [tasks](../../core/config/task-config.md),  and [scenarios](../../core/config/scenario-config.md).  Please refer to the [Core configuration user manual](../../core/config/index.md) for more information and  detailed examples.    Once your application is configured, import module `import taipy as tp` so you can use any function described  in the following section on [Functionc](#functions). In particular, the most used functions are `tp.create_scenario()`,  `tp.get_scenarios()`, `tp.get_data_nodes()`, `tp.submit()`, used to get, create, and submit entities.    !!! Note        Taipy Core provides a runnable service, `Core^` that runs as a service in a dedicated thread. The purpose is to      have a dedicated thread responsible for dispatching the submitted jobs to an available executor for their execution.        In particular, this `Core^` service is automatically run when Core is used with Taipy REST or Taipy GUI. See the      [running services](../../run-deploy/run/running_services.md) page of the user manual for more details.  """    from ._init import *  from ._init_version import _read_version  from .common.mongo_default_document import MongoDefaultDocument  from .data.data_node_id import Edit  from .exceptions import exceptions    __version__ = _read_version()


import json  import os  from pathlib import Path      def _read_version():      with open(f"{Path(os.path.abspath(__file__)).parent}{os.sep}version.json") as version_file:          version = json.load(version_file)          version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'          if vext := version.get("ext"):              version_string = f"{version_string}.{vext}"      return version_string


from multiprocessing import Lock  from typing import Optional    from taipy.config import Config  from taipy.logger._taipy_logger import _TaipyLogger    from ._backup._backup import _init_backup_file_with_storage_folder  from ._core_cli import _CoreCLI  from ._orchestrator._dispatcher._job_dispatcher import _JobDispatcher  from ._orchestrator._orchestrator import _Orchestrator  from ._orchestrator._orchestrator_factory import _OrchestratorFactory  from ._version._version_manager_factory import _VersionManagerFactory  from .config import CoreSection  from .exceptions.exceptions import CoreServiceIsAlreadyRunning      class Core:      """      Core service      """        _is_running = False      __lock_is_running = Lock()        __logger = _TaipyLogger._get_logger()        _orchestrator: Optional[_Orchestrator] = None      _dispatcher: Optional[_JobDispatcher] = None        def __init__(self):          """          Initialize a Core service.          """          pass        def run(self, force_restart=False):          """          Start a Core service.            This function checks the configuration, manages application's version,          and starts a dispatcher and lock the Config.          """          if self.__class__._is_running:              raise CoreServiceIsAlreadyRunning            with self.__class__.__lock_is_running:              self.__class__._is_running = True            self.__update_core_section()          self.__manage_version()          self.__check_and_block_config()            if self._orchestrator is None:              self._orchestrator = _OrchestratorFactory._build_orchestrator()            self.__start_dispatcher(force_restart)        def stop(self):          """          Stop the Core service.            This function stops the dispatcher and unblock the Config for update.          """          Config.unblock_update()            if self._dispatcher:              self._dispatcher = _OrchestratorFactory._remove_dispatcher()              self.__logger.info("Core service has been stopped.")            with self.__class__.__lock_is_running:              self.__class__._is_running = False        @staticmethod      def __update_core_section():          _CoreCLI.create_parser()          Config._applied_config._unique_sections[CoreSection.name]._update(_CoreCLI.parse_arguments())        @staticmethod      def __manage_version():          _VersionManagerFactory._build_manager()._manage_version()          Config._applied_config._unique_sections[CoreSection.name]._update(              {"version_number": _VersionManagerFactory._build_manager()._get_latest_version()}          )        @staticmethod      def __check_and_block_config():          Config.check()          Config.block_update()          _init_backup_file_with_storage_folder()        def __start_dispatcher(self, force_restart):          if dispatcher := _OrchestratorFactory._build_dispatcher(force_restart=force_restart):              self._dispatcher = dispatcher            if Config.job_config.is_development:              _Orchestrator._check_and_execute_jobs_if_development_mode()


#!/usr/bin/env python    """The setup script."""  import json  import os    from setuptools import find_namespace_packages, find_packages, setup    with open("README.md") as readme_file:      readme = readme_file.read()    with open(f"src{os.sep}taipy{os.sep}core{os.sep}version.json") as version_file:      version = json.load(version_file)      version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'      if vext := version.get("ext"):          version_string = f"{version_string}.{vext}"    requirements = [      "pyarrow>=10.0.1,<11.0",      "networkx>=2.6,<3.0",      "openpyxl>=3.1.2,<3.2",      "modin[dask]>=0.23.0,<1.0",      "pymongo[srv]>=4.2.0,<5.0",      "sqlalchemy>=2.0.16,<2.1",      "toml>=0.10,<0.11",      "taipy-config@git+https://git@github.com/Avaiga/taipy-config.git@develop",  ]    test_requirements = ["pytest>=3.8"]    extras_require = {      "fastparquet": ["fastparquet==2022.11.0"],      "mssql": ["pyodbc>=4,<4.1"],      "mysql": ["pymysql>1,<1.1"],      "postgresql": ["psycopg2>2.9,<2.10"],  }    setup(      author="Avaiga",      author_email="dev@taipy.io",      python_requires=">=3.8",      classifiers=[          "Intended Audience :: Developers",          "License :: OSI Approved :: Apache Software License",          "Natural Language :: English",          "Programming Language :: Python :: 3",          "Programming Language :: Python :: 3.8",          "Programming Language :: Python :: 3.9",          "Programming Language :: Python :: 3.10",          "Programming Language :: Python :: 3.11",      ],      description="A Python library to build powerful and customized data-driven back-end applications.",      install_requires=requirements,      long_description=readme,      long_description_content_type="text/markdown",      license="Apache License 2.0",      keywords="taipy-core",      name="taipy-core",      package_dir={"": "src"},      packages=find_namespace_packages(where="src") + find_packages(include=["taipy", "taipy.core", "taipy.core.*"]),      include_package_data=True,      test_suite="tests",      tests_require=test_requirements,      url="https://github.com/avaiga/taipy-core",      version=version_string,      zip_safe=False,      extras_require=extras_require,  )


from typing import Dict    from taipy._cli._base_cli import _CLI    from .config import CoreSection      class _CoreCLI:      """Command-line interface for Taipy Core application."""        __MODE_ARGS: Dict[str, Dict] = {          "--development": {              "action": "store_true",              "dest": "taipy_development",              "help": """                  When execute Taipy application in `development` mode, all entities from the previous development version                  will be deleted before running new Taipy application.              """,          },          "--experiment": {              "dest": "taipy_experiment",              "nargs": "?",              "const": "",              "metavar": "VERSION",              "help": """                  When execute Taipy application in `experiment` mode, the current Taipy application is saved to a new                  version. If version name already exists, check for compatibility with current Python Config and run the                  application. Without being specified, the version number will be a random string.              """,          },          "--production": {              "dest": "taipy_production",              "nargs": "?",              "const": "",              "metavar": "VERSION",              "help": """                  When execute in `production` mode, the current version is used in production. All production versions                  should have the same configuration and share all entities. Without being specified, the latest version                  is used.              """,          },      }        __FORCE_ARGS: Dict[str, Dict] = {          "--force": {              "dest": "taipy_force",              "action": "store_true",              "help": """                  Force override the configuration of the version if existed and run the application. Default to False.              """,          },          "--no-force": {              "dest": "no_taipy_force",              "action": "store_true",              "help": "Stop the application if any Config conflict exists.",          },      }        @classmethod      def create_parser(cls):          core_parser = _CLI._add_groupparser("Taipy Core", "Optional arguments for Taipy Core service")            mode_group = core_parser.add_mutually_exclusive_group()          for mode_arg, mode_arg_dict in cls.__MODE_ARGS.items():              mode_group.add_argument(mode_arg, cls.__add_taipy_prefix(mode_arg), **mode_arg_dict)            force_group = core_parser.add_mutually_exclusive_group()          for force_arg, force_arg_dict in cls.__FORCE_ARGS.items():              force_group.add_argument(cls.__add_taipy_prefix(force_arg), **force_arg_dict)        @classmethod      def create_run_parser(cls):          run_parser = _CLI._add_subparser("run", help="Run a Taipy application.")          mode_group = run_parser.add_mutually_exclusive_group()          for mode_arg, mode_arg_dict in cls.__MODE_ARGS.items():              mode_group.add_argument(mode_arg, **mode_arg_dict)            force_group = run_parser.add_mutually_exclusive_group()          for force_arg, force_arg_dict in cls.__FORCE_ARGS.items():              force_group.add_argument(force_arg, **force_arg_dict)        @classmethod      def parse_arguments(cls):          args = _CLI._parse()          as_dict = {}          if args.taipy_development:              as_dict[CoreSection._MODE_KEY] = CoreSection._DEVELOPMENT_MODE          elif args.taipy_experiment is not None:              as_dict[CoreSection._MODE_KEY] = CoreSection._EXPERIMENT_MODE              as_dict[CoreSection._VERSION_NUMBER_KEY] = args.taipy_experiment          elif args.taipy_production is not None:              as_dict[CoreSection._MODE_KEY] = CoreSection._PRODUCTION_MODE              as_dict[CoreSection._VERSION_NUMBER_KEY] = args.taipy_production            if args.taipy_force:              as_dict[CoreSection._FORCE_KEY] = True          elif args.no_taipy_force:              as_dict[CoreSection._FORCE_KEY] = False            return as_dict        @classmethod      def __add_taipy_prefix(cls, key: str):          if key.startswith("--no-"):              return key[:5] + "taipy-" + key[5:]            return key[:2] + "taipy-" + key[2:]


import json  import re  from datetime import datetime, timedelta      class _Decoder(json.JSONDecoder):      def __init__(self, *args, **kwargs):          json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs)        def _str_to_timedelta(self, timedelta_str: str) -> timedelta:          """          Parse a time string e.g. (2h13m) into a timedelta object.            :param timedelta_str: A string identifying a duration.  (eg. 2h13m)          :return datetime.timedelta: A datetime.timedelta object          """          regex = re.compile(              r"^((?P<days>[\.\d]+?)d)? *"              r"((?P<hours>[\.\d]+?)h)? *"              r"((?P<minutes>[\.\d]+?)m)? *"              r"((?P<seconds>[\.\d]+?)s)?$"          )          parts = regex.match(timedelta_str)          if not parts:              raise TypeError("Can not deserialize string into timedelta")          time_params = {name: float(param) for name, param in parts.groupdict().items() if param}          # mypy has an issue with dynamic keyword parameters, hence the type ignore on the line bellow.          return timedelta(**time_params)  # type: ignore        def object_hook(self, source):          if source.get("__type__") == "Datetime":              return datetime.fromisoformat(source.get("__value__"))          if source.get("__type__") == "Timedelta":              return self._str_to_timedelta(source.get("__value__"))          else:              return source      def loads(d):      return json.loads(d, cls=_Decoder)


import pathlib  from abc import abstractmethod  from typing import Any, Dict, Generic, Iterable, List, Optional, TypeVar, Union    ModelType = TypeVar("ModelType")  Entity = TypeVar("Entity")      class _AbstractRepository(Generic[ModelType, Entity]):      @abstractmethod      def _save(self, entity: Entity):          """          Save an entity in the repository.            Parameters:              entity: The data from an object.          """          raise NotImplementedError        @abstractmethod      def _exists(self, entity_id: str) -> bool:          """          Check if an entity with id entity_id exists in the repository.          Parameters:              entity_id: The entity id, i.e., its primary key.            Returns:              True if the entity id exists.          """          raise NotImplementedError        @abstractmethod      def _load(self, entity_id: str) -> Entity:          """          Retrieve the entity data from the repository.          Parameters:              entity_id: The entity id, i.e., its primary key.            Returns:              An entity.          """          raise NotImplementedError        @abstractmethod      def _load_all(self, filters: Optional[List[Dict]] = None) -> List[Entity]:          """          Retrieve all the entities' data from the repository taking any passed filter into account.            Returns:              A list of entities.          """          raise NotImplementedError        @abstractmethod      def _delete(self, entity_id: str):          """          Delete an entity in the repository.            Parameters:              entity_id: The id of the entity to be deleted.          """          raise NotImplementedError        @abstractmethod      def _delete_all(self):          """          Delete all entities from the repository.          """          raise NotImplementedError        @abstractmethod      def _delete_many(self, ids: Iterable[str]):          """          Delete all entities from the list of ids from the repository.            Parameters:              ids: List of ids to be deleted.          """          raise NotImplementedError        @abstractmethod      def _delete_by(self, attribute: str, value: str):          """          Delete all entities from the list of ids from the repository.            Parameters:              attribute: The entity property that is the key to the search.              value: The value of the attribute that are being searched.          """          raise NotImplementedError        @abstractmethod      def _search(self, attribute: str, value: Any, filters: Optional[List[Dict]] = None) -> List[Entity]:          """          Parameters:              attribute: The entity property that is the key to the search.              value: The value of the attribute that are being searched.            Returns:              A list of entities that match the search criteria.          """          raise NotImplementedError        @abstractmethod      def _export(self, entity_id: str, folder_path: Union[str, pathlib.Path]):          """          Export an entity from the repository.            Parameters:              entity_id (str): The id of the entity to be exported.              folder_path (Union[str, pathlib.Path]): The folder path to export the entity to.          """          raise NotImplementedError


import json  from datetime import datetime, timedelta  from enum import Enum  from typing import Any      class _Encoder(json.JSONEncoder):      def _timedelta_to_str(self, obj: timedelta) -> str:          total_seconds = obj.total_seconds()          return (              f"{int(total_seconds // 86400)}d"              f"{int(total_seconds % 86400 // 3600)}h"              f"{int(total_seconds % 3600 // 60)}m"              f"{int(total_seconds % 60)}s"          )        def default(self, o: Any):          if isinstance(o, Enum):              result = o.value          elif isinstance(o, datetime):              result = {"__type__": "Datetime", "__value__": o.isoformat()}          elif isinstance(o, timedelta):              result = {"__type__": "Timedelta", "__value__": self._timedelta_to_str(o)}          else:              result = json.JSONEncoder.default(self, o)          return result      def dumps(d):      return json.dumps(d, cls=_Encoder)


from abc import ABC, abstractmethod      class _AbstractConverter(ABC):      @classmethod      @abstractmethod      def _entity_to_model(cls, entity):          raise NotImplementedError        @classmethod      @abstractmethod      def _model_to_entity(cls, model):          raise NotImplementedError


import dataclasses  import enum  import json  from typing import Any, Dict    from sqlalchemy import Table    from ._decoder import _Decoder  from ._encoder import _Encoder      class _BaseModel:      __table__: Table        def __iter__(self):          for attr, value in self.__dict__.items():              yield attr, value        def to_dict(self) -> Dict[str, Any]:          model_dict = {**dataclasses.asdict(self)}            for k, v in model_dict.items():              if isinstance(v, enum.Enum):                  model_dict[k] = repr(v)          return model_dict        @staticmethod      def _serialize_attribute(value):          return json.dumps(value, ensure_ascii=False, cls=_Encoder)        @staticmethod      def _deserialize_attribute(value):          if isinstance(value, str):              return json.loads(value.replace("'", '"'), cls=_Decoder)          return value        @staticmethod      def from_dict(data: Dict[str, Any]):          pass        def to_list(self):          pass


import sqlite3  from functools import lru_cache  from sqlite3 import Connection    from sqlalchemy.dialects import sqlite  from sqlalchemy.schema import CreateTable    from taipy.config.config import Config    from ...exceptions import MissingRequiredProperty      def dict_factory(cursor, row):      d = {}      for idx, col in enumerate(cursor.description):          d[col[0]] = row[idx]      return d      class _SQLConnection:      _connection = None        @classmethod      def init_db(cls):          if cls._connection:              return cls._connection            cls._connection = _build_connection()          cls._connection.row_factory = dict_factory            from ..._version._version_model import _VersionModel          from ...cycle._cycle_model import _CycleModel          from ...data._data_model import _DataNodeModel          from ...job._job_model import _JobModel          from ...scenario._scenario_model import _ScenarioModel          from ...submission._submission_model import _SubmissionModel          from ...task._task_model import _TaskModel            cls._connection.execute(              str(CreateTable(_CycleModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_DataNodeModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_JobModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_ScenarioModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_TaskModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_VersionModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )          cls._connection.execute(              str(CreateTable(_SubmissionModel.__table__, if_not_exists=True).compile(dialect=sqlite.dialect()))          )            return cls._connection      def _build_connection() -> Connection:      # Set SQLite threading mode to Serialized, means that threads may share the module, connections and cursors      sqlite3.threadsafety = 3        properties = Config.core.repository_properties      try:          db_location = properties["db_location"]      except KeyError:          raise MissingRequiredProperty("Missing property db_location.")        return __build_connection(db_location)      @lru_cache  def __build_connection(db_location: str):      return sqlite3.connect(db_location, check_same_thread=False)


#  # 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 sqlalchemy.orm import declarative_base, registry    _SQLBaseModel = declarative_base()  mapper_registry = registry()


import os    from taipy.config import Config    __BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME = "TAIPY_BACKUP_FILE_PATH"      def _init_backup_file_with_storage_folder():      if preserve_file_path := os.getenv(__BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME):          with open(preserve_file_path, "a") as f:              f.write(f"{Config.core.storage_folder}\n")      def _append_to_backup_file(new_file_path: str):      if preserve_file_path := os.getenv(__BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME):          storage_folder = os.path.abspath(Config.core.storage_folder) + os.sep          if not os.path.abspath(new_file_path).startswith(storage_folder):              with open(preserve_file_path, "a") as f:                  f.write(f"{new_file_path}\n")      def _remove_from_backup_file(to_remove_file_path: str):      if preserve_file_path := os.getenv(__BACKUP_FILE_PATH_ENVIRONMENT_VARIABLE_NAME, None):          storage_folder = os.path.abspath(Config.core.storage_folder) + os.sep          if not os.path.abspath(to_remove_file_path).startswith(storage_folder):              try:                  with open(preserve_file_path, "r+") as f:                      old_backup = f.read()                      to_remove_file_path = to_remove_file_path + "\n"                        # To avoid removing the file path of different data nodes that are pointing                      # to the same file. We will only replace the file path only once.                      if old_backup.startswith(to_remove_file_path):                          new_backup = old_backup.replace(to_remove_file_path, "", 1)                      else:                          new_backup = old_backup.replace("\n" + to_remove_file_path, "\n", 1)                        if new_backup is not old_backup:                          f.seek(0)                          f.write(new_backup)                          f.truncate()              except Exception:                  pass      def _replace_in_backup_file(old_file_path: str, new_file_path: str):      _remove_from_backup_file(old_file_path)      _append_to_backup_file(new_file_path)


from taipy.config import _inject_section  from taipy.config.checker._checker import _Checker  from taipy.config.common.frequency import Frequency  # type: ignore  from taipy.config.common.scope import Scope  # type: ignore  from taipy.config.config import Config  # type: ignore  from taipy.config.global_app.global_app_config import GlobalAppConfig  # type: ignore    from .checkers._config_id_checker import _ConfigIdChecker  from .checkers._core_section_checker import _CoreSectionChecker  from .checkers._data_node_config_checker import _DataNodeConfigChecker  from .checkers._job_config_checker import _JobConfigChecker  from .checkers._scenario_config_checker import _ScenarioConfigChecker  from .checkers._task_config_checker import _TaskConfigChecker  from .core_section import CoreSection  from .data_node_config import DataNodeConfig  from .job_config import JobConfig  from .migration_config import MigrationConfig  from .scenario_config import ScenarioConfig  from .task_config import TaskConfig    _inject_section(      JobConfig,      "job_config",      JobConfig.default_config(),      [("configure_job_executions", JobConfig._configure)],      add_to_unconflicted_sections=True,  )  _inject_section(      DataNodeConfig,      "data_nodes",      DataNodeConfig.default_config(),      [          ("configure_data_node", DataNodeConfig._configure),          ("configure_data_node_from", DataNodeConfig._configure_from),          ("set_default_data_node_configuration", DataNodeConfig._set_default_configuration),          ("configure_csv_data_node", DataNodeConfig._configure_csv),          ("configure_json_data_node", DataNodeConfig._configure_json),          ("configure_parquet_data_node", DataNodeConfig._configure_parquet),          ("configure_sql_table_data_node", DataNodeConfig._configure_sql_table),          ("configure_sql_data_node", DataNodeConfig._configure_sql),          ("configure_mongo_collection_data_node", DataNodeConfig._configure_mongo_collection),          ("configure_in_memory_data_node", DataNodeConfig._configure_in_memory),          ("configure_pickle_data_node", DataNodeConfig._configure_pickle),          ("configure_excel_data_node", DataNodeConfig._configure_excel),          ("configure_generic_data_node", DataNodeConfig._configure_generic),      ],  )  _inject_section(      TaskConfig,      "tasks",      TaskConfig.default_config(),      [          ("configure_task", TaskConfig._configure),          ("set_default_task_configuration", TaskConfig._set_default_configuration),      ],  )  _inject_section(      ScenarioConfig,      "scenarios",      ScenarioConfig.default_config(),      [          ("configure_scenario", ScenarioConfig._configure),          ("set_default_scenario_configuration", ScenarioConfig._set_default_configuration),      ],  )  _inject_section(      MigrationConfig,      "migration_functions",      MigrationConfig.default_config(),      [("add_migration_function", MigrationConfig._add_migration_function)],      add_to_unconflicted_sections=True,  )  _inject_section(      CoreSection,      "core",      CoreSection.default_config(),      [("configure_core", CoreSection._configure)],      add_to_unconflicted_sections=True,  )    _Checker.add_checker(_ConfigIdChecker)  _Checker.add_checker(_CoreSectionChecker)  _Checker.add_checker(_DataNodeConfigChecker)  _Checker.add_checker(_JobConfigChecker)  # We don't need to add _MigrationConfigChecker because it is run only when the Core service is run.  _Checker.add_checker(_TaskConfigChecker)  _Checker.add_checker(_ScenarioConfigChecker)


import collections.abc  from copy import deepcopy  from typing import Any, Callable, Dict, Optional, Union    from taipy.config._config import _Config  from taipy.config.common._template_handler import _TemplateHandler as _tpl  from taipy.config.config import Config  from taipy.config.section import Section  from taipy.config.unique_section import UniqueSection      class MigrationConfig(UniqueSection):      """      Configuration fields needed to register migration functions from an old version to newer one.        Attributes:          migration_fcts (Dict[str, Dict[str, Callable]]): A dictionary that maps the version that entities are              migrated from to the migration functions.          **properties (dict[str, Any]): A dictionary of additional properties.      """        name = "VERSION_MIGRATION"        _MIGRATION_FCTS_KEY = "migration_fcts"        def __init__(          self,          migration_fcts: Dict[str, Dict[str, Callable]],          **properties,      ):          self.migration_fcts = migration_fcts            super().__init__(**properties)        def __copy__(self):          return MigrationConfig(              deepcopy(self.migration_fcts),              **deepcopy(self._properties),          )        def _clean(self):          self.migration_fcts.clear()          self._properties.clear()        def __getattr__(self, item: str) -> Optional[Any]:          return _tpl._replace_templates(self._properties.get(item))  # type: ignore        @classmethod      def default_config(cls):          return MigrationConfig({})        def _to_dict(self):          return {              self._MIGRATION_FCTS_KEY: self.migration_fcts,              **self._properties,          }        @classmethod      def _from_dict(cls, as_dict: Dict[str, Any], id: str, config: Optional[_Config]):          return MigrationConfig(**as_dict)        def _update(self, as_dict, default_section=None):          def deep_update(d, u):              for k, v in u.items():                  if isinstance(v, collections.abc.Mapping):                      d[k] = deep_update(d.get(k, {}), v)                  else:                      d[k] = v              return d            migration_fcts = as_dict.pop(self._MIGRATION_FCTS_KEY)          deep_update(self.migration_fcts, migration_fcts)            self._properties.update(as_dict)        @staticmethod      def _add_migration_function(          target_version: str,          config: Union[Section, str],          migration_fct: Callable,          **properties,      ):          """Add a migration function for a Configuration to migrate entities to the target version.            Parameters:              target_version (str): The production version that entities are migrated to.              config (Union[Section, str]): The configuration or the `id` of the config that needs to migrate.              migration_fct (Callable): Migration function that takes an entity as input and returns a new entity                  that is compatible with the target production version.              **properties (Dict[str, Any]): A keyworded variable length list of additional arguments.          Returns:              `MigrationConfig^`: The Migration configuration.          """          config_id = config if isinstance(config, str) else config.id          migration_fcts = {target_version: {config_id: migration_fct}}            section = MigrationConfig(              migration_fcts,              **properties,          )          Config._register(section)          return Config.unique_sections[MigrationConfig.name]