network
dev_tool.tools.network
log = logging.getLogger(__name__)
module-attribute
derive_port
A function that derives a stable port from a project name.
The port is the project name's SHA-256 digest folded into the window that starts at the base port, so every project lands on a port of its own and lands on the same one on every machine and every run.
Parameters:
-
name(str) –The project name the port is derived from.
-
base(int) –The first port of the window.
-
span(int) –The number of ports in the window.
Returns:
-
int–The derived port number.
Source code in dev_tool/tools/network.py
get_local_ip
A function that gets the local IP address of the machine.
On Linux/WSL, returns '0.0.0.0' to allow external access.
Returns:
-
str–The local IP address, or '127.0.0.1' if it cannot be determined.
Source code in dev_tool/tools/network.py
is_port_ready
A function that waits for a port to accept connections.
Parameters:
-
host(str) –The host address to check.
-
port(int) –The port number to check.
-
timeout(float, default:30.0) –The maximum time to wait in seconds.
Returns:
-
bool–True if the port is ready, False if the timeout was reached.