Skip to main content

Typo and spelling checker

Project description

Pytypos

PyPI version Downloads PyPI - Downloads License contributions welcome

Description

Pytypos is a typo and spelling checker used to identify spelling mistakes in comments of a various programming languages, such as Python, Java, C++, C#, Matlab, and others. In addition, it can check other text-oriented files such as MD, RST, TXT, or similar.

Spell checking uses dictionaries installed on the host computer. The dictionary language can be defined in the Pytypos object with dictionary='de' for German, for instance. For installation and management of dictionaries, see the documentation of pyenchant. To list available dictionary languages on the host system, print pytypos.available_languages().

Installation

The easiest way to install is using pip:

pip install pytypos

To install from source:

git clone https://github.com/PApostol/pytypos.git
cd pytypos
python setup.py install

For usage details check help(pytypos).

Usage Examples

The below will recursively scan my/path/project/ for comments (i.e. # this is a comment) in Python files:

from pytypos import Pytypos
prj = Pytypos(target='my/path/project/', match_identifier='#', file_extension='py', recursive=True)
prj.find_typos()
print(prj.typo_list)
print(prj.typo_details)

Pytypos.typo_list stores a list of all possible typos found.

Pytypos.typo_details stores a dictionary with the following structure:

If suggestions = False (default):

{'file1': ['typo1', 'typo2'],
 'file2': ['typo1', 'typo2']
}

If suggestions = True:

{'file1': [{'typo1': ['suggestion1a', 'suggestion1b'],
            'typo2': ['suggestion2a', 'suggestion2b']
           },
 'file2': [{'typo1': ['suggestion1a', 'suggestion1b'],
            'typo2': ['suggestion2a', 'suggestion2b']
           }
}

The above can be nicely printed on stdout with Python's built-in pprint.

Other Examples

# recursively scan "foo/bar/" for any text in RST files and give suggestions, but skip file "foo/UPDATE.rst" and exclude the words "repos" and "GitHub"
Pytypos(target='foo/bar/', match_identifier='', file_extension='rst', recursive=True, suggestions=True, exclude_file_list=['foo/UPDATE.rst'], exclude_word_list=['repos', 'GitHub'])

# scan the "a/b/c.java" Java file for comments (i.e. "// this is a comment") and give suggestions with a french dictionary, but exclude words found in "exclusions.txt"
Pytypos(target='a/b/c.java', match_identifier='//', dictionary='fr', suggestions=True, exclude_word_file='exclusions.txt')

Testing

You can do some simple testing after cloning the repo:

python tests/run_test.py

Note any additional requirements for running the tests: pip install -r tests/requirements.txt

Additional methods

Pytypos.fix_typos(): Fixes typos found in-between spaces with the most likely replacement

Pytypos.add_to_dictionary(): Adds custom word list to dictionary

Pytypos.add_to_exclusions(): Removes custom word list from dictionary

Pytypos.replace_word(): Replaces words in dictionary

License

Released under MIT by @PApostol

  • You can freely modify and reuse.
  • The original license must be included with copies of this software.
  • Please link back to this repo if you use a significant portion the source code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytypos-1.2.1.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file pytypos-1.2.1.tar.gz.

File metadata

  • Download URL: pytypos-1.2.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.6

File hashes

Hashes for pytypos-1.2.1.tar.gz
Algorithm Hash digest
SHA256 76fcee94d562b4ab2ab01f842e5148f0cb4f48dd99f1d261ccc0ae88b138afd1
MD5 3f60009e974fedfef83e7e8793157458
BLAKE2b-256 5acd57e48a43dd7ae75cd660cc84cc7e6434ea209ee5bc1384e10b75a9ce39b8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page