URL: https://github.com/freeipa/freeipa/pull/1258
Author: tiran
 Title: #1258: Remove ignore_import_errors
Action: opened

PR body:
"""
ignore_import_errors was added in 9b534238 to build FreeIPA ACI/API with
some dependencies missing. It turns out that the import hook doesn't
play nice with other meta importers or Cython-generated code like lxml:

```
./makeaci: ipaserver/plugins/dogtag.py:246: ignoring ImportError: No module 
named lxml.re
Traceback (most recent call last):
  File "./makeaci", line 134, in <module>
    main(options)
  File "./makeaci", line 107, in main
    api.finalize()
  File "ipalib/plugable.py", line 733, in finalize
    self.__do_if_not_done('load_plugins')
  File "ipalib/plugable.py", line 425, in __do_if_not_done
    getattr(self, name)()
  File "ipalib/plugable.py", line 614, in load_plugins
    self.add_package(package)
  File "ipalib/plugable.py", line 641, in add_package
    module = importlib.import_module(name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "ipaserver/plugins/dogtag.py", line 246, in <module>
    from lxml import etree
  File "src/lxml/etree.pyx", line 93, in init lxml.etree
  File "src/lxml/_elementpath.py", line 58, in init lxml._elementpath
AttributeError: 'FailedImport' object has no attribute 'compile'
```

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/1258/head:pr1258
git checkout pr1258
From 730b64c7f7103b26ff7272e0f069e782f4865e1f Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 8 Nov 2017 16:07:16 +0100
Subject: [PATCH] Remove ignore_import_errors

ignore_import_errors was added in 9b534238 to build FreeIPA ACI/API with
some dependencies missing. It turns out that the import hook doesn't
play nice with other meta importers or Cython-generated code like lxml:

./makeaci: ipaserver/plugins/dogtag.py:246: ignoring ImportError: No module named lxml.re
Traceback (most recent call last):
  File "./makeaci", line 134, in <module>
    main(options)
  File "./makeaci", line 107, in main
    api.finalize()
  File "ipalib/plugable.py", line 733, in finalize
    self.__do_if_not_done('load_plugins')
  File "ipalib/plugable.py", line 425, in __do_if_not_done
    getattr(self, name)()
  File "ipalib/plugable.py", line 614, in load_plugins
    self.add_package(package)
  File "ipalib/plugable.py", line 641, in add_package
    module = importlib.import_module(name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "ipaserver/plugins/dogtag.py", line 246, in <module>
    from lxml import etree
  File "src/lxml/etree.pyx", line 93, in init lxml.etree
  File "src/lxml/_elementpath.py", line 58, in init lxml._elementpath
AttributeError: 'FailedImport' object has no attribute 'compile'

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ignore_import_errors.py | 87 -------------------------------------------------
 makeaci                 |  2 --
 makeapi                 |  2 --
 3 files changed, 91 deletions(-)
 delete mode 100644 ignore_import_errors.py

diff --git a/ignore_import_errors.py b/ignore_import_errors.py
deleted file mode 100644
index 4ee6ee98bc..0000000000
--- a/ignore_import_errors.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
-#
-
-"""
-ImportError ignoring import hook.
-"""
-
-from __future__ import print_function
-
-import imp
-import inspect
-import os.path
-import sys
-
-DIRNAME = os.path.dirname(os.path.abspath(__file__))
-
-
-class FailedImport(object):
-    def __init__(self, loader, name):
-        self.__file__ = __file__
-        self.__name__ = name
-        self.__path__ = []
-        self.__loader__ = loader
-        self.__package__ = name
-
-    def __repr__(self):
-        return '<failed import {!r}>'.format(self.__name__)
-
-
-class IgnoringImporter(object):
-    def find_module(self, fullname, path=None):
-        parentname, dot, name = fullname.rpartition('.')
-        assert (not dot and path is None) or (dot and path is not None)
-
-        # check if the module can be found
-        try:
-            file, _filename, _description = imp.find_module(name, path)
-        except ImportError:
-            pass
-        else:
-            if file is not None:
-                file.close()
-            # it can be found, do normal import
-            return None
-
-        # check if the parent module import failed
-        if dot and isinstance(sys.modules[parentname], FailedImport):
-            # it did fail, so this import will fail as well
-            return self
-
-        # find out from where are we importing
-        if path is None:
-            path = sys.path
-        for pathname in path:
-            pathname = os.path.abspath(pathname)
-            if not pathname.startswith(DIRNAME):
-                break
-        else:
-            # importing from our source tree, do normal import
-            return None
-
-        # find out into what .py file are we importing
-        frame = inspect.currentframe().f_back
-        filename = frame.f_code.co_filename
-        if filename.startswith('<'):
-            # not a file, do normal import
-            return None
-        filename = os.path.abspath(filename)
-        if not filename.startswith(DIRNAME):
-            # not a file in our source tree, do normal import
-            return None
-
-        return self
-
-    def load_module(self, fullname):
-        frame = inspect.currentframe().f_back
-        print("{}: {}:{}: ignoring ImportError: No module named {}".format(
-                sys.argv[0],
-                os.path.relpath(frame.f_code.co_filename),
-                frame.f_lineno,
-                fullname))
-
-        return sys.modules.setdefault(fullname, FailedImport(self, fullname))
-
-
-sys.meta_path.insert(0, IgnoringImporter())
diff --git a/makeaci b/makeaci
index 57622fe046..ff46f1ec09 100755
--- a/makeaci
+++ b/makeaci
@@ -30,8 +30,6 @@ import sys
 import difflib
 from argparse import ArgumentParser
 
-import ignore_import_errors     # pylint: disable=unused-import
-
 from ipalib import api
 from ipapython.dn import DN
 from ipapython.ipaldap import LDAPClient
diff --git a/makeapi b/makeapi
index 2b1d154672..05bd684a81 100755
--- a/makeapi
+++ b/makeapi
@@ -33,8 +33,6 @@ import re
 import inspect
 import operator
 
-import ignore_import_errors     # pylint: disable=unused-import
-
 from ipalib import api
 from ipalib.parameters import Param
 from ipalib.output import Output
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to