|
@@ -9,25 +9,37 @@
|
|
|
# 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 sys
|
|
|
import typing as t
|
|
|
|
|
|
+from flask import Flask
|
|
|
+
|
|
|
from taipy.gui import Gui
|
|
|
from taipy.rest import Rest
|
|
|
from taipy.core import Core
|
|
|
|
|
|
+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(*apps: t.List[t.Union[Gui, Rest, Core]], **kwargs) -> t.Optional[t.Union[Gui, Rest, Core]]:
|
|
|
+def _run(*apps: t.List[_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:
|
|
|
- *args (List[Union[`Gui^`, `Rest^`, `Core^`]]): Services to run. If several services are provided, all the services run simultaneously. If this is empty or set to None, this method does nothing.
|
|
|
+ *args (Union[`Gui^`, `Rest^`, `Core^`]): Services to run, as separate arguments.<br/>
|
|
|
+ If several services are provided, all the services run simultaneously.<br/>
|
|
|
+ If this is empty or set to None, this method does nothing.
|
|
|
**kwargs: Other parameters to provide to the services.
|
|
|
"""
|
|
|
- gui = __typing_get(apps, Gui)
|
|
|
- rest = __typing_get(apps, Rest)
|
|
|
- core = __typing_get(apps, Core)
|
|
|
+
|
|
|
+ gui = __get_app(apps, Gui)
|
|
|
+ rest = __get_app(apps, Rest)
|
|
|
+ core = __get_app(apps, Core)
|
|
|
|
|
|
if gui and core:
|
|
|
from taipy.core._version._version_cli import _VersioningCLI
|
|
@@ -49,8 +61,16 @@ def _run(*apps: t.List[t.Union[Gui, Rest, Core]], **kwargs) -> t.Optional[t.Unio
|
|
|
return gui.run(**kwargs)
|
|
|
else:
|
|
|
app = rest or gui
|
|
|
+ assert app is not None # Avoid pyright typing error
|
|
|
return app.run(**kwargs)
|
|
|
|
|
|
|
|
|
-def __typing_get(l, type_):
|
|
|
- return next(filter(lambda o: isinstance(o, type_), l), None)
|
|
|
+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)
|