fix for review

This commit is contained in:
Lendemor 2025-02-08 00:11:31 +01:00
parent a26962263d
commit d650dc8acb
2 changed files with 11 additions and 9 deletions

View File

@ -161,7 +161,7 @@ def _run(
# Find the next available open port if applicable. # Find the next available open port if applicable.
if frontend: if frontend:
autoswitch_frontend = not bool(frontend_port or config.frontend_port) auto_increment_frontend = not bool(frontend_port or config.frontend_port)
frontend_port = processes.handle_port( frontend_port = processes.handle_port(
"frontend", "frontend",
( (
@ -169,11 +169,11 @@ def _run(
or config.frontend_port or config.frontend_port
or constants.DefaultPorts.FRONTEND_PORT or constants.DefaultPorts.FRONTEND_PORT
), ),
autoswitch=autoswitch_frontend, auto_increment=auto_increment_frontend,
) )
if backend: if backend:
autoswitch_backend = not bool(backend_port or config.backend_port) auto_increment_backend = not bool(backend_port or config.backend_port)
backend_port = processes.handle_port( backend_port = processes.handle_port(
"backend", "backend",
@ -182,7 +182,7 @@ def _run(
or config.backend_port or config.backend_port
or constants.DefaultPorts.BACKEND_PORT or constants.DefaultPorts.BACKEND_PORT
), ),
autoswitch=autoswitch_backend, auto_increment=auto_increment_backend,
) )
# Apply the new ports to the config. # Apply the new ports to the config.

View File

@ -116,7 +116,7 @@ def change_port(port: int, _type: str) -> int:
return new_port return new_port
def handle_port(service_name: str, port: int, autoswitch: bool) -> int: def handle_port(service_name: str, port: int, auto_increment: bool) -> int:
"""Change port if the specified port is in use and is not explicitly specified as a CLI arg or config arg. """Change port if the specified port is in use and is not explicitly specified as a CLI arg or config arg.
otherwise tell the user the port is in use and exit the app. otherwise tell the user the port is in use and exit the app.
@ -126,7 +126,7 @@ def handle_port(service_name: str, port: int, autoswitch: bool) -> int:
Args: Args:
service_name: The frontend or backend. service_name: The frontend or backend.
port: The provided port. port: The provided port.
autoswitch: Whether to automatically switch the port. auto_increment: Whether to automatically switch the port.
Returns: Returns:
The port to run the service on. The port to run the service on.
@ -134,12 +134,14 @@ def handle_port(service_name: str, port: int, autoswitch: bool) -> int:
Raises: Raises:
Exit:when the port is in use. Exit:when the port is in use.
""" """
if not is_process_on_port(port): if (process := get_process_on_port(port)) is None:
return port return port
if autoswitch: if auto_increment:
return change_port(port, service_name) return change_port(port, service_name)
else: else:
console.error(f"{service_name.capitalize()} port: {port} is already in use") console.error(
f"{service_name.capitalize()} port: {port} is already in use by PID: {process.pid}."
)
raise typer.Exit() raise typer.Exit()