From 134412d274c7f7ff4f8ba02d653cfbeb88770b43 Mon Sep 17 00:00:00 2001 From: Eduardo Davalos Anaya <40870026+edavalosanaya@users.noreply.github.com> Date: Sat, 5 Aug 2023 12:37:56 -0500 Subject: [PATCH] fix(ifaddr): Replaced netifaces with ifaddr to make the engine easier to install. (#224) --- chimerapy/engine/utils.py | 26 +++++++++++++------------- pyproject.toml | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/chimerapy/engine/utils.py b/chimerapy/engine/utils.py index a6431bd5..2cc37eca 100644 --- a/chimerapy/engine/utils.py +++ b/chimerapy/engine/utils.py @@ -12,7 +12,7 @@ # Third-party from tqdm import tqdm -import netifaces as ni +import ifaddr # Internal from chimerapy.engine import _logger @@ -146,19 +146,19 @@ def get_open_port(start_port: int) -> socket.socket: def get_ip_address() -> str: - # Get gateway of the network - gws = ni.gateways() - try: - default_gw_name = gws["default"][ni.AF_INET][1] - # Get the ip in the default gateway - ip = ni.ifaddresses(default_gw_name)[ni.AF_INET][0]["addr"] - except KeyError: - logger.warning( - "ChimeraPy-Engine: Couldn't find connected network, using 127.0.0.1" - ) - ip = "127.0.0.1" + # Get all the network adapters + adapters = ifaddr.get_adapters() + + # Iterate through the adapters to find a suitable IP + for adapter in adapters: + for ip in adapter.ips: + # Check if it's an IPv4 address and not the local address + if isinstance(ip.ip, str) and ip.ip != "127.0.0.1": + return ip.ip - return ip + # Return the local address if no suitable IP is found + logger.warning("ChimeraPy-Engine: Couldn't find connected network, using 127.0.0.1") + return "127.0.0.1" def create_payload( diff --git a/pyproject.toml b/pyproject.toml index a18e93c9..0810a0a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "chimerapy-engine" version = "0.1.0" -description = "ChimeraPy-Engine: The Cluster Networking Engine for the ChimeraPy framework" +description = "ChimeraPy-Engine: The Cluster Networking Engine for the ChimeraPy Framework" authors = [ {name = "Eduardo Davalos", email="eduardo.davalos.anaya@vanderbilt.edu"}, {name = "Umesh Timalsina", email="umesh.timalsina@vanderbilt.edu"} @@ -19,7 +19,7 @@ classifiers = [ dependencies = [ 'networkx', 'dill', - 'netifaces', + 'ifaddr', 'matplotlib', 'multiprocess', 'opencv-python', @@ -81,9 +81,9 @@ examples = [ ] [project.urls] -homepath = "https://github.com/ChimeraPy/ChimeraPy-Engine" +homepath = "https://github.com/ChimeraPy" documentation = "https://chimerapy-engine.readthedocs.io/en/latest/index.html" -repository = "https://github.com/ChimeraPy/ChimeraPy-Engine" +repository = "https://github.com/ChimeraPy/Engine" # Entrypoint [project.scripts]