From 9c3d9f3055c748c4199a157ffc6f897f5930f270 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Nov 22 2017 16:05:55 +0000 Subject: 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 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 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 Reviewed-By: Alexander Bokovoy Reviewed-By: Alexander Bokovoy --- diff --git a/Makefile.am b/Makefile.am index f74252a..758b30a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,16 +14,13 @@ SUBDIRS = asn1 util client contrib po pypi \ $(IPACLIENT_SUBDIRS) ipaplatform $(IPATESTS_SUBDIRS) $(SERVER_SUBDIRS) MOSTLYCLEANFILES = ipasetup.pyc ipasetup.pyo \ - ignore_import_errors.pyc ignore_import_errors.pyo \ - ipasetup.pyc ipasetup.pyo \ pylint_plugins.pyc pylint_plugins.pyo # user-facing scripts dist_bin_SCRIPTS = ipa # files required for build but not installed -dist_noinst_SCRIPTS = ignore_import_errors.py \ - makeapi \ +dist_noinst_SCRIPTS = makeapi \ makeaci \ make-doc \ make-test \ diff --git a/ignore_import_errors.py b/ignore_import_errors.py deleted file mode 100644 index 4ee6ee9..0000000 --- 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 ''.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 98b199c..6673112 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 d0a7295..1168498 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