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:
object
Common 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.EmailFilter
Override the
enchant.tokenize.EmailFilter
to filter out addresses enclosed in angle brackets, for example:
-
exception
sourcespell.sourcespell.
EmptyFileError
[source]¶ Bases:
exceptions.Exception
Error thrown for empty files.
-
class
sourcespell.sourcespell.
HashBangFilter
(tokenizer)[source]¶ Bases:
enchant.tokenize.Filter
Filter 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.BaseChecker
Interactive 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.Exception
Trigger to advance to the next file.
-
exception
sourcespell.sourcespell.
ParseError
[source]¶ Bases:
exceptions.Exception
Error thrown for Pygments lexer errors.
-
class
sourcespell.sourcespell.
SourceFile
(filename, dictionary, tokeniser, base_dir, encoding='utf-8')[source]¶ Bases:
object
Interface 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: tuple
of (int, int)
-
_select_token
(tokentype, name, value)[source]¶ Return
True
if the token should be used,False
otherwise.
-
errors
()[source]¶ Generator that yields
SpellingCorrection
objects 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.BaseChecker
Non-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:
object
Object 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