def scan_file(pym, filename, sentinel, installed):
    '''Entry point scan that creates a PyModule instance if needed.
    '''
    if not utils.is_python_script(filename):
        return

    if not pym:
        # This is for finding a previously created instance, not finding an
        # installed module with the same name. Might need to base the name
        # on the actual paths to reduce ambiguity in the printed scan results.
        module = os.path.basename(filename)
        pym = utils.find_package(module, installed)
        if not pym:
            pym = PyModule(module, 'SCRIPT', os.path.abspath(filename))
            installed.insert(0, pym)
        else:
            pym.is_scan = True

    for imp_type, import_path, extra_file_scan in _scan_file(filename, sentinel):
        dep = utils.find_package(import_path, installed)
        if dep:
            dep.add_dependant(pym)
            pym.add_dependency(dep)

            if imp_type != 'import':
                pym.add_framework(imp_type)

        if extra_file_scan:
            # extra_file_scan should be a directory or file containing the
            # import name
            scan_filename = utils.file_containing_import(import_path, extra_file_scan)
            log.info('Related scan: %s - %s', import_path, scan_filename)
            if scan_filename.endswith('__init__.py'):
                scan_directory(pym, os.path.dirname(scan_filename), sentinel, installed)
            else:
                scan_file(pym, scan_filename, sentinel, installed)

    return pym