URL: https://github.com/freeipa/freeipa/pull/671
Author: tiran
 Title: #671: Slim down dependencies
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/671/head:pr671
git checkout pr671
From b12cb1e72769d43cbe09a77ec79b9b1267e5004c Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 29 Mar 2017 11:20:21 +0200
Subject: [PATCH] Slim down dependencies

* Remove unused install requires
* Correct dependencies for yubico otptoken
* Properly report optional dependency for yubico otptoken
* Make jinja2 an optional dependency and csrgen an optional plugin
* Add explicit dependency on cffi for csrgen
* Python 2 uses python-ldap, Python 3 pyldap

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipaclient/plugins/csrgen.py           | 10 ++++++++--
 ipaclient/plugins/otptoken_yubikey.py | 11 ++++++++---
 ipaclient/setup.py                    |  6 ++----
 ipapython/setup.py                    |  6 ++----
 ipaserver/setup.py                    |  3 ++-
 ipasetup.py.in                        | 15 +++++++++++----
 ipatests/setup.py                     |  3 ++-
 7 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/ipaclient/plugins/csrgen.py b/ipaclient/plugins/csrgen.py
index 568a79f..d18a90c 100644
--- a/ipaclient/plugins/csrgen.py
+++ b/ipaclient/plugins/csrgen.py
@@ -6,8 +6,6 @@
 
 import six
 
-from ipaclient import csrgen
-from ipaclient import csrgen_ffi
 from ipalib import api
 from ipalib import errors
 from ipalib import output
@@ -18,6 +16,14 @@
 from ipalib.text import _
 from ipapython import dogtag
 
+try:
+    import jinja2  # pylint: disable=unused-import
+except ImportError:
+    raise errors.SkipPluginModule(reason=_("jinja2 is not installed."))
+else:
+    from ipaclient import csrgen
+    from ipaclient import csrgen_ffi
+
 if six.PY3:
     unicode = str
 
diff --git a/ipaclient/plugins/otptoken_yubikey.py b/ipaclient/plugins/otptoken_yubikey.py
index 759b722..9993ec8 100644
--- a/ipaclient/plugins/otptoken_yubikey.py
+++ b/ipaclient/plugins/otptoken_yubikey.py
@@ -20,15 +20,20 @@
 import os
 
 import six
-import usb.core
-import yubico
 
 from ipalib import _, api, IntEnum
-from ipalib.errors import NotFound
+from ipalib.errors import NotFound, SkipPluginModule
 from ipalib.frontend import Command, Method, Object
 from ipalib.plugable import Registry
 from ipalib.util import classproperty
 
+try:
+    import usb.core
+    import yubico
+except ImportError:
+    # python-yubico depends on pyusb
+    raise SkipPluginModule(reason=_("python-yubico is not installed."))
+
 if six.PY3:
     unicode = str
 
diff --git a/ipaclient/setup.py b/ipaclient/setup.py
index f5be7ea..43e1164 100644
--- a/ipaclient/setup.py
+++ b/ipaclient/setup.py
@@ -54,15 +54,13 @@
             "cryptography",
             "ipalib",
             "ipapython",
-            "jinja2",
-            "python-yubico",
-            "pyusb",
             "qrcode",
             "six",
         ],
         extras_require={
             "install": ["ipaplatform"],
-            "otptoken_yubikey": ["yubico", "usb"]
+            "otptoken_yubikey": ["python-yubico", "pyusb"],
+            "csrgen": ["cffi", "jinja2"],
         },
         zip_safe=False,
     )
diff --git a/ipapython/setup.py b/ipapython/setup.py
index f4bc3f8..4f71530 100755
--- a/ipapython/setup.py
+++ b/ipapython/setup.py
@@ -41,16 +41,14 @@
             "cryptography",
             "dnspython",
             "gssapi",
-            "jwcrypto",
             # "ipalib",  # circular dependency
-            "pyldap",
             "netaddr",
             "netifaces",
-            "requests",
             "six",
         ],
         extras_require={
-            ":python_version<'3'": ["enum34"],
+            ":python_version<'3'": ["enum34", "python-ldap"],
+            ":python_version>='3'": ["pyldap"],
             "install": ["dbus-python"],  # for certmonger
         },
     )
diff --git a/ipaserver/setup.py b/ipaserver/setup.py
index 097508f..307e7a8 100755
--- a/ipaserver/setup.py
+++ b/ipaserver/setup.py
@@ -58,7 +58,6 @@
             "lxml",
             "netaddr",
             "pyasn1",
-            "pyldap",
             "six",
         ],
         entry_points={
@@ -70,6 +69,8 @@
             ],
         },
         extras_require={
+            ":python_version<'3'": ["python-ldap"],
+            ":python_version>='3'": ["pyldap"],
             # These packages are currently not available on PyPI.
             "dcerpc": ["samba", "pysss", "pysss_nss_idmap"],
             "hbactest": ["pyhbac"],
diff --git a/ipasetup.py.in b/ipasetup.py.in
index b0a5051..4bdd890 100644
--- a/ipasetup.py.in
+++ b/ipasetup.py.in
@@ -138,13 +138,20 @@ def ipasetup(name, doc, **kwargs):
     cmdclass = setup_kwargs.setdefault('cmdclass', {})
     cmdclass['build_py'] = build_py
 
-    # Env markers like ":python_version<'3.3'" are not supported by
+    # Env markers like ":python_version<'3'" are not supported by
     # setuptools < 18.0.
     if 'extras_require' in setup_kwargs and SETUPTOOLS_VERSION < (18, 0, 0):
         for k in list(setup_kwargs['extras_require']):
-            if k.startswith(':'):
-                req = setup_kwargs.setdefault('install_requires', [])
-                req.extend(setup_kwargs['extras_require'].pop(k))
+            if not k.startswith(':'):
+                continue
+            values = setup_kwargs['extras_require'].pop(k)
+            req = setup_kwargs.setdefault('install_requires', [])
+            if k == ":python_version<'3'" and sys.version_info.major == 2:
+                req.extend(values)
+            elif k == ":python_version>='3'" and sys.version_info.major >= 3:
+                req.extend(values)
+            else:
+                raise ValueError(k, values)
 
     os.chdir(local_path)
     try:
diff --git a/ipatests/setup.py b/ipatests/setup.py
index 4c02c79..00b9334 100644
--- a/ipatests/setup.py
+++ b/ipatests/setup.py
@@ -68,12 +68,13 @@
             "ipapython",
             "nose",
             "polib",
-            "pyldap",
             "pytest",
             "pytest_multihost",
             "six",
         ],
         extras_require={
+            ":python_version<'3'": ["python-ldap"],
+            ":python_version>='3'": ["pyldap"],
             "integration": ["dbus-python", "pyyaml", "ipaserver"],
             "ipaserver": ["ipaserver"],
             "webui": ["selenium", "pyyaml", "ipaserver"],
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to