Generator that performs the actual scanning of files.

    Yeilds a tuple containing import type, import path, and an extra file
    that should be scanned. Extra file scans should be the file or directory
    that relates to the import name.
774746
def _scan_file(filename, sentinel, source_type='import'):
    '''
    '''
    filename = os.path.abspath(filename)
    real_filename = os.path.realpath(filename)

    if os.path.getsize(filename) <= max_file_size:
        if real_filename not in sentinel and os.path.isfile(filename):
            sentinel.add(real_filename)

            basename = os.path.basename(filename)
            scope, imports = ast_scan_file(filename)

            if scope is not None and imports is not None:
                for imp in imports:
                    yield (source_type, imp.module, None)

                if 'INSTALLED_APPS' in scope and basename == 'settings.py':
                    log.info('Found Django settings: %s', filename)
                    for item in django.handle_django_settings(filename):
                        yield item
            else:
                log.warn('Could not scan imports from: %s', filename)
    else:
        log.warn('File size too large: %s', filename)
1034722
function scanForOptimization (context)
{
  var module, verboseOut = context.grunt.log.verbose;

  // Track repeated files to determine which modules can be optimized.

  Object.keys (context.modules).forEach (function (name)
  {
    if (context.modules.hasOwnProperty (name)) {
      module = context.modules[name];
      if (!module.external)
        module.filePaths ().forEach (function (path)
        {
          if (!context.filesRefCount[path])
            context.filesRefCount[path] = 1;
          else {
            verboseOut.writeln (util.csprintf ('white',
              'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.', name));
            ++context.filesRefCount[path];
            module.optimize = false;
          }
        });
    }
  });

  // Determine which modules can act as containers for non-optimized sections of code.

  scan (context.options.mainModule, true);

  /**
   * Search for unoptimizable modules.
   * @param {string} moduleName
   * @param {boolean?} first=false Is this the root module?
   * @returns {boolean} `true` if the module is not optimizable.
   */
  function scan (moduleName, first)
  {
    var module = context.modules[moduleName];
    if (!module)
      throw new Error (sprintf ("Module '%' was not found.", moduleName));
    // Ignore the module if it's external.
    if (module.external)
      return false;
    if (!module.optimize) {
      if (first)
        module.nonOptimizedContainer = true;
      disableOptimizationsForChildrenOf (module);
      return true;
    }
    for (var i = 0, m = module.requires.length, any = false; i < m; ++i)
      if (scan (module.requires[i])) //Note: scan() still must be called for ALL submodules!
        any = true;
    if (any)
      module.nonOptimizedContainer = true;
    return false;
  }

  function disableOptimizationsForChildrenOf (module)
  {
    if (module.external)
      return;
    for (var i = 0, m = module.requires.length; i < m; ++i) {
      var sub = context.modules[module.requires[i]];
      if (sub.external)
        continue;
      if (sub.optimize)
        verboseOut.writeln (util.csprintf ('white', "Also disabling optimizations for <cyan>%</cyan>.", sub.name.cyan));
      sub.optimize = false;
      disableOptimizationsForChildrenOf (sub);
    }
  }
}
1080952
def GetFileEntryByPath(self, path):
    
    if path is None:
      return None

    file_entry_type, _ = self._paths.get(path, (None, None))
    if not file_entry_type:
      return None

    path_spec = fake_path_spec.FakePathSpec(location=path)
    return fake_file_entry.FakeFileEntry(
        self._resolver_context, self, path_spec,
        file_entry_type=file_entry_type)
1367011
def __scanPlugins(self):
        
        self.logger.info("Initialization Plugins Start, local plugins path: %s, third party plugins: %s" % (self.plugins_abspath, self.plugin_packages))

        #: Load third-party plugins
        if self.plugin_packages and isinstance(self.plugin_packages, (list, tuple)):
            for package_name in self.plugin_packages:
                try:
                    plugin = __import__(package_name)
                except ImportError as e:
                    raise PluginError("ImportError for %s, detail is %s" %(package_name, e))
                else:
                    plugin_abspath = os.path.dirname(os.path.abspath(plugin.__file__))
                    self.__loadPlugin(plugin, plugin_abspath, package_name)

        #: Load local plug-in directory
        if os.path.isdir(self.plugins_abspath) and os.path.isfile(os.path.join(self.plugins_abspath, "__init__.py")):
            for package_name in os.listdir(self.plugins_abspath):
                package_abspath = os.path.join(self.plugins_abspath, package_name)
                if os.path.isdir(package_abspath) and os.path.isfile(os.path.join(package_abspath, "__init__.py")):
                    self.logger.info("find plugin package: %s" % package_name)
                    #: Dynamic load module (plugins.package): you can query custom information and get the plugin's class definition through getPluginClass
                    plugin = __import__("{0}.{1}".format(self.plugins_folder, package_name), fromlist=[self.plugins_folder, ])
                    self.__loadPlugin(plugin, package_abspath, package_name)
218432
def scan_django_settings(values, imports):
    '''
    '''
    if isinstance(values, (str, bytes)):
        if utils.is_import_str(values):
            imports.add(values)
    elif isinstance(values, dict):
        for k, v in values.items():
            scan_django_settings(k, imports)
            scan_django_settings(v, imports)
    elif hasattr(values, '__file__') and getattr(values, '__file__'):
        imp, _ = utils.import_path_from_file(getattr(values, '__file__'))
        imports.add(imp)
    elif hasattr(values, '__iter__'):
        for item in values:
            scan_django_settings(item, imports)
