def incfile(fname, fpointer, lrange="<STR_LIT>", sdir=None):
<EOL>file_dir = (<EOL>sdir<EOL>if sdir<EOL>else os.environ.get("<STR_LIT>", os.path.abspath(os.path.dirname(__file__)))<EOL>)<EOL>fname = os.path.join(file_dir, fname)<EOL>with open(fname) as fobj:<EOL><INDENT>lines = fobj.readlines()<EOL><DEDENT>tokens = [item.strip() for item in lrange.split("<STR_LIT:U+002C>")]<EOL>inc_lines = []<EOL>for token in tokens:<EOL><INDENT>if "<STR_LIT:->" in token:<EOL><INDENT>subtokens = token.split("<STR_LIT:->")<EOL>lmin, lmax = (<EOL>int(subtokens[<NUM_LIT:0>]),<EOL>int(subtokens[<NUM_LIT:1>]) if subtokens[<NUM_LIT:1>] else len(lines),<EOL>)<EOL>for num in range(lmin, lmax + <NUM_LIT:1>):<EOL><INDENT>inc_lines.append(num)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>inc_lines.append(int(token))<EOL><DEDENT><DEDENT>fpointer("<STR_LIT>")<EOL>fpointer("<STR_LIT:\n>")<EOL>for num, line in enumerate(lines):<EOL><INDENT>if num + <NUM_LIT:1> in inc_lines:<EOL><INDENT>fpointer("<STR_LIT:U+0020>" + line.replace("<STR_LIT:\t>", "<STR_LIT:U+0020>") if line.strip() else "<STR_LIT:\n>")<EOL><DEDENT><DEDENT>fpointer("<STR_LIT:\n>")<EOL>
r"""
    Include a Python source file in a docstring formatted in reStructuredText.

    :param fname: File name, relative to environment variable
                  :bash:`${TRACER_DIR}`
    :type  fname: string

    :param fpointer: Output function pointer. Normally is :code:`cog.out` but
                     :code:`print` or other functions can be used for
                     debugging
    :type  fpointer: function object

    :param lrange: Line range to include, similar to Sphinx
                   `literalinclude <http://sphinx-doc.org/markup/code.html
                   #directive-literalinclude>`_ directive
    :type  lrange: string

    :param sdir: Source file directory. If None the :bash:`${TRACER_DIR}`
                 environment variable is used if it is defined, otherwise
                 the directory where the :code:`docs.support.incfile` module
                 is located is used
    :type  sdir: string

    For example:

    .. code-block:: python

        def func():
            \"\"\"
            This is a docstring. This file shows how to use it:

            .. =[=cog
            .. import docs.support.incfile
            .. docs.support.incfile.incfile('func_example.py', cog.out)
            .. =]=
            .. code-block:: python

                # func_example.py
                if __name__ == '__main__':
                    func()

            .. =[=end=]=
            \"\"\"
            return 'This is func output'