PK¼#OH spellrst.py#!/usr/bin/env python """Spell check reStructuredText.""" import os import sys from glob import glob import click from docutils.parsers.rst import Parser, Directive, directives, roles from docutils.utils import new_document from docutils.frontend import OptionParser from docutils.nodes import Text import spacy __version__ = '0.1.0' class IgnoredDirective(Directive): """Stub for unknown directives.""" has_content = True def run(self): """Do nothing.""" return [] def ignore_role(name, rawtext, text, lineno, inliner, options=None, content=None): """Stub for unknown roles.""" # pylint: disable=unused-argument return ([], []) # ignore Sphinx directives ignored = ['todo', 'toctree', 'autoclass', 'graphviz', 'automodule'] for ignore in ignored: directives.register_directive(ignore, IgnoredDirective) iroles = ['py:class', 'ref'] for role in iroles: roles.register_local_role(role, ignore_role) TEXT_NODES = set(['block_quote', 'paragraph', 'list_item', 'term', 'definition_list_item', 'title']) def is_misspelled(token): if token.like_url or token.like_num or token.like_email: return False return token.is_oov @click.command() @click.argument('files', nargs=-1) @click.option( '-d', '--dictionary', help='spaCy language model (spacy.io/models), e.g. en_core_web_md', default='en_core_web_md', ) def main(files, dictionary): """Spell check reStructuredText.""" parser = Parser() settings = OptionParser(components=(Parser,)).get_default_values() nlp = spacy.load(dictionary) any_misspellings = False for file in files: for filename in glob(file): document = new_document(filename, settings) p = parser.parse(open(filename, 'r').read(), document) misspellings = set() for node in parser.document.traverse(Text): if ( node.tagname == '#text' and node.parent and node.parent.tagname in TEXT_NODES and ( (node.parent.parent and node.parent.parent.tagname != 'system_message') or not node.parent.parent ) ): misspellings |= set( token.text for token in nlp(node.astext()) if is_misspelled(token) ) if misspellings: any_misspellings = True print(f'✘ {filename}') print(*misspellings, sep='\n') else: print(f'✔ {filename}') sys.exit(os.EX_DATAERR if any_misspellings else os.EX_OK) if __name__ == '__main__': main() PK!HK-d%*)spellrst-0.1.0.dist-info/entry_points.txtN+I/N.,()*.H)*.1r3PKV#Oy-- spellrst-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2019 Jacques Kvam Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HPOspellrst-0.1.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPK!H^8;!spellrst-0.1.0.dist-info/METADATAS]O0|؇>9h>DRm%.ٻq\Pj'k<ٙ| r+[&9dSa0_6$צ0Gp8v/9$5+JEO' EHk&?ǟLFk%Ľ^Mgߦu)|FWD@F(B_uV:B2OrMKdm򎝡NUS[,_)jwcgʇVq̭~-cGaa]>@CA4e @ O ;)s)9!N[06G 73Lt?ΖKhm ( Gd@aɳl# _D3vilr 6mr݉JQK2X9k:4M#q~5 U;}r6>IkFά[|Pdiaq}'EIzxg+.Ⱦ_Vdfg꼰 Ţ<1lY/08a\Ji$m(siweig|;$F6+ĄD+Xb YU4EUǬiu~+)E~9ה3|zpJDN8#<.1Acdq4hAHֶ(anmwYA,| ½@ E ǒ/w>B."⹦_Ven>oja~O$hR۳S{rOgR! x-GmȵruIPK¼#OH spellrst.pyPK!HK-d%*) spellrst-0.1.0.dist-info/entry_points.txtPKV#Oy-- H spellrst-0.1.0.dist-info/LICENSEPK!HPOspellrst-0.1.0.dist-info/WHEELPK!H^8;!?spellrst-0.1.0.dist-info/METADATAPK!HwB==(spellrst-0.1.0.dist-info/RECORDPK