83549
def _scan(self, trigger=True):
        
        changed = False
        files_seen = set()
        os_path_join = os.path.join
        for path in self.paths:
            for root, dirs, files in os.walk(path):
                for f in files:
                    fpath = os_path_join(root, f)
                    if not self.is_valid_type(fpath):
                        continue
                    files_seen.add(fpath)
                    if self._requires_new_modtime(fpath):
                        self._watch_file(fpath, trigger)
                        changed = True
            for f in self._watched_files:
                if f not in files_seen:
                    self._unwatch_file(f, trigger)
                    changed = True
        return changed
411677
def find_imports_and_track_names(filename, warn_about_duplicates=False,
                                 verbose=False):
    
    with open(filename) as f:
        root = ast.parse(f.read(), filename)
    visitor = ImportFinderAndNameTracker(filename)
    visitor.warn_about_duplicates = warn_about_duplicates
    visitor.verbose = verbose
    visitor.visit(root)
    visitor.leaveAllScopes()
    return visitor.imports, visitor.unused_names
412752
def get_files(files, extnames=['.root']):
    """"""

    files_out = []
    for f in files:

        mime = mimetypes.guess_type(f)
        if os.path.splitext(f)[1] in extnames:
            files_out += [f]
        elif mime[0] == 'text/plain':
            files_out += list(np.loadtxt(f, unpack=True, dtype='str'))
        else:
            raise Exception('Unrecognized input type.')

    return files_out
1086944
def scantypes(cls, value, value_type, visitor):
        

        item_type_generator = None
        if issubclass(value_type, Collection):

            def get_item_types():
                if isinstance(value_type.itemtype, tuple):
                    # not actually supported by Collection yet, but whatever
                    for vt in value_type.itemtype:
                        yield (vt, vt)
                else:
                    yield value_type.itemtype, value_type.itemtype

            item_type_generator = get_item_types()

        propget = None
        if issubclass(value_type, Record):
            def propget(prop):
                return prop

        return propget, item_type_generator
1220846
def find_files(dir_path, extension="*"):
    
    if sys.version_info.major == 3 and sys.version_info.minor >= 5:
        pattern = '/'.join([dir_path, '**', extension])
        for filename in glob.iglob(pattern, recursive=True):
            yield filename
    else:
        for root, dirnames, filenames in os.walk(dir_path):
            for filename in fnmatch.filter(filenames, extension):
                yield os.path.join(root, filename)
927104
def imports():
    
    from .core.import_hooks import ExtensionImporter
    importer = ExtensionImporter()
    sys.meta_path.append(importer)
    yield
    sys.meta_path.remove(importer)
989444
def CheckDirectory(self, path, extension='yaml'):
    
    result = True

    if extension:
      glob_spec = os.path.join(path, '*.{0:s}'.format(extension))
    else:
      glob_spec = os.path.join(path, '*')

    for definition_file in sorted(glob.glob(glob_spec)):
      if not self.CheckFile(definition_file):
        result = False

    return result
471263
def get_extra_files():
    
    FILES_TO_SKIP = ["src/gdbgui.js"]
    THIS_DIR = os.path.dirname(os.path.abspath(__file__))
    extra_dirs = [THIS_DIR]
    extra_files = []
    for extra_dir in extra_dirs:
        for dirname, _, files in os.walk(extra_dir):
            for filename in files:
                filepath = os.path.join(dirname, filename)
                if os.path.isfile(filepath) and filepath not in extra_files:
                    for skipfile in FILES_TO_SKIP:
                        if skipfile not in filepath:
                            extra_files.append(filepath)
    return extra_files
624223
@Override
    public List<File> scan() {

        File baseDirFile = new File(baseDir);

        List<File> includedFiles = walkDirectory(baseDirFile);
        return includedFiles;
    }
586661
def _find_input_files(var, out):
    
    if isinstance(var, (list, tuple)):
        for x in var:
            out = _find_input_files(x, out)
    elif isinstance(var, dict):
        if var.get("class") == "File":
            out.append(var["path"])
            out = _find_input_files(var.get("secondaryFiles", []), out)
        for key, val in var.items():
            out = _find_input_files(val, out)
    return out
734206
def get_files(path:PathOrStr, extensions:Collection[str]=None, recurse:bool=False,
              include:Optional[Collection[str]]=None)->FilePathList:
    ""
    if recurse:
        res = []
        for i,(p,d,f) in enumerate(os.walk(path)):
            # skip hidden dirs
            if include is not None and i==0:  d[:] = [o for o in d if o in include]
            else:                             d[:] = [o for o in d if not o.startswith('.')]
            res += _get_files(path, p, f, extensions)
        return res
    else:
        f = [o.name for o in os.scandir(path) if o.is_file()]
        return _get_files(path, path, f, extensions)
1272491
def load_file_or_directory(path):
    
    assert os.path.exists(path), "{0} does not exist!".format(path)
    absolute_path = os.path.abspath(path)
    if not os.path.isdir(path):
        yield absolute_path
    else:
        for root, dirs, file_paths in os.walk(path):
            for file_path in file_paths:
                yield os.path.join(root, file_path)