Skip to content

Commit

Permalink
Merge pull request #24 from timgraham/logging-warnings
Browse files Browse the repository at this point in the history
Remove usage of deprecated logging API
  • Loading branch information
TimKam authored Jan 27, 2019
2 parents 573197e + 53f8b5a commit 3108cd8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
6 changes: 5 additions & 1 deletion sphinxcontrib/spelling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import inspect

from sphinx.util import logging

from .builder import SpellingBuilder
from .directive import SpellingDirective

logger = logging.getLogger(__name__)


def setup(app):
# If we are running inside the test suite, "app" will be a module.
if inspect.ismodule(app):
return
app.info('Initializing Spelling Checker')
logger.info('Initializing Spelling Checker')
app.add_builder(SpellingBuilder)
# Register the 'spelling' directive for setting parameters within
# a document
Expand Down
27 changes: 15 additions & 12 deletions sphinxcontrib/spelling/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

import docutils.nodes
from sphinx.builders import Builder
from sphinx.util import logging
from sphinx.util.console import darkgreen, red

from enchant.tokenize import EmailFilter, WikiWordFilter

from . import checker
from . import filters

logger = logging.getLogger(__name__)

# TODO - Words with multiple uppercase letters treated as classes and ignored


Expand All @@ -44,27 +47,27 @@ def init(self):
EmailFilter,
]
if self.config.spelling_ignore_wiki_words:
self.info('Ignoring wiki words')
logger.info('Ignoring wiki words')
f.append(WikiWordFilter)
if self.config.spelling_ignore_acronyms:
self.info('Ignoring acronyms')
logger.info('Ignoring acronyms')
f.append(filters.AcronymFilter)
if self.config.spelling_ignore_pypi_package_names:
self.info('Adding package names from PyPI to local dictionary...')
logger.info('Adding package names from PyPI to local dictionary')
f.append(filters.PyPIFilterFactory())
if self.config.spelling_ignore_python_builtins:
self.info('Ignoring Python builtins')
logger.info('Ignoring Python builtins')
f.append(filters.PythonBuiltinsFilter)
if self.config.spelling_ignore_importable_modules:
self.info('Ignoring importable module names')
logger.info('Ignoring importable module names')
f.append(filters.ImportableModuleFilter)
f.extend(self.config.spelling_filters)

if not os.path.isdir(self.outdir):
os.mkdir(self.outdir)

word_list = self.get_wordlist_filename()
self.info('Looking for custom word list in {}'.format(word_list))
logger.info('Looking for custom word list in {}'.format(word_list))

self.checker = checker.SpellingChecker(
lang=self.config.spelling_lang,
Expand Down Expand Up @@ -106,7 +109,7 @@ def _build_combined_wordlist(self):
for word_file in word_list:
# Paths are relative
long_word_file = os.path.join(self.srcdir, word_file)
self.info('Adding contents of {} to custom word list'.format(
logger.info('Adding contents of {} to custom word list'.format(
long_word_file))
with io.open(long_word_file, 'r', encoding='UTF-8') as infile:
infile_contents = infile.readlines()
Expand Down Expand Up @@ -155,7 +158,7 @@ def write_doc(self, docname, doctree):
parent = node
seen = set()
while lineno is None:
# self.info('looking for line number on %r' % node)
# logger.info('looking for line number on %r' % node)
seen.add(parent)
parent = node.parent
if parent is None or parent in seen:
Expand All @@ -170,7 +173,7 @@ def write_doc(self, docname, doctree):
msg_parts.append(red(word))
msg_parts.append(self.format_suggestions(suggestions))
msg = ':'.join(msg_parts)
self.info(msg)
logger.info(msg)
self.output.write(u"%s:%s: (%s) %s\n" % (
self.env.doc2path(docname, None),
lineno, word,
Expand All @@ -183,8 +186,8 @@ def write_doc(self, docname, doctree):

def finish(self):
self.output.close()
self.info('Spelling checker messages written to %s' %
self.output_filename)
logger.info('Spelling checker messages written to %s' %
self.output_filename)
if self.misspelling_count:
self.warn('Found %d misspelled words' % self.misspelling_count)
logger.warn('Found %d misspelled words' % self.misspelling_count)
return
5 changes: 4 additions & 1 deletion sphinxcontrib/spelling/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import collections

from docutils.parsers import rst
from sphinx.util import logging

from . import filters

logger = logging.getLogger(__name__)


class SpellingDirective(rst.Directive):
"""Custom directive for passing instructions to the spelling checker.
Expand Down Expand Up @@ -38,7 +41,7 @@ def run(self):
continue
good_words.extend(entry.split())
if good_words:
env.app.debug(
logger.debug(
'Extending local dictionary for %s with %s' % (
env.docname, str(good_words))
)
Expand Down

0 comments on commit 3108cd8

Please sign in to comment.