URL: https://github.com/freeipa/freeipa/pull/1285 Author: tiran Title: #1285: [Backport][ipa-4-6] Remove ignore_import_errors Action: opened
PR body: """ This PR was opened automatically because PR #1258 was pushed to master and backport to ipa-4-6 is required. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1285/head:pr1285 git checkout pr1285
From c7bcd59c3ce65371925062842a87ff3d092f4778 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> --- Makefile.am | 5 +-- ignore_import_errors.py | 87 ------------------------------------------------- makeaci | 2 -- makeapi | 2 -- 4 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 ignore_import_errors.py diff --git a/Makefile.am b/Makefile.am index 02e53f550c..90a4875a1b 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 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