coalib.parsing package¶
Subpackages¶
Submodules¶
coalib.parsing.CliParsing module¶
-
coalib.parsing.CliParsing.
check_conflicts
(sections)[source]¶ Checks if there are any conflicting arguments passed.
Parameters: sections – The {section_name: section_object}
dictionary to check conflicts for.Returns: True if no conflicts occur. Raises: SystemExit – If there are conflicting arguments (exit code: 2)
-
coalib.parsing.CliParsing.
parse_cli
(arg_list=None, origin='/home/docs/checkouts/readthedocs.org/user_builds/coala-api/checkouts/latest/docs', arg_parser=None, args=None, key_value_delimiters=('=', ':'), comment_seperators=(), key_delimiters=(', ', ), section_override_delimiters=('.', ), key_value_append_delimiters=('+=', ))[source]¶ Parses the CLI arguments and creates sections out of it.
Parameters: - arg_list – The CLI argument list.
- origin – Directory used to interpret relative paths given as argument.
- arg_parser – Instance of ArgParser that is used to parse none-setting arguments.
- args – Alternative pre-parsed CLI arguments.
- key_value_delimiters – Delimiters to separate key and value in setting arguments where settings are being defined.
- comment_seperators – Allowed prefixes for comments.
- key_delimiters – Delimiter to separate multiple keys of a setting argument.
- section_override_delimiters – The delimiter to delimit the section from the key name (e.g. the ‘.’ in sect.key = value).
- key_value_append_delimiters – Delimiters to separate key and value in setting arguments where settings are being appended.
Returns: A dictionary holding section names as keys and the sections themselves as value.
-
coalib.parsing.CliParsing.
parse_custom_settings
(sections, custom_settings_list, origin, line_parser)[source]¶ Parses the custom settings given to coala via
-S something=value
.Parameters: - sections – The Section dictionary to add to (mutable).
- custom_settings_list – The list of settings strings.
- origin – The originating directory.
- line_parser – The LineParser to use.
coalib.parsing.ConfParser module¶
-
class
coalib.parsing.ConfParser.
ConfParser
(key_value_delimiters=('=', ), comment_seperators=('#', ), key_delimiters=(', ', ' '), section_name_surroundings=mappingproxy({'[': ']'}), remove_empty_iter_elements=True, key_value_append_delimiters=('+=', ))[source]¶ Bases:
object
-
parse
(input_data, overwrite=False)[source]¶ Parses the input and adds the new data to the existing.
Parameters: - input_data – The filename to parse from.
- overwrite – If True, wipes all existing Settings inside this instance and adds only the newly parsed ones. If False, adds the newly parsed data to the existing one (and overwrites already existing keys with the newly parsed values).
Returns: A dictionary with (lowercase) section names as keys and their Setting objects as values.
-
coalib.parsing.DefaultArgParser module¶
-
class
coalib.parsing.DefaultArgParser.
CustomFormatter
(prog, indent_increment=2, max_help_position=24, width=None)[source]¶ Bases:
argparse.RawDescriptionHelpFormatter
A Custom Formatter that will keep the metavars in the usage but remove them in the more detailed arguments section.
-
class
coalib.parsing.DefaultArgParser.
PathArg
[source]¶ Bases:
str
Uni(xi)fying OS-native directory separators in path arguments.
Removing the pain from interactively using coala in a Windows cmdline, because backslashes are interpreted as escaping syntax and therefore removed when arguments are turned into coala settings
>>> import os >>> PathArg(os.path.join('path', 'with', 'separators')) 'path/with/separators'
coalib.parsing.FilterHelper module¶
-
coalib.parsing.FilterHelper.
apply_filter
(filter_name, filter_args, all_bears=None)[source]¶ Returns bears after filtering based on
filter_args
. It returns all bears if nothing is present infilter_args
.Parameters: - filter_name – Name of the filter.
- filter_args – Arguments of the filter to be passed in.
For example:
['c', 'java']
- all_bears – List of bears on which filter is to be applied. All the bears are loaded automatically by default.
Returns: Filtered bears based on a single filter.
-
coalib.parsing.FilterHelper.
apply_filters
(filters, bears=None)[source]¶ Returns bears after filtering based on
filters
. It returns intersection of bears if more than one element is present infilters
list.Parameters: - filters – List of args based on
bears
has to be filtered. For example:[['language', 'c', 'java'], ['can_fix', 'syntax']]
- bears – The bears to filter.
Returns: Filtered bears.
- filters – List of args based on
coalib.parsing.Globbing module¶
-
coalib.parsing.Globbing.
fnmatch
(name, globs)[source]¶ Tests whether name matches one of the given globs.
An empty glob will match nothing and return false.
Parameters: - name – File or directory name
- globs – Glob string with wildcards or list of globs
Returns: Boolean: Whether or not name is matched by glob
Glob Syntax:
- ‘[seq]’: Matches any character in seq. Cannot be empty. Any
- special character looses its special meaning in a set.
- ‘[!seq]’: Matches any character not in seq. Cannot be empty. Any
- special character looses its special meaning in a set.
- ‘(seq_a|seq_b)’: Matches either sequence_a or sequence_b as a whole.
- More than two or just one sequence can be given.
- ‘?’: Matches any single character.
- ‘*’: Matches everything but os.sep.
- ‘**’: Matches everything.
-
coalib.parsing.Globbing.
glob
(pattern)[source]¶ Iterates all filesystem paths that get matched by the glob pattern. Syntax is equal to that of fnmatch.
Parameters: pattern – Glob pattern with wildcards Returns: List of all file names that match pattern
-
coalib.parsing.Globbing.
glob_escape
(input_string)[source]¶ Escapes the given string with
[c]
pattern. Examples:>>> from coalib.parsing.Globbing import glob_escape >>> glob_escape('test (1)') 'test [(]1[)]' >>> glob_escape('test folder?') 'test folder[?]' >>> glob_escape('test*folder') 'test[*]folder'
Parameters: input_string – String that is to be escaped with [ ]
.Returns: Escaped string in which all the special glob characters ()[]|?*
are escaped.
-
coalib.parsing.Globbing.
has_wildcard
(pattern)[source]¶ Checks whether pattern has any wildcards.
Parameters: pattern – Glob pattern that may contain wildcards Returns: Boolean: Whether or not there are wildcards in pattern
-
coalib.parsing.Globbing.
iglob
(pattern)[source]¶ Iterates all filesystem paths that get matched by the glob pattern. Syntax is equal to that of fnmatch.
Parameters: pattern – Glob pattern with wildcards Returns: Iterator that yields all file names that match pattern
-
coalib.parsing.Globbing.
relative_flat_glob
(dirname, basename)[source]¶ Non-recursive glob for one directory. Does not accept wildcards.
Parameters: - dirname – Directory name
- basename – Basename of a file in dir of dirname
Returns: List containing Basename if the file exists
-
coalib.parsing.Globbing.
relative_recursive_glob
(dirname, pattern)[source]¶ Recursive Glob for one directory and all its (nested) subdirectories. Accepts only ‘**’ as pattern.
Parameters: - dirname – Directory name
- pattern – The recursive wildcard ‘**’
Returns: Iterator that yields all the (nested) subdirectories of the given dir
coalib.parsing.InvalidFilterException module¶
coalib.parsing.LineParser module¶
-
class
coalib.parsing.LineParser.
LineParser
(key_value_delimiters=('=', ), comment_separators=('#', ), key_delimiters=(', ', ' '), section_name_surroundings=None, section_override_delimiters=('.', ), key_value_append_delimiters=('+=', ))[source]¶ Bases:
object
-
parse
(line)[source]¶ Note that every value in the returned tuple besides the value is unescaped. This is so since the value is meant to be put into a Setting later thus the escapes may be needed there.
Parameters: line – The line to parse. Returns: section_name (empty string if it’s no section name), [(section_override, key), …], value, comment
-
Module contents¶
The StringProcessing module contains various functions for extracting information out of strings.
Most of them support regexes for advanced pattern matching.