coalib.collecting package

Submodules

coalib.collecting.Collectors module

coalib.collecting.Collectors.collect_all_bears_from_sections(sections, log_printer=None)[source]

Collect all kinds of bears from bear directories given in the sections.

Parameters:
  • sections – List of sections so bear_dirs are taken into account
  • log_printer – Log_printer to handle logging
Returns:

Tuple of dictionaries of local and global bears. The dictionary key is section class and dictionary value is a list of Bear classes

coalib.collecting.Collectors.collect_bears(bear_dirs, bear_globs, kinds, log_printer=None, warn_if_unused_glob=True)[source]

Collect all bears from bear directories that have a matching kind matching the given globs.

Parameters:
  • bear_dirs – Directory name or list of such that can contain bears.
  • bear_globs – Globs of bears to collect.
  • kinds – List of bear kinds to be collected.
  • log_printer – log_printer to handle logging.
  • warn_if_unused_glob – True if warning message should be shown if a glob didn’t give any bears.
Returns:

Tuple of list of matching bear classes based on kind. The lists are in the same order as kinds.

coalib.collecting.Collectors.collect_bears_by_aspects(aspects, kinds)[source]

Collect bear based on aspects.

Return a list of bears that have capability to analyze all aspects from given AspectList requirement.

Parameters:
  • aspects – An AspectList that need to be covered.
  • kinds – List of bear kinds to be collected.
Returns:

Tuple of list of bear classes based on kind. The lists are in the same order as kinds.

coalib.collecting.Collectors.collect_dirs(dir_paths, ignored_dir_paths=None)[source]

Evaluate globs in directory paths and return all matching directories

Parameters:
  • dir_paths – File path or list of such that can include globs
  • ignored_dir_paths – List of globs that match to-be-ignored dirs
Returns:

List of paths of all matching directories

coalib.collecting.Collectors.collect_files(file_paths, log_printer=None, ignored_file_paths=None, limit_file_paths=None, section_name='')[source]

Evaluate globs in file paths and return all matching files

Parameters:
  • file_paths – File path or list of such that can include globs
  • ignored_file_paths – List of globs that match to-be-ignored files
  • limit_file_paths – List of globs that the files are limited to
  • section_name – Name of currently executing section
Returns:

List of paths of all matching files

coalib.collecting.Collectors.collect_registered_bears_dirs(entrypoint)[source]

Searches setuptools for the entrypoint and returns the bear directories given by the module.

Parameters:entrypoint – The entrypoint to find packages with.
Returns:List of bear directories.
coalib.collecting.Collectors.filter_capabilities_by_languages(bears, languages)[source]

Filters the bears capabilities by languages.

Parameters:
  • bears – Dictionary with sections as keys and list of bears as values.
  • languages – Languages that bears are being filtered on.
Returns:

New dictionary with languages as keys and their bears capabilities as values. The capabilities are stored in a tuple of two elements where the first one represents what the bears can detect, and the second one what they can fix.

coalib.collecting.Collectors.filter_section_bears_by_languages(bears, languages)[source]

Filters the bears by languages.

Parameters:
  • bears – The dictionary of the sections as keys and list of bears as values.
  • languages – Languages that bears are being filtered on.
Returns:

New dictionary with filtered out bears that don’t match any language from languages.

coalib.collecting.Collectors.get_all_bears()[source]

Get a list of all available bears.

coalib.collecting.Collectors.get_all_bears_names()[source]

Get a list of names of all available bears.

coalib.collecting.Collectors.icollect(file_paths, ignored_globs=None, match_cache={})[source]

Evaluate globs in file paths and return all matching files.

Parameters:
  • file_paths – File path or list of such that can include globs
  • ignored_globs – List of globs to ignore when matching files
  • match_cache – Dictionary to use for caching results
Returns:

Iterator that yields tuple of path of a matching file, the glob where it was found

coalib.collecting.Collectors.icollect_bears(bear_dir_glob, bear_globs, kinds, log_printer=None)[source]

Collect all bears from bear directories that have a matching kind.

Parameters:
  • bear_dir_glob – Directory globs or list of such that can contain bears
  • bear_globs – Globs of bears to collect
  • kinds – List of bear kinds to be collected
  • log_printer – Log_printer to handle logging
Returns:

Iterator that yields a tuple with bear class and which bear_glob was used to find that bear class.

coalib.collecting.Dependencies module

coalib.collecting.Dependencies.resolve(bears)[source]

Collects all dependencies of the given bears. This will also remove duplicates.

Parameters:bears – The given bears. Will not be modified.
Returns:The new list of bears, sorted so that it can be executed sequentially without dependency issues.

coalib.collecting.Importers module

coalib.collecting.Importers.iimport_objects(file_paths, names=None, types=None, supers=None, attributes=None, local=False, suppress_output=False)[source]

Import all objects from the given modules that fulfill the requirements

Parameters:
  • file_paths – File path(s) from which objects will be imported.
  • names – Name(s) an objects need to have one of.
  • types – Type(s) an objects need to be out of.
  • supers – Class(es) objects need to be a subclass of.
  • attributes – Attribute(s) an object needs to (all) have.
  • local – If True: Objects need to be defined in the file they appear in to be collected.
  • suppress_output – Whether console output from stdout shall be suppressed or not.
Returns:

An iterator that yields all matching python objects.

Raises:

Exception – Any exception that is thrown in module code or an ImportError if paths are erroneous.

coalib.collecting.Importers.import_objects(file_paths, names=None, types=None, supers=None, attributes=None, local=False, verbose=False)[source]

Import all objects from the given modules that fulfill the requirements

Parameters:
  • file_paths – File path(s) from which objects will be imported
  • names – Name(s) an objects need to have one of
  • types – Type(s) an objects need to be out of
  • supers – Class(es) objects need to be a subclass of
  • attributes – Attribute(s) an object needs to (all) have
  • local – if True: Objects need to be defined in the file they appear in to be collected
Returns:

list of all matching python objects

Raises:

Exception – Any exception that is thrown in module code or an ImportError if paths are erroneous.

coalib.collecting.Importers.object_defined_in(obj, file_path)[source]

Check if the object is defined in the given file.

>>> object_defined_in(object_defined_in, __file__)
True
>>> object_defined_in(object_defined_in, "somewhere else")
False

Builtins are always defined outside any given file:

>>> object_defined_in(False, __file__)
False
Parameters:
  • obj – The object to check.
  • file_path – The path it might be defined in.
Returns:

True if the object is defined in the file.

Module contents