URL: https://github.com/freeipa/freeipa/pull/1779 Author: tiran Title: #1779: Defer import of ipaclient.csrgen Action: opened
PR body: """ The modules ipaclient.csrgen and ipaclient.csrgen_ffi are expensive to load, but rarely used. On demand loading speeds up ipa CLI by about 200ms. Fixes: https://pagure.io/freeipa/issue/7484 Signed-off-by: Christian Heimes <chei...@redhat.com> """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1779/head:pr1779 git checkout pr1779
From 1904872080e5e9b071487ead8ebe61a508c95aa9 Mon Sep 17 00:00:00 2001 From: Christian Heimes <chei...@redhat.com> Date: Thu, 5 Apr 2018 08:35:15 +0200 Subject: [PATCH] Defer import of ipaclient.csrgen The modules ipaclient.csrgen and ipaclient.csrgen_ffi are expensive to load, but rarely used. On demand loading speeds up ipa CLI by about 200ms. Fixes: https://pagure.io/freeipa/issue/7484 Signed-off-by: Christian Heimes <chei...@redhat.com> --- ipaclient/plugins/cert.py | 5 ++++- ipaclient/plugins/csrgen.py | 12 +++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ipaclient/plugins/cert.py b/ipaclient/plugins/cert.py index 50549cf590..2e3833a97d 100644 --- a/ipaclient/plugins/cert.py +++ b/ipaclient/plugins/cert.py @@ -23,7 +23,6 @@ import six -from ipaclient import csrgen from ipaclient.frontend import MethodOverride from ipalib import errors from ipalib import x509 @@ -105,6 +104,10 @@ def get_args(self): yield arg def forward(self, csr=None, **options): + # Deferred import, because ipaclient.csrgen is expensive to load + # see https://pagure.io/freeipa/issue/7484 + from ipaclient import csrgen + database = options.pop('database', None) private_key = options.pop('private_key', None) csr_profile_id = options.pop('csr_profile_id', None) diff --git a/ipaclient/plugins/csrgen.py b/ipaclient/plugins/csrgen.py index 01c75f4bcc..3756bcabe6 100644 --- a/ipaclient/plugins/csrgen.py +++ b/ipaclient/plugins/csrgen.py @@ -16,13 +16,6 @@ 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 @@ -79,6 +72,11 @@ class cert_get_requestdata(Local): ) def execute(self, *args, **options): + # Deferred import, because ipaclient.csrgen is expensive to load + # see https://pagure.io/freeipa/issue/7484 + from ipaclient import csrgen + from ipaclient import csrgen_ffi + if 'out' in options: util.check_writable_file(options['out'])
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org