Better than excluding everything that is not needed,
    collect only what is needed.
328427
def find_packages_by_root_package(where):
    
    root_package = os.path.basename(where)
    packages = [ "%s.%s" % (root_package, sub_package)
                 for sub_package in find_packages(where)]
    packages.insert(0, root_package)
    return packages
626161
function sweep() {

    # remove used values
    foreach (array_keys($this->flash) as $k) {
      if ($this->used[$k]) {
        unset($this->flash[$k], $this->used[$k]);
      } else {
        $this->_use($k);
      }
    }

    # cleanup if someone meddled with flash or used
    $fkeys = array_keys($this->flash);
    $ukeys = array_keys($this->used);
    foreach (array_diff($fkeys, $ukeys) as $k => $v) {
      unset($this->used[$k]);
    }
  }
1107247
def cleanup(self):
        """"""
        keys = self.client.smembers(self.keys_container)
        for key in keys:
            entry = self.client.get(key)
            if entry:
                entry = pickle.loads(entry)
                if self._is_expired(entry, self.timeout):
                    self.delete_entry(key)
949564
private void cleanup() {
		CacheEntry oldest = null;
		_count = 0;

		// Cleanup obsolete entries and find the oldest
		for (Map.Entry<String, CacheEntry> e : _cache.entrySet()) {
			String key = e.getKey();
			CacheEntry entry = e.getValue();
			// Remove obsolete entry
			if (entry.isExpired()) {
				_cache.remove(key);
			}
			// Count the remaining entry
			else {
				_count++;
				if (oldest == null || oldest.getExpiration() > entry.getExpiration())
					oldest = entry;
			}
		}

		// Remove the oldest if cache size exceeded maximum
		if (_count > _maxSize && oldest != null) {
			_cache.remove(oldest.getKey());
			_count--;
		}
	}
544353
def collect(self):
        """"""
        for func in self._caches:
            cache = {}
            for key in self._caches[func]:
                if (time.time() - self._caches[func][key][1]) < self._timeouts[func]:
                    cache[key] = self._caches[func][key]
            self._caches[func] = cache
643177
private void collectRequiredAddons(AddonInfo addonInfo, List<AddonInfo> addons)
   {
      // Move this addon to the top of the list
      addons.remove(addonInfo);
      addons.add(0, addonInfo);
      for (AddonId addonId : addonInfo.getRequiredAddons())
      {
         if (!addons.contains(addonId) && (!isDeployed(addonId) || !isEnabled(addonId)))
         {
            AddonInfo childInfo = info(addonId);
            collectRequiredAddons(childInfo, addons);
         }
      }
   }
