Skip to content

Commit

Permalink
fix(ifaddr): Replaced netifaces with ifaddr to make the engine easier…
Browse files Browse the repository at this point in the history
… to install. (#224)
  • Loading branch information
edavalosanaya authored Aug 5, 2023
1 parent 4cb8382 commit 134412d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions chimerapy/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Third-party
from tqdm import tqdm
import netifaces as ni
import ifaddr

# Internal
from chimerapy.engine import _logger
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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="[email protected]"},
{name = "Umesh Timalsina", email="[email protected]"}
Expand All @@ -19,7 +19,7 @@ classifiers = [
dependencies = [
'networkx',
'dill',
'netifaces',
'ifaddr',
'matplotlib',
'multiprocess',
'opencv-python',
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 134412d

Please sign in to comment.