Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sso hooks #1854

Merged
merged 10 commits into from
Oct 1, 2024
2 changes: 1 addition & 1 deletion taipy/gui/_default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"change_delay": None,
"chart_dark_template": None,
"base_url": "/",
"client_url": "http://localhost:5000",
"client_url": "http://localhost:{port}",
"dark_mode": True,
"dark_theme": None,
"debug": False,
Expand Down
8 changes: 8 additions & 0 deletions taipy/gui/_gui_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class _GuiCLI(_AbstractCLI):
"const": "",
"help": "Specify server host",
},
("--client-url", "-H"): {
"dest": "taipy_client_url",
"metavar": "CLIENT_URL",
"nargs": "?",
"default": "",
"const": "",
"help": "Specify client url",
},
("--ngrok-token",): {
"dest": "taipy_ngrok_token",
"metavar": "NGROK_TOKEN",
Expand Down
2 changes: 2 additions & 0 deletions taipy/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def _handle_argparse(self):
config["upload_folder"] = args.taipy_upload_folder
elif os.environ.get("TAIPY_GUI_UPLOAD_FOLDER"):
config["webapp_path"] = os.environ.get("TAIPY_GUI_UPLOAD_FOLDER")
if args.taipy_client_url:
config["client_url"] = args.taipy_client_url

def _build_config(self, root_dir, env_filename, kwargs): # pragma: no cover
config = self.config
Expand Down
6 changes: 6 additions & 0 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,9 @@ def get_flask_app(self) -> Flask:
return t.cast(Flask, self._server.get_flask())
raise RuntimeError("get_flask_app() cannot be invoked before run() has been called.")

def _get_port(self) -> int:
return self._server.get_port()

def _set_frame(self, frame: t.Optional[FrameType]):
if not isinstance(frame, FrameType): # pragma: no cover
raise RuntimeError("frame must be a FrameType where Gui can collect the local variables.")
Expand Down Expand Up @@ -2624,6 +2627,8 @@ def __register_blueprint(self):
# server URL Rule for flask rendered react-router
pages_bp.add_url_rule(f"/{Gui.__INIT_URL}", view_func=self.__init_route)

_Hooks()._add_external_blueprint(self, __name__)
dinhlongviolin1 marked this conversation as resolved.
Show resolved Hide resolved

# Register Flask Blueprint if available
for bp in self._flask_blueprint:
t.cast(Flask, self._server.get_flask()).register_blueprint(bp)
Expand Down Expand Up @@ -2790,6 +2795,7 @@ def run(
return self._server.run(
host=app_config.get("host"),
port=app_config.get("port"),
client_url=app_config.get("client_url"),
debug=app_config.get("debug"),
use_reloader=app_config.get("use_reloader"),
flask_log=app_config.get("flask_log"),
Expand Down
8 changes: 7 additions & 1 deletion taipy/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def _direct_render_json(self, data):
def get_flask(self):
return self._flask

def get_port(self):
return self._port

def test_client(self):
return t.cast(Flask, self._flask).test_client()

Expand Down Expand Up @@ -286,6 +289,7 @@ def run(
self,
host,
port,
client_url,
debug,
use_reloader,
flask_log,
Expand All @@ -299,6 +303,7 @@ def run(
if port == "auto":
port = self._get_random_port(port_auto_ranges)
self._port = port
client_url = client_url.format(port=port)
if _is_in_notebook() and notebook_proxy: # pragma: no cover
from .utils.proxy import NotebookProxy

Expand All @@ -320,8 +325,9 @@ def run(
_TaipyLogger._get_logger().info(f" * Server starting on http://{host_value}:{port}")
else:
_TaipyLogger._get_logger().info(f" * Server reloaded on http://{host_value}:{port}")
_TaipyLogger._get_logger().info(f" * Application is accessible at {client_url}")
if not is_running_from_reloader() and self._gui._get_config("run_browser", False):
webbrowser.open(f"http://{host_value}{f':{port}' if port else ''}", new=2)
webbrowser.open(client_url, new=2)
if _is_in_notebook() or run_in_thread:
self._thread = KThread(target=self._run_notebook)
self._thread.start()
Expand Down
1 change: 1 addition & 0 deletions tests/gui/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def run_e2e_multi_client(gui: Gui):
gui._server.run(
host=gui._get_config("host", "127.0.0.1"),
port=gui._get_config("port", 5000),
client_url=gui._get_config("client_url", "http://localhost:{port}"),
debug=False,
use_reloader=False,
flask_log=False,
Expand Down
Loading