coalib.bearlib.abstractions package¶
Submodules¶
coalib.bearlib.abstractions.Lint module¶
-
class
coalib.bearlib.abstractions.Lint.
Lint
(*args, **kwargs)¶ Bases:
coalib.bears.Bear.Bear
Deals with the creation of linting bears.
For the tutorial see: http://coala.readthedocs.org/en/latest/Users/Tutorials/Linter_Bears.html
Parameters: - executable – The executable to run the linter.
- prerequisite_command – The command to run as a prerequisite
and is of type
list
. - prerequisites_fail_msg – The message to be displayed if the prerequisite fails.
- arguments –
The arguments to supply to the linter, such that the file name to be analyzed can be appended to the end. Note that we use
.format()
on the arguments - so,{abc}
needs to be given as{{abc}}
. Currently, the following will be replaced:{filename}
- The filename passed tolint()
{config_file}
- The config file created usingconfig_file()
- output_regex –
The regex which will match the output of the linter to get results. This is not used if
gives_corrected
is set. This regex should give out the following variables:- line - The line where the issue starts.
- column - The column where the issue starts.
- end_line - The line where the issue ends.
- end_column - The column where the issue ends.
- severity - The severity of the issue.
- message - The message of the result.
- origin - The origin of the issue.
- diff_severity – The severity to use for all results if
gives_corrected
is set. - diff_message – The message to use for all results if
gives_corrected
is set. - use_stderr – Uses stderr as the output stream is it’s True.
- use_stdin – Sends file as stdin instead of giving the file name.
- gives_corrected – True if the executable gives the corrected file or just the issues.
- severity_map – A dict where the keys are the possible severity values the Linter gives out and the values are the severity of the coala Result to set it to. If it is not a dict, it is ignored.
-
arguments
= ''¶
-
classmethod
check_prerequisites
()¶ Checks for prerequisites required by the Linter Bear.
-
static
config_file
()¶ Returns a configuation file from the section given to the bear. The section is available in self.section. To add the config file’s name generated by this function to the arguments, use {config_file}.
Returns: A list of lines of the config file to be used or None.
-
diff_message
= 'No result message was set'¶
-
diff_severity
= 1¶
-
executable
= None¶
-
generate_config_file
()¶ Generates a temporary config file. Note: The user of the function is responsible for deleting the tempfile when done with it.
Returns: The file name of the tempfile created.
-
gives_corrected
= False¶
-
lint
(filename=None, file=None)¶ Takes a file and lints it using the linter variables defined apriori.
Parameters: - filename – The name of the file to execute.
- file – The contents of the file as a list of strings.
-
match_to_result
(match, filename)¶ Converts a regex match’s groups into a result.
Parameters: - match – The match got from regex parsing.
- filename – The name of the file from which this match is got.
-
output_regex
= re.compile('(?P<line>\\d+)\\.(?P<column>\\d+)\\|(?P<severity>\\d+): (?P<message>.*)')¶
-
prerequisite_command
= None¶
-
prerequisite_fail_msg
= 'Unknown failure.'¶
-
process_output
(output, filename, file)¶
-
severity_map
= None¶
-
use_stderr
= False¶
-
use_stdin
= False¶
coalib.bearlib.abstractions.SectionCreatable module¶
-
class
coalib.bearlib.abstractions.SectionCreatable.
SectionCreatable
¶ Bases:
object
A SectionCreatable is an object that is creatable out of a section object. Thus this is the class for many helper objects provided by the bearlib.
If you want to use an object that inherits from this class the following approach is recommended: Instantiate it via the from_section method. You can provide default arguments via the lower case keyword arguments.
Example:
SpacingHelper.from_section(section, tabwidth=8)
creates a SpacingHelper and if the “tabwidth” setting is needed and not contained in section, 8 will be taken.
It is recommended to write the prototype of the __init__ method according to this example:
def __init__(self, setting_one: int, setting_two: bool=False): pass # Implementation
This way the get_optional_settings and the get_non_optional_settings method will extract automatically that:
- setting_one should be an integer
- setting_two should be a bool and defaults to False
If you write a documentation comment, you can use :param to add descriptions to your parameters. These will be available too automatically.
-
classmethod
from_section
(section, **kwargs)¶ Creates the object from a section object.
Parameters: - section – A section object containing at least the settings specified by get_non_optional_settings()
- kwargs – Additional keyword arguments
-
classmethod
get_metadata
()¶
-
classmethod
get_non_optional_settings
()¶ Retrieves the minimal set of settings that need to be defined in order to use this object.
Returns: a dictionary of needed settings as keys and help texts as values
-
classmethod
get_optional_settings
()¶ Retrieves the settings needed IN ADDITION to the ones of get_non_optional_settings to use this object without internal defaults.
Returns: a dictionary of needed settings as keys and help texts as values
Module contents¶
The abstractions package contains classes that serve as interfaces for helper classes in the bearlib.