예제 #1
0
def begin(repfile=None,
          pattern=None,
          continuous=False,
          submodule_accesses=True):
    """Start collecting import and module access information

    repfile (default no file) is the destination for an
    end-of-run module import and access report. It can be either a file
    path or an open file object.

    pattern (default ['*']) is a list of modules on which to collect data. It
    is a list of one or more dotted full module names. An asterisk '*' is a
    wild card an matches everything. Examples:
      ['pygame']               Will on report on top level pygame package
      ['pygame', 'numpy']      Only top level pygame and numpy modules
      ['pygame', 'pygame.surface']
                               pygame and pygame.surface
      ['pygame', 'pygame.*']   pygame and all its submodules
      ['*']                    everything

    continous (default False) indicates whether per-module attribute access
    recording should stop with the first access or be continuous. Set False
    to stop after the first access, True for continuous recording.

    submodule_accesses (default True) indicates whether submodules imports
    are to be included as an access on the containing package.

    """
    global installed, collecting

    if not installed:
        sys.meta_path.insert(0, importer)
        installed = True
        if repfile is not None:
            atexit.register(write_report, repfile)
    try:
        if collecting:
            return
    except NameError:
        collecting = True
    if continuous:
        module.set_report_mode('continuous')
    importer.begin(pattern, submodule_accesses)
예제 #2
0
def begin(repfile=None,
          pattern=None,
          continuous=False,
          submodule_accesses=True):
    """Start collecting import and module access information

    repfile (default no file) is the destination for an
    end-of-run module import and access report. It can be either a file
    path or an open file object.

    pattern (default ['*']) is a list of modules on which to collect data. It
    is a list of one or more dotted full module names. An asterisk '*' is a
    wild card an matches everything. Examples:
      ['pygame']               Will on report on top level pygame package
      ['pygame', 'numpy']      Only top level pygame and numpy modules
      ['pygame', 'pygame.surface']
                               pygame and pygame.surface
      ['pygame', 'pygame.*']   pygame and all its submodules
      ['*']                    everything

    continous (default False) indicates whether per-module attribute access
    recording should stop with the first access or be continuous. Set False
    to stop after the first access, True for continuous recording.

    submodule_accesses (default True) indicates whether submodules imports
    are to be included as an access on the containing package.

    """
    global installed, collecting

    if not installed:
        sys.meta_path.insert(0, importer)
        installed = True
        if repfile is not None:
            atexit.register(write_report, repfile)
    try:
        if collecting:
            return
    except NameError:
        collecting = True
    if continuous:
        module.set_report_mode('continuous')
    importer.begin(pattern, submodule_accesses)
예제 #3
0
def end():
    global collecting
    collecting = False
    reporter.end()
    importer.end()
    module.set_report_mode('quit')
예제 #4
0
def end():
    global collecting
    collecting = False
    reporter.end()
    importer.end()
    module.set_report_mode('quit')