From f7a7b725ef633b4802382e86143406e43954d506 Mon Sep 17 00:00:00 2001 From: Alice Grosch Date: Fri, 2 Jun 2023 13:13:33 +0200 Subject: [PATCH] Allow use of function via custom_port variable --- backendspawner/backendspawner.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backendspawner/backendspawner.py b/backendspawner/backendspawner.py index 814e682..9313149 100644 --- a/backendspawner/backendspawner.py +++ b/backendspawner/backendspawner.py @@ -92,13 +92,26 @@ def get_request_kwargs(self): request_kwargs = self.request_kwargs return request_kwargs - port = Union( + custom_port = Union( [Integer(), Callable()], default_value=8080, help=""" """, ).tag(config=True) + port = Integer( + help=""" + The port for single-user servers to listen on. + """, + ) + + @default('port') + def get_port(self): + port = self.custom_port + if callable(port): + port = port() + return port + async def get_port(self): if callable(self.port): port = await maybe_future(self.port(self))