Просмотр исходного кода

Merge branch 'develop' into fix/coverage-action

João André 1 год назад
Родитель
Сommit
dfcb533e39

+ 5 - 5
taipy/core/_entity/_labeled.py

@@ -52,20 +52,20 @@ class _Labeled:
         return self.__LABEL_SEPARATOR.join(ls)
 
     def _get_explicit_label(self) -> Optional[str]:
-        return self._properties.get("label") if hasattr(self, "_properties") else None
+        return getattr(self, "_properties").get("label") if hasattr(self, "_properties") else None  # noqa: B009
 
     def _get_owner_id(self) -> Optional[str]:
-        return self.owner_id if hasattr(self, "owner_id") else None
+        return getattr(self, "owner_id") if hasattr(self, "owner_id") else None  # noqa: B009
 
     def _get_name(self) -> Optional[str]:
         if hasattr(self, "name"):
-            return self.name
+            return getattr(self, "name")  # noqa: B009
         if hasattr(self, "_properties"):
-            return self._properties.get("name")
+            return getattr(self, "_properties").get("name")  # noqa: B009
         return None
 
     def _get_config_id(self) -> Optional[str]:
-        return self.config_id if hasattr(self, "config_id") else None
+        return getattr(self, "config_id") if hasattr(self, "config_id") else None  # noqa: B009
 
     def _generate_entity_label(self) -> str:
         if name := self._get_name():

+ 1 - 1
taipy/core/_orchestrator/_orchestrator.py

@@ -77,7 +77,7 @@ class _Orchestrator(_AbstractOrchestrator):
             getattr(submittable, "config_id", None),
             **properties,
         )
-        jobs = []
+        jobs: List[Job] = []
         tasks = submittable._get_sorted_tasks()
         with cls.lock:
             for ts in tasks:

+ 24 - 3
taipy/gui/_renderers/utils.py

@@ -11,6 +11,8 @@
 
 import typing as t
 
+import pandas as pd
+
 from .._warnings import _warn
 from ..types import NumberTypes
 from ..utils import _RE_PD_TYPE, _get_date_col_str_name, _MapDict
@@ -31,14 +33,33 @@ def _get_columns_dict_from_list(
 ):
     col_dict = {}
     idx = 0
+    cols = None
+
     for col in col_list:
         if col in col_types_keys:
             col_dict[col] = {"index": idx}
             idx += 1
         elif col:
-            _warn(
-                f'Error column "{col}" is not present in the Dataframe "{value.head(0) if hasattr(value, "head") else value}".'  # noqa: E501
-            )
+            if cols is None:
+                cols = (
+                    list(value.columns)
+                    if isinstance(value, pd.DataFrame)
+                    else list(value.keys())
+                    if isinstance(value, (dict, _MapDict))
+                    else value
+                    if isinstance(value, (list, tuple))
+                    else []
+                )
+
+            if cols and (col not in cols):
+                _warn(
+                    f'Column "{col}" is not present. Available columns: {cols}.'  # noqa: E501
+                )
+            else:
+                _warn(
+                    "The 'data' property value is of an unsupported type."
+                    + " Only DataFrame, dict, list, or tuple are supported."
+                )
     return col_dict
 
 

+ 10 - 3
taipy/gui/config.py

@@ -133,7 +133,7 @@ Config = t.TypedDict(
         "use_reloader": bool,
         "watermark": t.Optional[str],
         "webapp_path": t.Optional[str],
-        "port": int,
+        "port": t.Union[t.Literal["auto"], int],
     },
     total=False,
 )
@@ -189,7 +189,9 @@ class _Config(object):
 
         config = self.config
         if args.taipy_port:
-            if not _Config.__RE_PORT_NUMBER.match(args.taipy_port):
+            if str(args.taipy_port).strip() == "auto":
+                config["port"] = "auto"
+            elif not _Config.__RE_PORT_NUMBER.match(args.taipy_port):
                 _warn("Port value for --port option is not valid.")
             else:
                 config["port"] = int(args.taipy_port)
@@ -226,6 +228,8 @@ class _Config(object):
                 try:
                     if isinstance(value, dict) and isinstance(config[key], dict):
                         config[key].update(value)
+                    elif key == "port" and str(value).strip() == "auto":
+                        config["port"] = "auto"
                     else:
                         config[key] = value if config[key] is None else type(config[key])(value)  # type: ignore
                 except Exception as e:
@@ -239,7 +243,10 @@ class _Config(object):
                 key = key.lower()
                 if value is not None and key in config:
                     try:
-                        config[key] = value if config[key] is None else type(config[key])(value)  # type: ignore
+                        if key == "port" and str(value).strip() == "auto":
+                            config["port"] = "auto"
+                        else:
+                            config[key] = value if config[key] is None else type(config[key])(value)  # type: ignore
                     except Exception as e:
                         _warn(
                             f"Invalid env value in Gui.run(): {key} - {value}. Unable to parse value to the correct type",  # noqa: E501

+ 3 - 1
taipy/gui/server.py

@@ -268,6 +268,8 @@ class _Server:
     def run(self, host, port, debug, use_reloader, flask_log, run_in_thread, allow_unsafe_werkzeug, notebook_proxy):
         host_value = host if host != "0.0.0.0" else "localhost"
         self._host = host
+        if port == "auto":
+            port = self._get_random_port()
         self._port = port
         if _is_in_notebook() and notebook_proxy:  # pragma: no cover
             from .utils.proxy import NotebookProxy
@@ -281,7 +283,7 @@ class _Server:
             runtime_manager.add_gui(self._gui, port)
         if debug and not is_running_from_reloader() and _is_port_open(host_value, port):
             raise ConnectionError(
-                f"Port {port} is already opened on {host_value}. You have another server application running on the same port."  # noqa: E501
+                "Port {port} is already opened on {host} because another application is running on the same port. Please pick another port number and rerun with the 'port=<new_port>' option. You can also let Taipy choose a port number for you by running with the 'port=\"auto\"' option."  # noqa: E501
             )
         if not flask_log:
             log = logging.getLogger("werkzeug")