How to use the cppimport.importer.imp function in cppimport

To help you get started, we’ve selected a few cppimport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tbenthompson / cppimport / cppimport / import_hook.py View on Github external
def find_module(self, fullname, path = None):
        # Prevent re-entry by the underlying importer
        if self._running:
            return

        try:
            self._running = True
            cppimport.importer.imp(fullname, opt_in = True)
        except ImportError as e:
            # ImportError should be quashed because that simply means cppimport
            # didn't find anything, and probably shouldn't have found anything!
            if self.print_exceptions:
                import traceback
                print(traceback.format_exc())
        finally:
            self._running = False