Пример #1
0
    def _early_rewrite_bailout(self, name, state):
        """
        This is a fast way to get out of rewriting modules. Profiling has
        shown that the call to imp.find_module (inside of the find_module
        from this class) is a major slowdown, so, this method tries to
        filter what we're sure won't be rewritten before getting to it.
        """
        if self.session is not None and not self._session_paths_checked:
            self._session_paths_checked = True
            for path in self.session._initialpaths:
                # Make something as c:/projects/my_project/path.py ->
                #     ['c:', 'projects', 'my_project', 'path.py']
                parts = str(path).split(os.path.sep)
                # add 'path' to basenames to be checked.
                self._basenames_to_check_rewrite.add(
                    os.path.splitext(parts[-1])[0])

        # Note: conftest already by default in _basenames_to_check_rewrite.
        parts = name.split(".")
        if parts[-1] in self._basenames_to_check_rewrite:
            return False

        # For matching the name it must be as if it was a filename.
        path = PurePath(os.path.sep.join(parts) + ".py")

        for pat in self.fnpats:
            # if the pattern contains subdirectories ("tests/**.py" for example) we can't bail out based
            # on the name alone because we need to match against the full path
            if os.path.dirname(pat):
                return False
            if fnmatch_ex(pat, path):
                return False

        if self._is_marked_for_rewrite(name, state):
            return False

        state.trace("early skip of rewriting module: %s" % (name, ))
        return True
Пример #2
0
 def match_(pattern, path):
     return fnmatch_ex(pattern, path)