

def scan_directory(pym, directory, sentinel, installed, depth=0):
    'Entry point scan that creates a PyModule instance if needed.\n    '
    if (not pym):
        d = os.path.abspath(directory)
        basename = os.path.basename(d)
        pym = utils.find_package(basename, directory)
        if (not pym):
            version = 'DIRECTORY'
            if os.path.isfile(os.path.join(d, '__init__.py')):
                version = 'MODULE'
            pym = PyModule(basename, version, d)
            installed.insert(0, pym)
        else:
            pym.is_scan = True
    bad_scans = 0
    for item in _scan_directory(directory, sentinel, depth):
        if os.path.isfile(item):
            if (bad_scans > 100):
                log.debug('Stopping scan of directory since it looks like a data dump: %s', directory)
                break
            if (not scan_file(pym, item, sentinel, installed)):
                bad_scans += 1
            else:
                bad_scans = 0
        elif os.path.isdir(item):
            scan_directory(pym, item, sentinel, installed, (depth + 1))
    return pym

dataset/ETHPy150Open tweekmonster/moult/moult/filesystem_scanner.py scan_directory/VarMisuse@60/91 `installed`->`directory`