sourcespell package¶
Submodules¶
sourcespell.sourcespell module¶
-
class
sourcespell.sourcespell.BaseChecker(base_dir='.', ignore_patterns=None, language='en_GB', project_dict=None, encoding='utf-8')[source]¶ Bases:
objectCommon functionality for all checker classes.
Parameters: - base_dir – The path to the base directory.
- ignore_patterns – List of glob ignore patterns to skip.
- language – ISO language code, e.g. ‘en_GB’ or ‘en_US’
- project_dict – Path to the project dictionary for excluded words.
- encoding – Character set encoding to use reading / writing files.
-
_process_file(src_file)[source]¶ Called from run for each source file under the base directory.
Parameters: src_file ( SourceFile) – The source file being checked.
-
class
sourcespell.sourcespell.EmailFilter(tokenizer)[source]¶ Bases:
enchant.tokenize.EmailFilterOverride the
enchant.tokenize.EmailFilterto filter out addresses enclosed in angle brackets, for example:
-
exception
sourcespell.sourcespell.EmptyFileError[source]¶ Bases:
exceptions.ExceptionError thrown for empty files.
-
class
sourcespell.sourcespell.HashBangFilter(tokenizer)[source]¶ Bases:
enchant.tokenize.FilterFilter skipping over the hashbang in executable scripts.
Taken from: https://github.com/htgoebel/pysource-spellchecker
-
class
sourcespell.sourcespell.InteractiveChecker(base_dir='.', ignore_patterns=None, language='en_GB', project_dict=None, encoding='utf-8')[source]¶ Bases:
sourcespell.sourcespell.BaseCheckerInteractive spellchecker. Allows the user to quickly fix spelling errors and add words to the excluded words dictionary.
-
_get_source_map(contents)[source]¶ Creates a map of index, token pairs from the source file to handle spelling replacements.
Parameters: contents – The contents of the source file. Returns: The generated map. Return type: collections.OrderedDict
-
_handle_response(src_map, error)[source]¶ Handle the user response. Return True if a correction was made.
Parameters: - src_map (
collections.OrderedDict) – The map of indexes to tokens. - error (
SpellingCorrection) – The spelling correction data.
- src_map (
-
_process_file(src_file)[source]¶ For each error in the file. Prompt the user for the action to take.
Parameters: src_file ( SourceFile) – Source file being checked.
-
-
exception
sourcespell.sourcespell.NextFile[source]¶ Bases:
exceptions.ExceptionTrigger to advance to the next file.
-
exception
sourcespell.sourcespell.ParseError[source]¶ Bases:
exceptions.ExceptionError thrown for Pygments lexer errors.
-
class
sourcespell.sourcespell.SourceFile(filename, dictionary, tokeniser, base_dir, encoding='utf-8')[source]¶ Bases:
objectInterface for checking for spelling errors in a single source file.
Parameters: - filename – Absolute path to the file.
- dictionary (
enchant.Dict) – Enchant dictionary. - tokeniser (
enchant.tokenize.Tokenizer) – Enchant tokeniser fromget_tokenizer() - base_dir – Base directory path.
- encoding – Character set encoding to read files with.
-
_filter_code_tokens(stream)[source]¶ Filter the token stream based on token type and the name of the lexer.
-
_index_to_col_lineno(index)[source]¶ Calculates the line and column index from the file index.
Parameters: index – The file index. Returns: A tuple of line number and column index. Return type: tupleof (int, int)
-
_select_token(tokentype, name, value)[source]¶ Return
Trueif the token should be used,Falseotherwise.
-
errors()[source]¶ Generator that yields
SpellingCorrectionobjects for the current source file.
-
relname¶ Returns the name of the file relative to the base directory being checked.
-
class
sourcespell.sourcespell.SpellChecker(base_dir='.', ignore_patterns=None, language='en_GB', project_dict=None, encoding='utf-8')[source]¶ Bases:
sourcespell.sourcespell.BaseCheckerNon-Interactive spell checker. Prints a list of all spelling errors found.
-
class
sourcespell.sourcespell.SpellingCorrection(filename, word, index, line_no, column, dictionary, line_content)[source]¶ Bases:
objectObject to store information for a spelling error.
Parameters: - filename – File path, relative to the base directory.
- word – The word being checked.
- index – The file index at the start of the word.
- line_no – The 1-indexed line number.
- column – The column index.
- dictionary (
enchant.Dict) – Reference to the dictionary object. - line_content – The contents of the line containing the error.
-
sourcespell.sourcespell.get_parser(description='')[source]¶ Initialise the command line argument parsing.
Returns: The argument parser. Return type: argparse.ArgumentParser