651654
function collect() {
		$inc_failed = count($this->_failed['inc']);
		$dec_failed = count($this->_failed['dec']);
		$n_saved    = count($this->_saved);
		$n_inc      = count($this->_increased);
		$n_dec      = count($this->_decreased);
		$n_fetched  = count($this->_fetched);
		$n_deleted  = count($this->_deleted);
		$data = array(
			'count'       =>0,
			'messages'    =>array(),
		);
		if ( $inc_failed+$dec_failed>0 ) {
			$data['messages'][] =  array(
				'message'  => "Caches Failed: [ Inc:{$inc_failed} , Dec:{$dec_failed} ]",
				'is_string'=> true,
				'label'    => 'Caches Summary'
			);
		}
		$message = "Caches Count: [ Saved:{$n_saved} ; Gets:{$n_fetched}";
		if ( $this->_nulls>0 ) {
			$message .= "(nulls:{$this->_nulls})";
		}
		if ( $n_inc>0 ) {
			$message .= " ; Inc:{$n_inc}";
		}
		if ( $n_dec>0 ) {
			$message .= " ; Dec:{$n_dec}";
		}
		if ( $n_deleted>0 ) {
			$message .= " ; Deleted:{$n_deleted}";
		}
		if ( $this->_flushed ) {
			$message .= " ; Has Flushed";
		}
		$data['messages'][] = array(
			'message'  => $message.' ]',
			'is_string'=> true,
			'label'    => 'Caches Summary'
		);

		if ( !$this->_mode && $this->_messagesCollector ) {
			foreach ( $data['messages'] as $value ) {
				$this->_messagesCollector->addMessage($value['message'],$value['label'],$value['is_string']);
			}
			return array();
		}

		$messages = array();
		foreach ( $this->_saved as $key=>$value ) {
			$lifetime = '';
			if ( $value['lifetime']!==null ) {
				$lifetime = "Lifetime=>"."{$value['lifetime']}";
			}
			$content    = $value['content'];
			if ( !is_string( $content ) ) {
				$content = $this->formatVars($content);
				$message= "Saved: [ Key=>\"$key\"  $lifetime  Value=> $content[0] ]";
			}else{
				$message= "Saved: [ Key=>\"$key\"  $lifetime  Value=> \"$content\" ]";
			}
			$messages[] = array(
				'message'   => $message,
				'is_string' => mb_strlen($message)>100?false:true,
				'label'     => 'Saved',
				'time'      =>$value['time'],
			);
		}
		foreach ( $this->_fetched as $key=>$value ) {
			$content = $value['value'];
			if ( !is_string( $value ) ) {
				$content = $this->formatVars($content);
				$message= "Gets: [ Key=>\"$key\"   Value=> $content[0] ]";
			}else{
				$message= "Gets: [ Key=>\"$key\"   Value=> \"$content\" ]";
			}
			$messages[] = array(
				'message'   => $message,
				'is_string' => mb_strlen($message)>100?false:true,
				'label'     => 'Gets',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_deleted as $value ) {
			$messages[] = array(
				'message'   => 'DeletedKey: [ '.$value['key'].' ]',
				'is_string' => true,
				'label'     => 'Deleted',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_increased as $value ) {
			$messages[] = array(
				'message'   => "Increased: [ Key:{$value['key']} , Step:{$value['step']} , NewValue:{$value['new_value']}] ",
				'is_string' => true,
				'label'     => 'Increased',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_decreased as $value ) {
			$messages[] = array(
				'message'   => "Decreased: [ Key:{$value['key']} , Step:{$value['step']} , NewValue:{$value['new_value']}] ",
				'is_string' => true,
				'label'     => 'Decreased',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_failed['inc'] as $value ) {
			$messages[] = array(
				'message'   => "IncFailed: [ Key:{$value['key']} , Step:{$value['step']}] ",
				'is_string' => true,
				'label'     => 'IncFailed',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_failed['dec'] as $value ) {
			$messages[] = array(
				'message'   => "DecFailed: [ Key:{$value['key']} , Step:{$value['step']}] ",
				'is_string' => true,
				'label'     => 'DecFailed',
				'time'      => $value['time'],
			);
		}
		$data['messages'] = array_merge($data['messages'],  $this->sort($messages));
		$data['count'] = count($messages);
		return $data;
	}
94948
def _collect_all_files(self, files=None):
        
        if files is None:
            files = self._root_elements
        collected = set()
        for entry in files:
            collected.add(entry)
            collected.update(self._collect_all_files(entry.children))
        return collected
1062578
def purge_needs(app, env, docname):
    
    if not hasattr(env, 'needs_all_needs'):
        return
    env.needs_all_needs = {key: need for key, need in env.needs_all_needs.items() if need['docname'] != docname}
91060
def collect(options = {}, &block)
      collector = AnswersCollector.new(self, options)
      collector.call(&block)
    end
923564
function collect(p, files, matches) {
  if (!files) files = []

  matches = matches || function (p) {
    return p.match(/\.js$/)
  }

  if (fs.statSync(p).isDirectory()) {
    fs.readdirSync(p).forEach(function (item) {
      collect(path.join(p, item), files, matches)
    })
  } else if (matches(p)) {
    files.push(p)
  }

  return files
}
270104
function collectHolidays() {
      if (typeof self.year.holidays[self.m] !== 'undefined' && typeof self.year.holidays[self.m] !== 'undefined') {
        self.year.holidays[self.m].forEach(function(holiday) {
          if (holidays.length < count && holiday.day >= self.d) {
            holidays.push(holiday);
          }
        });
      }
    }
420815
protected void cleanUp() {
        int prevNodeCount = ghStorage.getNodes();
        PrepareRoutingSubnetworks preparation = new PrepareRoutingSubnetworks(ghStorage, encodingManager.fetchEdgeEncoders());
        preparation.setMinNetworkSize(minNetworkSize);
        preparation.setMinOneWayNetworkSize(minOneWayNetworkSize);
        preparation.doWork();
        int currNodeCount = ghStorage.getNodes();
        logger.info("edges: " + Helper.nf(ghStorage.getAllEdges().length()) + ", nodes " + Helper.nf(currNodeCount)
                + ", there were " + Helper.nf(preparation.getMaxSubnetworks())
                + " subnetworks. removed them => " + Helper.nf(prevNodeCount - currNodeCount)
                + " less nodes");
    }
868535
public void cleanup() {
    keys.cleanup();
    counts.cleanup();
    dictionary.cleanup();
    // Decrement the dictionary memory by the total size of all the elements
    memoryEstimate.decrementDictionaryMemory(SizeOf.SIZE_OF_LONG * numElements);
  }
40952
def collect_related(self, finder_funcs, obj, count, *args, **kwargs):
        
        collected = []
        for func in finder_funcs:
            gathered = func(obj, count, collected, *args, **kwargs)
            if gathered:
                collected += gathered
            if len(collected) >= count:
                return collected[:count]

        return collected
321839
def get_provides(self, ignored=tuple()):
        

        if self._provides is None:
            self._collect_requires_provides()

        d = self._provides
        if ignored:
            d = dict((k, v) for k, v in d.items()
                     if not fnmatches(k, *ignored))
        return d
1212182
def cleanup_storage(*args):
    """"""
    ShardedClusters().cleanup()
    ReplicaSets().cleanup()
    Servers().cleanup()
    sys.exit(0)