diff options
| author | Christian Heimes <cheimes@redhat.com> | 2019-04-07 20:55:15 +0200 |
|---|---|---|
| committer | Christian Heimes <cheimes@redhat.com> | 2019-04-09 11:28:37 +0200 |
| commit | a5213140c3abf67a341b04d6edaeea6e0e1de62e (patch) | |
| tree | 9af0d525540268f7166d816529a80263af56e3e9 /ipapython | |
| parent | 8a5dc1b375db94c4e722fa725f48eb16d032f1aa (diff) | |
| download | freeipa-a5213140c3abf67a341b04d6edaeea6e0e1de62e.tar.gz freeipa-a5213140c3abf67a341b04d6edaeea6e0e1de62e.tar.xz freeipa-a5213140c3abf67a341b04d6edaeea6e0e1de62e.zip | |
Make netifaces optional
netifaces is a binary Python extension. Outside of the installer, it's
only used by CheckedIPAddress.get_matching_interface, which is only
called from installer code.
Make the import of netifaces optional to reduce the amount of
dependencies for PyPI package use case. Binary extensions are especially
annoying, because they depend on shared libraries, compiler, and header
files to be present.
Related: https://pagure.io/freeipa/issue/6468
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Oleg Kozlov <okozlov@redhat.com>
Diffstat (limited to 'ipapython')
| -rw-r--r-- | ipapython/ipautil.py | 8 | ||||
| -rw-r--r-- | ipapython/setup.py | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 9da3f0790..106745354 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -34,7 +34,6 @@ import socket import re import datetime import netaddr -import netifaces import time import pwd import grp @@ -49,6 +48,11 @@ from dns.exception import DNSException import six from six.moves import input +try: + import netifaces +except ImportError: + netifaces = None + from ipapython.dn import DN logger = logging.getLogger(__name__) @@ -197,6 +201,8 @@ class CheckedIPAddress(UnsafeIPAddress): :return: InterfaceDetails named tuple or None if no interface has this address """ + if netifaces is None: + raise ImportError("netifaces") logger.debug("Searching for an interface of IP address: %s", self) if self.version == 4: family = netifaces.AF_INET diff --git a/ipapython/setup.py b/ipapython/setup.py index f7f4ade0f..8bba2fe4f 100644 --- a/ipapython/setup.py +++ b/ipapython/setup.py @@ -43,11 +43,12 @@ if __name__ == '__main__': # "ipalib", # circular dependency "ipaplatform", "netaddr", - "netifaces", "python-ldap", "six", ], extras_require={ "install": ["dbus-python"], # for certmonger + # CheckedIPAddress.get_matching_interface + "netifaces": ["netifaces"], }, ) |
