config: changes web_port loading

The web_port argument in the pydase.Server defaults to None now. If it
is None, the value from ServiceConfig().web_port will be used.
This fixes the issue where users might pass the web port dynamcially and
by passing None they want to use the default value.
This commit is contained in:
Mose Müller 2025-01-28 10:29:16 +01:00
parent c0016673a8
commit b0c8af0108

View File

@ -87,8 +87,10 @@ class Server:
service: The DataService instance that this server will manage. service: The DataService instance that this server will manage.
host: The host address for the server. Defaults to `'0.0.0.0'`, which means all host: The host address for the server. Defaults to `'0.0.0.0'`, which means all
available network interfaces. available network interfaces.
web_port: The port number for the web server. Defaults to web_port: The port number for the web server. If set to None, it will use the
[`ServiceConfig().web_port`][pydase.config.ServiceConfig.web_port]. port defined in
[`ServiceConfig().web_port`][pydase.config.ServiceConfig.web_port]. Defaults
to None.
enable_web: Whether to enable the web server. enable_web: Whether to enable the web server.
filename: Filename of the file managing the service state persistence. filename: Filename of the file managing the service state persistence.
additional_servers: A list of additional servers to run alongside the main additional_servers: A list of additional servers to run alongside the main
@ -140,7 +142,7 @@ class Server:
self, self,
service: DataService, service: DataService,
host: str = "0.0.0.0", host: str = "0.0.0.0",
web_port: int = ServiceConfig().web_port, web_port: int | None = None,
enable_web: bool = True, enable_web: bool = True,
filename: str | Path | None = None, filename: str | Path | None = None,
additional_servers: list[AdditionalServer] | None = None, additional_servers: list[AdditionalServer] | None = None,
@ -151,6 +153,9 @@ class Server:
additional_servers = [] additional_servers = []
self._service = service self._service = service
self._host = host self._host = host
if web_port is None:
self._web_port = ServiceConfig().web_port
else:
self._web_port = web_port self._web_port = web_port
self._enable_web = enable_web self._enable_web = enable_web
self._kwargs = kwargs self._kwargs = kwargs