How to use the birdseye.utils.read_source_file function in birdseye

To help you get started, we’ve selected a few birdseye 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 alexmojaki / executing / tests / samples / bird.py View on Github external
filename = None
        while context >= 0:
            frame = frame.f_back
            filename = inspect.getsourcefile(frame)
            if filename is not None:
                context -= 1
        filename = os.path.abspath(filename)

        if frame.f_globals.get('__name__') != '__main__':
            if PY3 and self._treetrace_hidden_with_stmt.__name__ not in frame.f_globals:
                raise RuntimeError(
                    'To trace an imported module, you must import birdseye before '
                    'importing that module.')
            return

        lines = read_source_file(filename).splitlines()
        lines[:frame.f_lineno] = [''] * frame.f_lineno
        source = '\n'.join(lines)
        self.exec_string(source, filename, frame.f_globals, frame.f_locals, deep)
        sys.exit(0)
github alexmojaki / birdseye / tests / test_utils.py View on Github external
def read():
            return read_source_file(filename).strip()
github alexmojaki / executing / tests / samples / tracer.py View on Github external
pass

        if is_lambda(func):
            raise ValueError('You cannot trace lambdas')

        filename = inspect.getsourcefile(func)  # type: str

        if is_ipython_cell(filename):
            # noinspection PyPackageRequirements
            from IPython import get_ipython
            import linecache

            flags = get_ipython().compile.flags
            source = ''.join(linecache.cache[filename][2])
        else:
            source = read_source_file(filename)
            flags = 0

        # We compile the entire file instead of just the function source
        # because it can contain context which affects the function code,
        # e.g. enclosing functions and classes or __future__ imports
        traced_file = self.compile(source, filename, flags)

        if func.__dict__:
            raise ValueError('The birdseye decorator must be applied first, '
                             'at the bottom of the list.')

        # Then we have to recursively search through the newly compiled
        # code to find the code we actually want corresponding to this function
        code_options = []  # type: List[CodeType]

        def find_code(root_code):
github alexmojaki / birdseye / birdseye / bird.py View on Github external
filename = None
        while context >= 0:
            frame = frame.f_back
            filename = inspect.getsourcefile(frame)
            if filename is not None:
                context -= 1
        filename = os.path.abspath(filename)

        if frame.f_globals.get('__name__') != '__main__':
            if PY3 and self._treetrace_hidden_with_stmt.__name__ not in frame.f_globals:
                raise RuntimeError(
                    'To trace an imported module, you must import birdseye before '
                    'importing that module.')
            return

        lines = read_source_file(filename).splitlines()
        lines[:frame.f_lineno] = [''] * frame.f_lineno
        source = '\n'.join(lines)
        self.exec_string(source, filename, frame.f_globals, frame.f_locals, deep)
        sys.exit(0)
github alexmojaki / birdseye / birdseye / tracer.py View on Github external
pass

        if is_lambda(func):
            raise ValueError('You cannot trace lambdas')

        filename = inspect.getsourcefile(func)  # type: str

        if is_ipython_cell(filename):
            # noinspection PyPackageRequirements
            from IPython import get_ipython
            import linecache

            flags = get_ipython().compile.flags
            source = ''.join(linecache.cache[filename][2])
        else:
            source = read_source_file(filename)
            flags = 0

        # We compile the entire file instead of just the function source
        # because it can contain context which affects the function code,
        # e.g. enclosing functions and classes or __future__ imports
        traced_file = self.compile(source, filename, flags)

        if func.__dict__:
            raise ValueError('The birdseye decorator must be applied first, '
                             'at the bottom of the list.')

        # Then we have to recursively search through the newly compiled
        # code to find the code we actually want corresponding to this function
        code_options = []  # type: List[CodeType]

        def find_code(root_code):